Changeset ebd65a8 in rattail


Ignore:
Timestamp:
06/16/20 16:39:41 (8 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
2117212
Parents:
8a6c147
Message:

Remove 'fixture' use within tests; plus fix some tests

Files:
17 edited
1 moved

Legend:

Unmodified
Added
Removed
  • rattail/tests/__init__.py

    r8a6c147 rebd65a8  
    3434
    3535    def update(self, value):
     36        return True
     37
     38    def destroy(self):
    3639        pass
    3740
    38     def destroy(self):
     41    def finish(self):
    3942        pass
    4043
  • rattail/tests/commands/test_core.py

    r8a6c147 rebd65a8  
    33from __future__ import unicode_literals, absolute_import
    44
     5import os
    56import csv
    67import datetime
    78import argparse
     9import shutil
     10import tempfile
    811from unittest import TestCase
    912from six import StringIO
     
    1215# from sqlalchemy import func
    1316from mock import patch, Mock
    14 from fixture import TempIO
    1517
    1618from rattail.commands import core
     
    111113        command = core.Command()
    112114        fake = command.subcommands['fake'] = Fake
    113         tmp = TempIO()
    114         config_path = tmp.putfile('test.ini', '')
    115         out_path = tmp.putfile('out.txt', '')
     115        tempdir = tempfile.mkdtemp()
     116        config_path = os.path.join(tempdir, 'test.ini')
     117        with open(config_path, 'wt') as f:
     118            f.write('')
     119        out_path = os.path.join(tempdir, 'out.txt')
     120        with open(out_path, 'wt') as f:
     121            f.write('')
    116122        command.run('fake', '--config', config_path, '--stdout', out_path)
    117123        with open(out_path) as f:
    118124            self.assertEqual(f.read(), "standard output stuff")
     125        shutil.rmtree(tempdir)
    119126
    120127    def test_stderr_may_be_redirected(self):
     
    125132        command = core.Command()
    126133        fake = command.subcommands['fake'] = Fake
    127         tmp = TempIO()
    128         config_path = tmp.putfile('test.ini', '')
    129         err_path = tmp.putfile('err.txt', '')
     134        tempdir = tempfile.mkdtemp()
     135        config_path = os.path.join(tempdir, 'test.ini')
     136        with open(config_path, 'wt') as f:
     137            f.write('')
     138        err_path = os.path.join(tempdir, 'err.txt')
     139        with open(err_path, 'wt') as f:
     140            f.write('')
    130141        command.run('fake', '--config', config_path, '--stderr', err_path)
    131142        with open(err_path) as f:
    132143            self.assertEqual(f.read(), "standard error stuff")
     144        shutil.rmtree(tempdir)
    133145
    134146    # # TODO: Figure out a better way to test this, or don't bother.
  • rattail/tests/db/test_init.py

    r8a6c147 rebd65a8  
    33from __future__ import unicode_literals, absolute_import
    44
     5import os
     6import shutil
     7import tempfile
    58from unittest import TestCase
    69
    710import six
    811import sqlalchemy as sa
    9 from fixture import TempIO
    1012
    1113from rattail import db
     
    4749
    4850    def setUp(self):
    49         self.tempio = TempIO()
     51        self.tempdir = tempfile.mkdtemp()
    5052
    5153    def tearDown(self):
    5254        db.Session.configure(bind=None, rattail_config=None)
    53         self.tempio = None
     55        shutil.rmtree(self.tempdir)
     56
     57    def write_file(self, fname, content):
     58        path = os.path.join(self.tempdir, fname)
     59        with open(path, 'wt') as f:
     60            f.write(content)
     61        return path
    5462
    5563    def test_configure_empty(self):
     
    6876
    6977    def test_configure_connections(self):
    70         default_path = self.tempio.putfile('default.sqlite', '')
     78        default_path = self.write_file('default.sqlite', '')
    7179        default_url = 'sqlite:///{}'.format(default_path)
    72         host_path = self.tempio.putfile('host.sqlite', '')
     80        host_path = self.write_file('host.sqlite', '')
    7381        host_url = 'sqlite:///{}'.format(host_path)
    7482
  • rattail/tests/filemon/test_actions.py

    r8a6c147 rebd65a8  
    44
    55import os
     6import shutil
    67import time
     8import tempfile
    79from six.moves import queue
    810from unittest import TestCase
    911
    1012from mock import Mock, patch, call
    11 from fixture import TempIO
    1213
    1314from rattail.config import make_config, RattailConfig
     
    2829
    2930    def setUp(self):
    30         self.tmp = TempIO()
     31        self.tempdir = tempfile.mkdtemp()
    3132        self.config = make_config([])
    3233        self.config.set(u'rattail.filemon', u'monitor', u'foo')
    33         self.config.set(u'rattail.filemon', u'foo.dirs', self.tmp)
     34        self.config.set('rattail.filemon', 'foo.dirs', self.tempdir)
    3435        self.config.set(u'rattail.filemon', u'foo.actions', u'noop')
    3536        self.config.set(u'rattail.filemon', u'foo.action.noop.func', u'rattail.filemon.actions:noop')
    3637        # Must delay creating the profile since doing it here would bypass our mock of noop.
     38
     39    def tearDown(self):
     40        shutil.rmtree(self.tempdir)
     41
     42    def write_file(self, fname, content):
     43        path = os.path.join(self.tempdir, fname)
     44        with open(path, 'wt') as f:
     45            f.write(content)
     46        return path
    3747
    3848    def get_profile(self, stop_on_error=False):
     
    4252        profile.queue.get_nowait.side_effect = [
    4353            queue.Empty, # for coverage sake; will be effectively skipped
    44             self.tmp.putfile(u'file1', u''),
    45             self.tmp.putfile(u'file2', u''),
    46             self.tmp.putfile(u'file3', u''),
     54            self.write_file('file1', ''),
     55            self.write_file('file2', ''),
     56            self.write_file('file3', ''),
    4757            actions.StopProcessing,
    4858            ]
     
    5464        self.assertEqual(noop.call_count, 3)
    5565        noop.assert_has_calls([
    56                 call(self.tmp.join(u'file1')),
    57                 call(self.tmp.join(u'file2')),
    58                 call(self.tmp.join(u'file3')),
     66                call(os.path.join(self.tempdir, 'file1')),
     67                call(os.path.join(self.tempdir, 'file2')),
     68                call(os.path.join(self.tempdir, 'file3')),
    5969                ])
    6070
    6171    def test_action_is_skipped_for_nonexistent_file(self, noop):
    6272        profile = self.get_profile()
    63         os.remove(self.tmp.join(u'file2'))
     73        os.remove(os.path.join(self.tempdir, 'file2'))
    6474        actions.perform_actions(profile)
    6575        self.assertEqual(noop.call_count, 2)
    6676        # no call for file2
    6777        noop.assert_has_calls([
    68                 call(self.tmp.join(u'file1')),
    69                 call(self.tmp.join(u'file3')),
     78                call(os.path.join(self.tempdir, 'file1')),
     79                call(os.path.join(self.tempdir, 'file3')),
    7080                ])
    7181
     
    7787        noop.side_effect = [None, RuntimeError, None]
    7888        actions.perform_actions(profile)
    79         self.assertFalse(os.path.exists(self.tmp.join(u'file1')))
    80         self.assertTrue(os.path.exists(self.tmp.join(u'file2')))
    81         self.assertFalse(os.path.exists(self.tmp.join(u'file3')))
     89        self.assertFalse(os.path.exists(os.path.join(self.tempdir, 'file1')))
     90        self.assertTrue(os.path.exists(os.path.join(self.tempdir, 'file2')))
     91        self.assertFalse(os.path.exists(os.path.join(self.tempdir, 'file3')))
    8292
    8393    def test_action_which_raises_error_causes_all_processing_to_stop_if_so_configured(self, noop):
     
    90100        self.assertEqual(noop.call_count, 2)
    91101        noop.assert_has_calls([
    92                 call(self.tmp.join(u'file1')),
    93                 call(self.tmp.join(u'file2')),
     102                call(os.path.join(self.tempdir, 'file1')),
     103                call(os.path.join(self.tempdir, 'file2')),
    94104                ])
    95         self.assertFalse(os.path.exists(self.tmp.join(u'file1')))
    96         self.assertTrue(os.path.exists(self.tmp.join(u'file2')))
    97         self.assertTrue(os.path.exists(self.tmp.join(u'file3')))
     105        self.assertFalse(os.path.exists(os.path.join(self.tempdir, 'file1')))
     106        self.assertTrue(os.path.exists(os.path.join(self.tempdir, 'file2')))
     107        self.assertTrue(os.path.exists(os.path.join(self.tempdir, 'file3')))
    98108
    99109
     
    105115        self.action.action = Mock(return_value=None)
    106116        self.action.retry_attempts = 6
    107         self.tmp = TempIO()
    108         self.file = self.tmp.putfile(u'file', u'')
     117        self.tempdir = tempfile.mkdtemp()
     118        self.file = self.write_file('file', '')
     119
     120    def tearDown(self):
     121        shutil.rmtree(self.tempdir)
     122
     123    def write_file(self, fname, content):
     124        path = os.path.join(self.tempdir, fname)
     125        with open(path, 'wt') as f:
     126            f.write(content)
     127        return path
    109128
    110129    def test_action_which_succeeds_is_only_called_once(self):
  • rattail/tests/filemon/test_config.py

    r8a6c147 rebd65a8  
    1 # -*- coding: utf-8 -*-
    2 
    3 from __future__ import unicode_literals
     1# -*- coding: utf-8; -*-
     2
     3from __future__ import unicode_literals, absolute_import
    44
    55import os
     6import shutil
     7import tempfile
    68from unittest import TestCase
    7 
    8 from fixture import TempIO
    99
    1010from rattail.config import make_config
     
    9999
    100100    def test_normalize_dirs(self):
    101         tmp = TempIO()
    102         dir1 = tmp.mkdir(u'dir1')
     101        tempdir = tempfile.mkdtemp()
     102        dir1 = os.path.join(tempdir, 'dir1')
     103        os.makedirs(dir1)
    103104        # dir2 will be pruned due to its not existing
    104         dir2 = tmp.mkdir(u'dir2')
    105         os.rmdir(dir2)
     105        dir2 = os.path.join(tempdir, 'dir2')
    106106        # file1 will be pruned due to its not being a directory
    107         file1 = tmp.putfile(u'file1', u'')
     107        file1 = os.path.join(tempdir, 'file1')
     108        with open(file1, 'wt') as f:
     109            f.write('')
    108110        self.config.set(u'rattail.filemon', u'foo.action.bar.func', u'os:remove')
    109111        self.config.set(u'rattail.filemon', u'foo.dirs', u' '.join([u'"{0}"'.format(d) for d in [dir1, dir2, file1]]))
     
    111113        self.assertEqual(len(profile.dirs), 1)
    112114        self.assertEqual(profile.dirs[0], dir1)
     115        shutil.rmtree(tempdir)
    113116
    114117
     
    116119
    117120    def setUp(self):
    118         self.tmp = TempIO()
     121        self.tempdir = tempfile.mkdtemp()
    119122        self.config = make_config([])
    120123        self.config.set(u'rattail.filemon', u'monitor', u'foo, bar')
    121         self.config.set(u'rattail.filemon', u'foo.dirs', u'"{0}"'.format(self.tmp))
     124        self.config.set(u'rattail.filemon', u'foo.dirs', u'"{0}"'.format(self.tempdir))
    122125        self.config.set(u'rattail.filemon', u'foo.actions', u'delete')
    123126        self.config.set(u'rattail.filemon', u'foo.action.delete.func', u'os:remove')
    124         self.config.set(u'rattail.filemon', u'bar.dirs', u'"{0}"'.format(self.tmp))
     127        self.config.set(u'rattail.filemon', u'bar.dirs', u'"{0}"'.format(self.tempdir))
    125128        self.config.set(u'rattail.filemon', u'bar.actions', u'delete')
    126129        self.config.set(u'rattail.filemon', u'bar.action.delete.func', u'os:remove')
    127130
     131    def tearDown(self):
     132        shutil.rmtree(self.tempdir)
     133
    128134    def test_returns_all_profiles_specified_in_monitor_option(self):
    129135        monitored = config.load_profiles(self.config)
     
    162168        self.config.parser.remove_option('rattail.filemon', 'monitor')
    163169        self.config.set(u'rattail.filemon', u'monitored', u'foo, bar')
    164         self.config.set(u'rattail.filemon', u'foo.dirs', u"['{0}']".format(self.tmp))
     170        self.config.set(u'rattail.filemon', u'foo.dirs', u"['{0}']".format(self.tempdir))
    165171        self.config.set(u'rattail.filemon', u'foo.actions', u"['os:remove']")
    166         self.config.set(u'rattail.filemon', u'bar.dirs', u"['{0}']".format(self.tmp))
     172        self.config.set(u'rattail.filemon', u'bar.dirs', u"['{0}']".format(self.tempdir))
    167173        self.config.set(u'rattail.filemon', u'bar.actions', u"['os:remove']")
    168174        monitored = config.load_profiles(self.config)
     
    204210
    205211    def test_normalize_dirs(self):
    206         tmp = TempIO()
    207         dir1 = tmp.mkdir(u'dir1')
     212        tempdir = tempfile.mkdtemp()
     213        dir1 = os.path.join(tempdir, 'dir1')
     214        os.makedirs(dir1)
    208215        # dir2 will be pruned due to its not existing
    209         dir2 = tmp.mkdir(u'dir2')
    210         os.rmdir(dir2)
     216        dir2 = os.path.join(tempdir, 'dir2')
    211217        # file1 will be pruned due to its not being a directory
    212         file1 = tmp.putfile(u'file1', u'')
     218        file1 = os.path.join(tempdir, 'file1')
     219        with open(file1, 'wt') as f:
     220            f.write('')
    213221        self.config.set(u'rattail.filemon', u'foo.dirs', u"[{0}]".format(u', '.join([u"'{0}'".format(d) for d in [dir1, dir2, file1]])))
    214222        profile = config.LegacyProfile(self.config, u'foo')
    215223        self.assertEqual(len(profile.dirs), 1)
    216224        self.assertEqual(profile.dirs[0], dir1)
     225        shutil.rmtree(tempdir)
    217226
    218227
     
    220229
    221230    def setUp(self):
    222         self.tmp = TempIO()
     231        self.tempdir = tempfile.mkdtemp()
    223232        self.config = make_config([])
    224233        self.config.set(u'rattail.filemon', u'monitored', u'foo, bar')
    225         self.config.set(u'rattail.filemon', u'foo.dirs', u"['{0}']".format(self.tmp))
     234        self.config.set(u'rattail.filemon', u'foo.dirs', u"['{0}']".format(self.tempdir))
    226235        self.config.set(u'rattail.filemon', u'foo.actions', u"['os:remove']")
    227         self.config.set(u'rattail.filemon', u'bar.dirs', u"['{0}']".format(self.tmp))
     236        self.config.set(u'rattail.filemon', u'bar.dirs', u"['{0}']".format(self.tempdir))
    228237        self.config.set(u'rattail.filemon', u'bar.actions', u"['os:remove']")
     238
     239    def tearDown(self):
     240        shutil.rmtree(self.tempdir)
    229241
    230242    def test_returns_all_profiles_specified_in_monitor_option(self):
  • rattail/tests/filemon/test_linux.py

    r8a6c147 rebd65a8  
    22
    33from __future__ import unicode_literals, absolute_import
     4
     5import os
     6import shutil
     7import tempfile
    48
    59from six.moves import queue
     
    711
    812from mock import Mock
    9 from fixture import TempIO
    1013
    1114from rattail.config import make_config
     
    1720
    1821    def setUp(self):
    19         self.tmp = TempIO()
     22        self.tempdir = tempfile.mkdtemp()
    2023        self.config = make_config([])
    2124        self.config.set(u'rattail.filemon', u'monitor', u'foo')
    22         self.config.set(u'rattail.filemon', u'foo.dirs', self.tmp)
     25        self.config.set(u'rattail.filemon', u'foo.dirs', self.tempdir)
    2326        self.config.set(u'rattail.filemon', u'foo.actions', u'noop')
    2427        self.config.set(u'rattail.filemon', u'foo.action.noop.func', u'rattail.filemon.actions:noop')
     
    2831        self.handler.my_init(self.profile)
    2932
     33    def tearDown(self):
     34        shutil.rmtree(self.tempdir)
     35
     36    def write_file(self, fname, content):
     37        path = os.path.join(self.tempdir, fname)
     38        with open(path, 'wt') as f:
     39            f.write(content)
     40        return path
     41
    3042    def test_in_access_event_does_nothing(self):
    31         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     43        event = Mock(pathname=self.write_file('file', ''))
    3244        self.handler.process_IN_ACCESS(event)
    3345        self.assertTrue(self.profile.queue.empty())
    3446
    3547    def test_in_attrib_event_does_nothing(self):
    36         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     48        event = Mock(pathname=self.write_file('file', ''))
    3749        self.handler.process_IN_ATTRIB(event)
    3850        self.assertTrue(self.profile.queue.empty())
    3951
    4052    def test_in_create_event_does_nothing(self):
    41         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     53        event = Mock(pathname=self.write_file('file', ''))
    4254        self.handler.process_IN_CREATE(event)
    4355        self.assertTrue(self.profile.queue.empty())
    4456
    4557    def test_in_modify_event_does_nothing(self):
    46         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     58        event = Mock(pathname=self.write_file('file', ''))
    4759        self.handler.process_IN_MODIFY(event)
    4860        self.assertTrue(self.profile.queue.empty())
    4961
    5062    def test_in_close_write_event_queues_file_if_profile_does_not_watch_locks(self):
    51         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     63        event = Mock(pathname=self.write_file('file', ''))
    5264        self.profile.watch_locks = False
    5365        self.handler.process_IN_CLOSE_WRITE(event)
    5466        self.assertEqual(self.profile.queue.qsize(), 1)
    55         self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file'))
     67        self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file'))
    5668
    5769    def test_in_close_write_event_does_nothing_if_profile_watches_locks(self):
    58         event = Mock(pathname=self.tmp.putfile(u'file.lock', u''))
     70        event = Mock(pathname=self.write_file('file.lock', ''))
    5971        self.profile.watch_locks = True
    6072        self.handler.process_IN_CLOSE_WRITE(event)
     
    6274
    6375    def test_in_moved_to_event_queues_file_if_profile_does_not_watch_locks(self):
    64         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     76        event = Mock(pathname=self.write_file('file', ''))
    6577        self.profile.watch_locks = False
    6678        self.handler.process_IN_MOVED_TO(event)
    6779        self.assertEqual(self.profile.queue.qsize(), 1)
    68         self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file'))
     80        self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file'))
    6981
    7082    def test_in_moved_to_event_does_nothing_if_profile_watches_locks(self):
    71         event = Mock(pathname=self.tmp.putfile(u'file.lock', u''))
     83        event = Mock(pathname=self.write_file('file.lock', ''))
    7284        self.profile.watch_locks = True
    7385        self.handler.process_IN_MOVED_TO(event)
     
    7587
    7688    def test_in_delete_event_queues_file_if_profile_watches_locks(self):
    77         event = Mock(pathname=self.tmp.putfile(u'file.lock', u''))
     89        event = Mock(pathname=self.write_file('file.lock', ''))
    7890        self.profile.watch_locks = True
    7991        self.handler.process_IN_DELETE(event)
    8092        self.assertEqual(self.profile.queue.qsize(), 1)
    81         self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file'))
     93        self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file'))
    8294
    8395    def test_in_moved_to_event_does_nothing_if_profile_does_not_watch_locks(self):
    84         event = Mock(pathname=self.tmp.putfile(u'file', u''))
     96        event = Mock(pathname=self.write_file('file', ''))
    8597        self.profile.watch_locks = False
    8698        self.handler.process_IN_DELETE(event)
  • rattail/tests/filemon/test_util.py

    r8a6c147 rebd65a8  
    33from __future__ import unicode_literals, absolute_import
    44
     5import os
     6import shutil
     7import tempfile
     8
    59from six.moves import queue
    610from unittest import TestCase
    7 
    8 from fixture import TempIO
    911
    1012from rattail.config import make_config
     
    1618
    1719    def setUp(self):
    18         self.tmp = TempIO()
     20        self.tempdir = tempfile.mkdtemp()
    1921        self.config = make_config([])
    2022        self.config.set(u'rattail.filemon', u'monitor', u'foo')
    21         self.config.set(u'rattail.filemon', u'foo.dirs', self.tmp)
     23        self.config.set('rattail.filemon', 'foo.dirs', self.tempdir)
    2224        self.config.set(u'rattail.filemon', u'foo.actions', u'noop')
    2325        self.config.set(u'rattail.filemon', u'foo.action.noop.func', u'rattail.filemon.actions:noop')
     
    2527        self.profile.queue = queue.Queue()
    2628
     29    def tearDown(self):
     30        shutil.rmtree(self.tempdir)
     31
     32    def write_file(self, fname, content):
     33        path = os.path.join(self.tempdir, fname)
     34        with open(path, 'wt') as f:
     35            f.write(content)
     36        return path
     37
    2738    def test_nothing_queued_if_no_files_exist(self):
    28         util.queue_existing(self.profile, self.tmp)
     39        util.queue_existing(self.profile, self.tempdir)
    2940        self.assertTrue(self.profile.queue.empty())
    3041
    3142    def test_normal_files_are_queued_but_not_folders(self):
    32         self.tmp.putfile(u'file', u'')
    33         self.tmp.mkdir(u'folder')
    34         util.queue_existing(self.profile, self.tmp)
     43        self.write_file('file', '')
     44        os.makedirs(os.path.join(self.tempdir, 'folder'))
     45        util.queue_existing(self.profile, self.tempdir)
    3546        self.assertEqual(self.profile.queue.qsize(), 1)
    36         self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file'))
     47        self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file'))
    3748        self.assertTrue(self.profile.queue.empty())
    3849
    3950    def test_if_profile_watches_locks_then_normal_files_are_queued_but_not_lock_files(self):
    4051        self.profile.watch_locks = True
    41         self.tmp.putfile(u'file1.lock', u'')
    42         self.tmp.putfile(u'file2', u'')
    43         util.queue_existing(self.profile, self.tmp)
     52        self.write_file('file1.lock', '')
     53        self.write_file('file2', '')
     54        util.queue_existing(self.profile, self.tempdir)
    4455        self.assertEqual(self.profile.queue.qsize(), 1)
    45         self.assertEqual(self.profile.queue.get_nowait(), self.tmp.join(u'file2'))
     56        self.assertEqual(self.profile.queue.get_nowait(), os.path.join(self.tempdir, 'file2'))
    4657        self.assertTrue(self.profile.queue.empty())
  • rattail/tests/importing/__init__.py

    r8a6c147 rebd65a8  
    1 # -*- coding: utf-8 -*-
     1# -*- coding: utf-8; -*-
    22
    33from __future__ import unicode_literals, absolute_import
  • rattail/tests/importing/test_handlers.py

    r8a6c147 rebd65a8  
    99from sqlalchemy import orm
    1010from mock import patch, Mock
    11 from fixture import TempIO
    1211
    1312from rattail.db import Session
     
    369368        self.handler = MockImportHandler(config=self.config)
    370369        self.importer = MockImporter(config=self.config)
     370        self.importer.handler = self.handler
    371371
    372372    def import_data(self, **kwargs):
  • rattail/tests/importing/test_importers.py

    r8a6c147 rebd65a8  
    1 # -*- coding: utf-8 -*-
     1# -*- coding: utf-8; -*-
    22
    33from __future__ import unicode_literals, absolute_import
     
    223223        data = [{'id': i} for i in range(1, 101)]
    224224        importer = importers.Importer(model_name='Foo', key='id', fields=['id'], empty_local_data=True)
     225        importer.handler = Mock(local_title="Nevermind")
    225226        with patch.object(importer, 'create_object'): # just mock that out
    226227            with patch.object(importer, 'flush_create_update') as flush:
     
    368369    def setUp(self):
    369370        self.importer = self.make_importer()
     371        self.importer.handler = Mock(local_title="Nevermind")
    370372
    371373    def test_create(self):
  • rattail/tests/importing/test_model.py

    r8a6c147 rebd65a8  
    1 # -*- coding: utf-8 -*-
     1# -*- coding: utf-8; -*-
    22
    33from __future__ import unicode_literals, absolute_import
     4
     5from mock import Mock
    46
    57from rattail.db import model, auth
     
    2729    def test_normalize_local_object(self):
    2830        importer = self.make_importer()
     31        importer.setup()
     32
    2933        user = model.User()
     34        user.username = 'fred'
     35        self.session.add(user)
     36        self.session.flush()
     37
    3038        data = importer.normalize_local_object(user)
    3139        self.assertFalse(data['admin'])
     40
    3241        user.roles.append(self.get_admin())
     42        self.session.flush()
    3343        data = importer.normalize_local_object(user)
    3444        self.assertTrue(data['admin'])
  • rattail/tests/importing/test_postgresql.py

    r8a6c147 rebd65a8  
    44
    55import datetime
     6import shutil
     7import tempfile
    68import unittest
    79
    810import sqlalchemy as sa
    911from sqlalchemy import orm
    10 from fixture import TempIO
    1112
    1213from rattail.db import Session, model
     
    2728
    2829    def setUp(self):
    29         self.tempio = TempIO()
     30        self.tempdir = tempfile.mkdtemp()
    3031        self.config = RattailConfig()
    31         self.config.set('rattail', 'workdir', self.tempio.realpath())
     32        self.config.set('rattail', 'workdir', self.tempdir)
    3233        self.config.set('rattail', 'timezone.default', 'America/Chicago')
    3334
    3435    def tearDown(self):
    35         self.tempio = None
     36        shutil.rmtree(self.tempdir)
    3637
    3738    def make_importer(self, **kwargs):
     
    130131    def setUp(self):
    131132        self.setup_rattail()
    132         self.tempio = TempIO()
    133         self.config.set('rattail', 'workdir', self.tempio.realpath())
     133        self.tempdir = tempfile.mkdtemp()
     134        self.config.set('rattail', 'workdir', self.tempdir)
    134135        self.importer = self.make_importer()
    135136
    136137    def tearDown(self):
    137138        self.teardown_rattail()
    138         self.tempio = None
     139        shutil.rmtree(self.tempdir)
    139140
    140141    def make_importer(self, **kwargs):
  • rattail/tests/importing/test_rattail.py

    r8a6c147 rebd65a8  
    88import sqlalchemy as sa
    99from mock import patch
    10 from fixture import TempIO
    1110
    1211from rattail.db import model, Session, SessionBase, auth
     
    138137    def test_normalize_host_object(self):
    139138        importer = self.make_importer()
     139        importer.setup()
     140
    140141        user = model.User()
     142        user.username = 'fred'
     143        self.session.add(user)
     144        self.session.flush()
     145
    141146        data = importer.normalize_host_object(user)
    142147        self.assertFalse(data['admin'])
     148
    143149        user.roles.append(self.get_admin())
     150        self.session.flush()
    144151        data = importer.normalize_host_object(user)
    145152        self.assertTrue(data['admin'])
  • rattail/tests/importing/test_rattail_bulk.py

    r8a6c147 rebd65a8  
    1 # -*- coding: utf-8 -*-
     1# -*- coding: utf-8; -*-
    22
    33from __future__ import unicode_literals, absolute_import
    44
     5import shutil
     6import tempfile
     7
    58from mock import patch, Mock
    6 from fixture import TempIO
    79
    810from rattail.importing import rattail_bulk as bulk
     
    1719    def setUp(self):
    1820        self.setup_rattail()
    19         self.tempio = TempIO()
    20         self.config.set('rattail', 'workdir', self.tempio.realpath())
     21        self.tempdir = tempfile.mkdtemp()
     22        self.config.set('rattail', 'workdir', self.tempdir)
    2123        self.handler = self.make_handler()
    2224
     
    2628    def tearDown(self):
    2729        self.teardown_rattail()
    28         self.tempio = None
     30        shutil.rmtree(self.tempdir)
    2931
    3032    @property
  • rattail/tests/importing/test_sqlalchemy.py

    r8a6c147 rebd65a8  
    66
    77import six
    8 from mock import patch
     8from mock import patch, Mock
    99
    1010import sqlalchemy as sa
     
    131131    def test_cache_local_data(self):
    132132        importer = self.make_importer(key='id', session=self.session)
     133        importer.handler = Mock(local_title="Nevermind")
    133134        cache = importer.cache_local_data()
    134135        self.assertEqual(len(cache), 3)
  • rattail/tests/test_config.py

    r8a6c147 rebd65a8  
    44
    55import os
     6import shutil
     7import tempfile
    68import unittest
    79from six.moves import configparser
    810
    911from mock import patch
    10 from fixture import TempIO
    1112
    1213from rattail import config
     
    9394
    9495    def setUp(self):
    95         self.tempio = TempIO()
     96        self.tempdir = tempfile.mkdtemp()
    9697
    9798    def tearDown(self):
    98         del self.tempio
     99        shutil.rmtree(self.tempdir)
     100
     101    def write_file(self, fname, content):
     102        path = os.path.join(self.tempdir, fname)
     103        with open(path, 'wt') as f:
     104            f.write(content)
     105        return path
    99106
    100107    def setup_files(self):
    101         self.site_path = self.tempio.putfile('site.conf', """
     108        self.site_path = self.write_file('site.conf', """
    102109[rattail]
    103110        """)
    104111
    105         self.host_path = self.tempio.putfile('host.conf', """
     112        self.host_path = self.write_file('host.conf', """
    106113[rattail.config]
    107114include = "{}"
    108115        """.format(self.site_path))
    109116
    110         self.app_path = self.tempio.putfile('app.conf', """
     117        self.app_path = self.write_file('app.conf', """
    111118[rattail.config]
    112119include = "{}"
    113120        """.format(self.host_path))
    114121
    115         self.custom_path = self.tempio.putfile('custom.conf', """
     122        self.custom_path = self.write_file('custom.conf', """
    116123[rattail.config]
    117124include = "%(here)s/app.conf"
     
    157164        self.setup_files()
    158165
    159         another_path = self.tempio.putfile('another.conf', """
     166        another_path = self.write_file('another.conf', """
    160167[rattail.config]
    161168include = "{custom}" "{site}" "{app}" "{site}" "{custom}"
     
    172179        self.assertFalse(os.path.exists(bogus_path))
    173180
    174         another_path = self.tempio.putfile('another.conf', """
     181        another_path = self.write_file('another.conf', """
    175182[rattail.config]
    176183include = "{bogus}" "{app}" "{bogus}" "{site}"
  • rattail/tests/test_files.py

    r8a6c147 rebd65a8  
    44
    55import os
    6 from unittest import TestCase
     6import shutil
     7import tempfile
     8import unittest
    79
    810import lockfile
    9 from fixture import TempIO
    1011
    1112from rattail import files
    1213
    1314
    14 class TestLockingCopy(TestCase):
     15class TestLockingCopy(unittest.TestCase):
    1516
    1617    def setUp(self):
    17         self.tmp = TempIO()
    18         self.src = self.tmp.mkdir(u'src')
    19         self.dst = self.tmp.mkdir(u'dst')
    20         self.src_file = self.src.putfile('somefile', '')
     18        self.tempdir = tempfile.mkdtemp()
     19
     20        self.srcdir = os.path.join(self.tempdir, 'src')
     21        os.makedirs(self.srcdir)
     22
     23        self.dstdir = os.path.join(self.tempdir, 'dst')
     24        os.makedirs(self.dstdir)
     25
     26        self.src_file = os.path.join(self.srcdir, 'somefile')
     27        with open(self.src_file, 'wt') as f:
     28            f.write('')
     29
     30    def tearDown(self):
     31        shutil.rmtree(self.tempdir)
    2132
    2233    def test_normal_copy_succeeds(self):
    23         files.locking_copy(self.src_file, self.dst)
    24         dst_file = os.path.join(self.dst, u'somefile')
     34        files.locking_copy(self.src_file, self.dstdir)
     35        dst_file = os.path.join(self.dstdir, 'somefile')
    2536        self.assertTrue(os.path.exists(dst_file))
    2637        self.assertTrue(os.path.isfile(dst_file))
    27         self.assertFalse(os.path.exists(os.path.join(self.dst, u'somefile.lock')))
     38        self.assertFalse(os.path.exists(os.path.join(self.dstdir, 'somefile.lock')))
  • setup.py

    r8a6c147 rebd65a8  
    133133
    134134        'coverage',                     # 3.6
    135         'fixture',                      # 1.5
    136135        'mock',                         # 1.0.1
    137136        'nose',                         # 1.3.0
Note: See TracChangeset for help on using the changeset viewer.