def test_cleanup(self): object_id = ObjectId() self.user_collection.insert = Mock(return_value=object_id) create("user") cleanup() self.user_collection.remove.assert_called_with(object_id) self.company_collection.remove.assert_called_with(self.company_id)
def test_create(self): to_return = { "_id": ObjectId, "first": "Mike", "last": "Smith", "prefs": { "receives_sms": True, "receives_email": False }, "company_id": self.company_id, "email": "*****@*****.**", "age": 21 } self.user_collection.insert = Mock(return_value=to_return["_id"]) self.user_collection.find_one = Mock(return_value=to_return) created = create("user", first='Mike') self.user_collection.insert.assert_called_with({ "first": "Mike", "last": "Smith", "prefs": { "receives_sms": True, "receives_email": False }, "company_id": self.company_id, "email": "*****@*****.**", "age": 21 }) self.user_collection.find_one.assert_called_with(to_return["_id"]) self.assertDictEqual(created, to_return)
def build(*args): # Flatten an function overrides instance_overrides = {} for key, value in overrides.iteritems(): if callable(value): instance_overrides[key] = value(*args) else: instance_overrides[key] = value return monufacture.create(factory_, document_, **instance_overrides)["_id"]
def test_create_named_document(self): created = create("user", "admin", first='Mike') expected = { "first": "Mike", "last": "Jones", "prefs": { "receives_sms": False, "receives_email": True, "v": 4 }, "company_id": self.company_id, "email": "*****@*****.**", "age": 21, "created": "now", "v": 4 } self.assertDictContainsSubset(expected, created)
def test_create(self): created = create("user", first='Mike') expected = { "first": "Mike", "last": "Smith", "prefs": { "receives_sms": True, "receives_email": False, "v": 4 }, "company_id": self.company_id, "email": "*****@*****.**", "age": 21, "created": "now" } self.assertDictContainsSubset(expected, created)
def test_debug_logging(self, debug): monufacture.debug = True def check_log(factory, document=None, **overrides): debug.assert_called_once_with( "CREATED [%s]: %s, document=%s, overrides=%s", ANY, factory, document, overrides) debug.reset_mock() create('company') check_log('company') create('company', 'pharma') check_log('company', 'pharma') create('company', thing='blah') check_log('company', thing='blah') create_list(1, 'company', 'pharma', thing='blah') check_log('company', 'pharma', thing='blah')
def test_cleanup(self): before_count = self.user_collection.count() create("user") cleanup() after_count = self.user_collection.count() self.assertEqual(before_count, after_count)
def test_some_other_functionality(self): user = create("user", first="Joe") self.assertEqual(user_collection.count(), 1) self.assertEqual("Joe", user['first'])
def build(*args): collection = monufacture.get_factory(factory).collection.name _id = monufacture.create(factory, document, **overrides)["_id"] return DBRef(collection, _id)
def test_create_collectionless_document(self): with self.assertRaises(IOError): create('fake')
def build(*args): return { "$id": monufacture.create(factory, document, **overrides)["_id"], "$ref": monufacture.get_factory(factory).collection.name }
def build(*args): return { "$id": monufacture.create(name)["_id"], "$ref": type }
def build(*args): return monufacture.create(name)["_id"]