def make_fixtures(self): self.app.post('/api/1/networks', headers=AUTHZ_HEADER, data=NETWORK_FIXTURE) network = Network.by_slug(NETWORK_FIXTURE['slug']) Schema.create(network, Schema.RELATION, h.TEST_RELATION_SCHEMA) Schema.create(network, Schema.ENTITY, h.TEST_ENTITY_SCHEMA) res = self.app.post('/api/1/net/entities', headers=AUTHZ_HEADER, data=ENTITY1_FIXTURE, follow_redirects=True) body = json.loads(res.data) self.source_id = body['id'] res = self.app.post('/api/1/net/entities', headers=AUTHZ_HEADER, data=ENTITY2_FIXTURE, follow_redirects=True) body = json.loads(res.data) self.target_id = body['id'] RELATION_FIXTURE['source'] = self.source_id RELATION_FIXTURE['target'] = self.target_id res = self.app.post('/api/1/net/relations', headers=AUTHZ_HEADER, data=RELATION_FIXTURE, follow_redirects=True) print res.data body = json.loads(res.data) self.id = body['id']
def setUp(self): self.app = make_test_app() self.app.post('/api/1/networks', headers=AUTHZ_HEADER, data=NETWORK_FIXTURE) network = Network.by_slug(NETWORK_FIXTURE['slug']) Schema.create(network, Schema.RELATION, h.TEST_RELATION_SCHEMA) Schema.create(network, Schema.ENTITY, h.TEST_ENTITY_SCHEMA) db.session.commit()
def make_fixtures(self): self.app.post('/api/1/networks', headers=AUTHZ_HEADER, data=NETWORK_FIXTURE) network = Network.by_slug(NETWORK_FIXTURE['slug']) Schema.create(network, Schema.RELATION, h.TEST_RELATION_SCHEMA) Schema.create(network, Schema.ENTITY, h.TEST_ENTITY_SCHEMA) db.session.commit() res = self.app.post('/api/1/net/entities', headers=AUTHZ_HEADER, data=ENTITY_FIXTURE, follow_redirects=True) body = json.loads(res.data) self.id = body['id']
def sqlshell(network): import sys from grano.model import Network from pprint import pprint network = Network.by_slug(network) print network while True: sys.stdout.write("%s> " % network.slug) command = sys.stdin.readline() try: rp = network.raw_query(command) pprint(rp.fetchall()) except Exception, e: print e
def _check(value): if context.network and context.network.slug == value: return True if Network.by_slug(value) is not None: return "This network name is already in use, please choose another." return True
def _get_network(slug): network = Network.by_slug(slug) if network is None: raise NotFound("No such network: %s" % slug) require.network.read(network) return network