def test_init_no_id(self): property = Property(name='name', value='value') self.assertIsNotNone(property) self.assertIsNone(property.id) self.assertEqual('name', property.name) self.assertEqual('value', property.value) self.assertEqual({'value': 'value', 'name': 'name'}, property.to_document())
def test_from_document(self): property1 = Property.from_document({'value': 'value', 'name': 'name'}) self.assertIsNotNone(property1) self.assertIsNone(property1.id) self.assertEqual('name', property1.name) self.assertEqual('value', property1.value) property2 = Property.from_document({'_id': '666', 'value': 'value', 'name': 'name'}) self.assertIsNotNone(property2) self.assertIsNotNone(property2.id) self.assertEqual('666', property2.id) self.assertEqual('666', property2.id) self.assertEqual('name', property2.name) self.assertEqual('value', property2.value)
def test_repr_with_id(self): property2 = Property.from_document({ '_id': '666', 'value': 'value', 'name': 'name' }) self.assertEquals("<Property(id='666', name='name', value='value')>", str(property2))
def add_property(self, name, value): collection = self.collection() prop = collection.find_one({MongoPropertyStore.NAME: name}) if prop is not None: prop['value'] = value YLogger.info(self, "Replacing property [%s] = [%s]", name, value) result = collection.replace_one({'_id': prop['_id']}, prop) return bool(result.modified_count > 0) prop = Property(name, value) YLogger.info(self, "Adding property [%s] = [%s]", name, value) return self.add_document(prop)
def add_property(self, name, value): collection = self.collection() property = collection.find_one({MongoPropertyStore.NAME: name}) if property is not None: property.value = value collection.replace_document(property) YLogger.debug(self, "Replacing property [%s] = [%s]", name, value) else: property = Property(name, value) self.add_document(property) YLogger.debug(self, "Adding property [%s] = [%s]", name, value) return True
def test_repr_no_id(self): property1 = Property.from_document({'value': 'value', 'name': 'name'}) self.assertEquals("<Property(id='n/a', name='name', value='value')>", str(property1))
def test_from_document_no_id(self): property1 = Property.from_document({'value': 'value', 'name': 'name'}) self.assertIsNotNone(property1) self.assertIsNone(property1.id) self.assertEqual('name', property1.name) self.assertEqual('value', property1.value)