예제 #1
0
    def test_raises_exception_if_dir_does_not_exist_after_creation_attempt(self):

        # test
        with patch.object(os.path, 'exists', Mock(return_value=False)):
            with patch.object(os, 'makedirs', Mock()) as fake_makedirs:
                try:
                    db = Database('sqlite:///test_database1.db')
                    db._create_path()
                except Exception as exc:
                    self.assertIn('Couldn\'t create directory', str(exc))
                fake_makedirs.assert_called_once_with('/')
예제 #2
0
    def test_raises_exception_if_dir_does_not_exist_after_creation_attempt(
            self):

        # test
        with patch.object(os.path, 'exists', Mock(return_value=False)):
            with patch.object(os, 'makedirs', Mock()) as fake_makedirs:
                try:
                    db = Database('sqlite:///test_database1.db')
                    db._create_path()
                except Exception as exc:
                    self.assertIn('Couldn\'t create directory', str(exc))
                fake_makedirs.assert_called_once_with('/')
예제 #3
0
    def test_ignores_exception_if_makedirs_failed(self):

        # prepare state.
        calls = []

        def my_exists(p):
            # returns False for first call and True for second.
            if p in calls:
                return True
            calls.append(p)
            return False

        # test
        with patch.object(os, 'makedirs', Mock(side_effect=Exception('Fake exception'))) as fake_makedirs:
            with patch.object(os.path, 'exists', Mock(side_effect=my_exists)):
                db = Database('sqlite:///test_database1.db')
                db._create_path()

                fake_makedirs.assert_called_once_with('/')
예제 #4
0
    def test_makes_database_directory(self):

        # prepare state

        calls = []

        def my_exists(p):
            # returns False for first call and True for second.
            if p in calls:
                return True
            calls.append(p)
            return False

        # test
        with patch.object(os, 'makedirs', Mock()) as fake_makedirs:
            with patch.object(os.path, 'exists', Mock(side_effect=my_exists)):
                db = Database('sqlite:///test_database1.db')
                db._create_path()

                # test calls
                fake_makedirs.assert_called_once_with('/')
예제 #5
0
    def test_makes_database_directory(self):

        # prepare state

        calls = []

        def my_exists(p):
            # returns False for first call and True for second.
            if p in calls:
                return True
            calls.append(p)
            return False

        # test
        with patch.object(os, 'makedirs', Mock()) as fake_makedirs:
            with patch.object(os.path, 'exists', Mock(side_effect=my_exists)):
                db = Database('sqlite:///test_database1.db')
                db._create_path()

                # test calls
                fake_makedirs.assert_called_once_with('/')
예제 #6
0
    def test_ignores_exception_if_makedirs_failed(self):

        # prepare state.
        calls = []

        def my_exists(p):
            # returns False for first call and True for second.
            if p in calls:
                return True
            calls.append(p)
            return False

        # test
        with patch.object(
                os, 'makedirs', Mock(
                    side_effect=Exception('Fake exception'))) as fake_makedirs:
            with patch.object(os.path, 'exists', Mock(side_effect=my_exists)):
                db = Database('sqlite:///test_database1.db')
                db._create_path()

                fake_makedirs.assert_called_once_with('/')