def test_page_kv_stores_value(self): doc = create_some_doc(self.user) page = Page( text="Some cool content in page model", user=self.user, document=doc ) page.save() page.kv.update( [ { 'key': 'shop', 'kv_type': TEXT, 'kv_format': '', 'value': 'lidl' }, { 'key': 'price', 'kv_type': MONEY, 'kv_format': 'dd,cc', 'value': '10,99' } ] ) page = Page.objects.get(id=page.id) kvstore_set = set([kv.value for kv in page.kv.all()]) self.assertEqual( kvstore_set, set(["10,99", "lidl"]) ) # now update value of key=shop # get ID's of newly created KVStoreNode instances _kv_list_of_dicts = [ { 'key': item.key, 'id': item.id, 'kv_type': item.kv_type, 'kv_format': item.kv_format, 'value': item.value } for item in page.kv.all() ] # find key titled 'total', and rename it to 'total_price' for obj_with_lidl_value in _kv_list_of_dicts: if obj_with_lidl_value['value'] == 'lidl': break else: obj_with_lidl_value = None if obj_with_lidl_value: obj_with_lidl_value['value'] = 'rewe' page.kv.update(_kv_list_of_dicts) kvstore_set = set([kv.value for kv in page.kv.all()]) self.assertEqual( kvstore_set, set(["10,99", "rewe"]) )
def test_basic_kvstore_for_page(self): doc = create_some_doc(self.user) page = Page(text="Some cool content in page model", user=self.user, document=doc) page.save() self.assertEqual(0, page.kvstore.count()) page.kv.add(key="shop") self.assertEqual(1, page.kvstore.count())
def test_page_not_matching_search(self): doc = create_some_doc(self.user) page = Page(text="Some cool content in page model", user=self.user, document=doc) page.save() result = Page.objects.search("andromeda") self.assertEqual(result.count(), 0)
def test_page_matching_search(self): doc = self.get_whatever_doc() page = Page(text="Some cool content in page model", user=self.user, document=doc) page.save() result = Page.objects.search("cool") self.assertEquals(result.count(), 1)
def test_page_kv_store_get_and_set(self): """ test that kv api works: page.kv['shop'] = 'lidl' page.kv['price'] = '11.99' page.kv['shop'] == 'lidl' page.kv['price'] == '11.99' """ doc = create_some_doc(self.user) page = Page(text="Receipt page", user=self.user, document=doc) page.save() # set page's kv to shop and price page.kv.update([{'key': 'shop'}, {'key': 'price'}]) # now following setters and getters should work page.kv['shop'] = 'lidl' page.kv['price'] = '42.50' page = Page.objects.get(text="Receipt page") self.assertEqual(page.kv['shop'], 'lidl') self.assertEqual(page.kv['price'], '42.50') with self.assertRaises(KV.MetadataKeyDoesNotExist): page.kv['blah'] = '10' with self.assertRaises(KV.MetadataKeyDoesNotExist): page.kv['blah']