Пример #1
0
 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']
Пример #2
0
 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']
Пример #3
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network()
     self.network.title = 'Net'
     self.network.slug = 'net'
     db.session.add(self.network)
     db.session.commit()
     self.context = ValidationContext(network=self.network)
Пример #4
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network.create({'title': 'Net', 'slug': 'net'})
     self.schema = Schema.create(self.network, Schema.ENTITY,
                                 h.TEST_ENTITY_SCHEMA)
     self.rschema = Schema.create(self.network, Schema.RELATION,
                                  h.TEST_RELATION_SCHEMA)
     db.session.commit()
     self.context = ValidationContext(network=self.network)
Пример #5
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network.create({'title': 'Net', 'slug': 'net'})
     self.schema = Schema.create(self.network, Schema.ENTITY,
                                 h.TEST_ENTITY_SCHEMA)
     self.rschema = Schema.create(self.network, Schema.RELATION,
                                 h.TEST_RELATION_SCHEMA)
     db.session.commit()
     self.context = ValidationContext(network=self.network)
Пример #6
0
 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()
Пример #7
0
def create():
    """ Create a new network. """
    require.network.create()
    data = request_content(request)
    context = ValidationContext()
    data = validate_network(dict(data.items()), context)
    network = Network.create(data)
    db.session.commit()
    url = url_for(".get", slug=network.slug)
    return jsonify(network, status=201, headers={"location": url})
Пример #8
0
def create():
    """ Create a new network. """
    require.network.create()
    data = request_content(request)
    context = ValidationContext()
    data = validate_network(dict(data.items()), \
            context)
    network = Network.create(data)
    db.session.commit()
    url = url_for('.get', slug=network.slug)
    return jsonify(network, status=201, headers={'location': url})
Пример #9
0
 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()
Пример #10
0
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
Пример #11
0
 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']
Пример #12
0
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
Пример #13
0
 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']
Пример #14
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network.create({'title': 'Net', 'slug': 'net'})
     self.schema = Schema.create(self.network, Schema.RELATION,
                                 h.TEST_RELATION_SCHEMA)
     db.session.commit()
     self.eschema = Schema.create(self.network, Schema.ENTITY,
                                  h.TEST_ENTITY_SCHEMA)
     self.context = ValidationContext(network=self.network)
     entity = deepcopy(TEST_ENTITY)
     entity['network'] = self.network.slug
     entity = validate_entity(entity, self.eschema, self.context)
     entity['title'] = 'Alice'
     a = self.network.Entity.create(self.eschema, entity)
     entity['title'] = 'Bob'
     b = self.network.Entity.create(self.eschema, entity)
     TEST_RELATION['source'] = a.id
     TEST_RELATION['target'] = b.id
     db.session.commit()
Пример #15
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network.create({'title': 'Net', 'slug': 'net'})
     self.schema = Schema.create(self.network, Schema.RELATION,
                                 h.TEST_RELATION_SCHEMA)
     db.session.commit()
     self.eschema = Schema.create(self.network, Schema.ENTITY,
                                  h.TEST_ENTITY_SCHEMA)
     self.context = ValidationContext(network=self.network)
     entity = deepcopy(TEST_ENTITY)
     entity['network'] = self.network.slug
     entity = validate_entity(entity, self.eschema, self.context)
     entity['title'] = 'Alice'
     a = self.network.Entity.create(self.eschema, entity)
     entity['title'] = 'Bob'
     b = self.network.Entity.create(self.eschema, entity)
     TEST_RELATION['source'] = a.id
     TEST_RELATION['target'] = b.id
     db.session.commit()
Пример #16
0
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
Пример #17
0
def index():
    """ List all available networks. """
    require.network.list()
    networks = Network.all()
    return jsonify(networks)
Пример #18
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network.create({'title': 'Net', 'slug': 'net'})
Пример #19
0
 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
Пример #20
0
 def setUp(self):
     self.client = h.make_test_app()
     self.network = Network.create({'title': 'Net', 'slug': 'net'})
Пример #21
0
 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
Пример #22
0
def index():
    """ List all available networks. """
    require.network.list()
    networks = Network.all()
    return jsonify(networks)
Пример #23
0
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