Exemple #1
0
    def test_cleanup(self):
        ids = [ObjectId() for x in range(3)]
        cleanup_ids = copy(ids)
        cleanup_ids.reverse()

        def insert_results(*args, **kwargs):
            return ids.pop(0)

        self.collection.insert = Mock(side_effect=insert_results)

        factory = Factory(self.collection)
        factory.default({
            "first_name": 'John',
            "last_name": 'Smith',
            "age": 32
        })
        factory.document('admin', {
            "first_name": 'Mick',
            "last_name": 'Jones',
            "age": 33
        })

        for x in range(2):
            factory.create()
        factory.create('admin')

        factory.cleanup()

        expected_calls = [call(oid) for oid in cleanup_ids]
        self.assertEqual(self.collection.remove.mock_calls, expected_calls)
        self.collection.reset_mock()
        factory.cleanup()
        self.assertFalse(self.collection.remove.called)
Exemple #2
0
    def test_cleanup(self):
        ids = [ObjectId() for x in range(3)]
        cleanup_ids = copy(ids)
        cleanup_ids.reverse()

        def insert_results(*args):
            return ids.pop(0)

        self.collection.insert = Mock(side_effect=insert_results)

        factory = Factory(self.collection,
            first_name='John',
            last_name='Smith',
            age=32)

        for x in range(3):
            factory.create()

        factory.cleanup()

        expected_calls = [call(oid) for oid in cleanup_ids]
        self.assertEqual(self.collection.remove.mock_calls, expected_calls)

        self.collection.reset_mock()

        factory.cleanup()

        self.assertFalse(self.collection.remove.called)
Exemple #3
0
    def test_cleanup_nothing_to_do(self):
        factory = Factory(self.collection,
            first_name='John',
            last_name='Smith',
            age=32)

        factory.cleanup()

        expected_calls = []
        self.assertEqual(self.collection.remove.mock_calls, expected_calls)
Exemple #4
0
    def test_cleanup_nothing_to_do(self):
        factory = Factory(self.collection)
        factory.default({
            "first_name": 'John',
            "last_name": 'Smith',
            "age": 32
        })

        factory.cleanup()

        expected_calls = []
        self.assertEqual(self.collection.remove.mock_calls, expected_calls)