def test_filter_true(self): # Load repository repository = self.ogm.repository('Page') page_fixture = PageFixture(self.ogm) page_fixture.clean() page_fixture.load() # Load objects website = page_fixture._parent['Website'].get('Website1') page = page_fixture.get('Website1Page1') # Ability to get() page_found = repository.get(page.eid) self.assertEquals(page_found.eid, page.eid) self.assertEquals(page_found.isHostedBy().eid, website.eid) # Ability to filter on eid results = repository.filter(eid=page.eid) page_found = next(results) self.assertEquals(page_found.eid, page.eid) self.assertEquals(page_found.isHostedBy().eid, website.eid) # Ability to filter on a set of parameters results = repository.filter(title=page.title, url=page.url) page_found = next(results) self.assertEquals(page_found.eid, page.eid) self.assertEquals(page_found.isHostedBy().eid, website.eid) # Ability to lazy-load pages = list(website.hosts()) self.assertEquals(pages[0].eid, page.eid) # self.assertEquals(website.hosts()[0], page) self.assertEquals(len(pages), 2)
def test_create(self): page_fixture = PageFixture(self.ogm) page_fixture.clean() page_fixture.load() inV = page_fixture._parent['Website'].get('Website1') outV = page_fixture.get('Website1Page1') # Ability to create an entity from the repository : hosts = self.ogm.repository('WebsiteHostsPage')(outV, inV, since=123) self.assertEquals(inV.eid, hosts._inV) self.assertEquals(outV.eid, hosts._outV) self.assertEquals(123, hosts.since) self.assertIsInstance(hosts, WebsiteHostsPage) # Ability to create an entity from the repository create method : hosts = self.ogm.repository('WebsiteHostsPage').create(outV, inV, since=30) self.assertEquals(inV.eid, hosts._inV) self.assertEquals(outV.eid, hosts._outV) self.assertEquals(30, hosts.since) self.assertIsInstance(hosts, WebsiteHostsPage)
def test_filter_true(self): # Load repository repository = self.ogm.repository('Page') page_fixture = PageFixture(self.ogm) page_fixture.clean() page_fixture.load() # Load objects website = page_fixture._parent['Website'].get('Website1') page = page_fixture.get('Website1Page1') # Ability to get() page_found = repository.get(page.eid) self.assertEquals(page_found.eid, page.eid) self.assertEquals(page_found.isHostedBy().eid, website.eid) # Ability to filter on eid results = repository.filter(eid=page.eid) page_found = next(results) self.assertEquals(page_found.eid, page.eid) self.assertEquals(page_found.isHostedBy().eid, website.eid) # Ability to filter on a set of parameters results = repository.filter( title=page.title, url=page.url ) page_found = next(results) self.assertEquals(page_found.eid, page.eid) self.assertEquals(page_found.isHostedBy().eid, website.eid) # Ability to lazy-load pages = list(website.hosts()) self.assertEquals(pages[0].eid, page.eid) # self.assertEquals(website.hosts()[0], page) self.assertEquals(len(pages), 2)
def test_flush_relation(self): # Load repository page_fixture = PageFixture(self.ogm) page_fixture.clean() page_fixture.load() outV = page_fixture.get('Website1Page1') inV = page_fixture._parent['Website'].get('Website1') # Ability to create an entity directly from its model : hosts = WebsiteHostsPage(since=2012) str(hosts) self.assertEquals('hosts', hosts.label) self.assertEquals(2012, hosts.since) self.assertEquals(None, hosts._client) self.assertIsInstance(hosts, WebsiteHostsPage) self.assertIn('since', hosts._properties) self.assertEquals({}, hosts._data) self.assertTrue(hosts._initialized) # Ability to set a property as a simple setter hosts.accessible = True self.assertEquals(True, hosts.accessible) self.assertIn('accessible', hosts._properties) self.assertEquals({}, hosts._data) self.assertTrue(hosts._initialized) # Flush the Relationship self.ogm.add(hosts) # self.assertRaises(Exception, self.ogm.flush()) hosts.set_outV(outV) hosts.set_inV(inV) self.ogm.flush() # Verify eid = hosts.eid self.assertTrue(eid > 0) self.assertEquals(outV.eid, hosts._outV) self.assertEquals(inV.eid, hosts._inV) self.assertEquals('hosts', hosts.label) self.assertEquals(2012, hosts.since) self.assertEquals(True, hosts.accessible) self.assertEquals({u'since': 2012, u'accessible': 1}, hosts._data) self.assertTrue(hosts._initialized) hosts_titan = self.ogm.repository('WebsiteHostsPage').get(eid) hosts_titan = self.ogm.query('g.e(eid)', {'eid':eid}) hosts_titan = next(hosts_titan) self.assertEquals(eid, hosts_titan.eid) self.assertEquals('hosts', hosts_titan.label) self.assertEquals(2012, hosts_titan.since) self.assertEquals(True, hosts_titan.accessible) # Update hosts.accessible = False hosts.since = 2013 self.assertEquals('hosts', hosts.label) self.assertEquals(2013, hosts.since) self.assertEquals(False, hosts.accessible) # Re-update self.ogm.flush() self.assertEquals(eid, hosts.eid) self.assertEquals(2013, hosts.since) self.assertEquals(False, hosts.accessible) # Still a bug here, for some reason the edge id changes on the database # side... # hosts_titan = self.ogm.repository('WebsiteHostsPage').get(eid) hosts_titan = self.ogm.query('g.e(eid)', {'eid':hosts.eid}) return hosts_titan = next(hosts_titan) self.assertEquals(eid, hosts_titan.eid) self.assertEquals('hosts', hosts_titan.label) self.assertEquals(2013, hosts_titan.since) self.assertEquals(False, hosts_titan.accessible)