Ejemplo n.º 1
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id='user_3')
     self.col = self.create_collection()
     book = {
         'schema': 'PlainText',
         'properties': {
             'name': 'The Book',
             'fileName': 'book.txt',
         }
     }
     self.book = Entity.create(book, self.col)
     self.book_id = self.col.ns.sign(self.book.id)
     self.data = {
         'schema': 'LegalEntity',
         'properties': {
             'name': 'Winnie the Pooh',
             'country': 'pa',
             'proof': self.book_id
         }
     }
     self.ent = Entity.create(self.data, self.col)
     self.id = self.col.ns.sign(self.ent.id)
     db.session.commit()
     self.col_id = str(self.col.id)
     index_entity(self.book)
     index_entity(self.ent)
Ejemplo n.º 2
0
def create_entity(data, collection, role=None, sync=False):
    entity = Entity.create(data, collection)
    collection.touch()
    db.session.commit()
    index.index_entity(entity, sync=sync)
    refresh_entity(entity)
    return collection.ns.sign(entity.id)
Ejemplo n.º 3
0
 def test_api_merge(self):
     index_entity(self.ent)
     index_entity(self.other)
     url = '/api/2/entities/%s/merge/%s' % (self.ent.id, self.other.id)
     res = self.client.delete(url, content_type='application/json')
     assert res.status_code == 403, res.status_code
     _, headers = self.login(is_admin=True)
     res = self.client.delete(url, headers=headers,
                              content_type='application/json')
     data = res.json['properties']
     assert 'bear' in data['description'][0], data
     assert 'pa' in data['country'], data
Ejemplo n.º 4
0
def upsert_entity(data, collection, sync=False):
    entity = None
    entity_id = collection.ns.sign(data.get('id'))
    if entity_id is not None:
        entity = Entity.by_id(entity_id,
                              collection=collection,
                              deleted=True)
    # TODO: migrate softly from index.
    if entity is None:
        entity = Entity.create(data, collection)
    else:
        entity.update(data, collection)
    collection.touch()
    db.session.commit()
    delete_aggregator_entity(collection, entity.id)
    index.index_entity(entity, sync=sync)
    refresh_entity(entity.id, sync=sync)
    refresh_collection(collection.id, sync=sync)
    return entity.id
Ejemplo n.º 5
0
def upsert_entity(data, collection, validate=True, sync=False):
    """Create or update an entity in the database. This has a side hustle
    of migrating entities created via the _bulk API or a mapper to a
    database entity in the event that it gets edited by the user.
    """
    entity = None
    entity_id = collection.ns.sign(data.get('id'))
    if entity_id is not None:
        entity = Entity.by_id(entity_id, collection=collection, deleted=True)
    # TODO: migrate softly from index.
    if entity is None:
        entity = Entity.create(data, collection, validate=validate)
    else:
        entity.update(data, collection, validate=validate)
    collection.touch()
    db.session.commit()
    delete_aggregator_entity(collection, entity.id)
    index.index_entity(entity, sync=sync)
    refresh_entity(entity.id, sync=sync)
    refresh_collection(collection.id, sync=sync)
    return entity.id
Ejemplo n.º 6
0
 def test_profile_expand(self):
     usg = {
         "schema": "PublicBody",
         "properties": {
             "name": "US Government"
         },
     }
     usg = self.create_entity(usg, self.col2)
     index_entity(usg)
     membership = {
         "schema": "Membership",
         "properties": {
             "organization": usg.id,
             "member": self.ent2.id,
             "role": "Chief executive",
         },
     }
     membership = self.create_entity(membership, self.col2)
     index_entity(membership)
     passport = {
         "schema": "Passport",
         "properties": {
             "holder": self.ent1.id
         },
     }
     passport = self.create_entity(passport, self.col1)
     index_entity(passport)
     url = "/api/2/profiles/%s/expand" % self.profile.id
     res = self.client.get(url)
     assert res.status_code == 403, res.json
     _, headers = self.login(foreign_id="rolex")
     res = self.client.get(url, headers=headers)
     assert res.status_code == 200, res.json
     assert res.json["total"] == 2, res.json
Ejemplo n.º 7
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id='user_3')
     self.col = self.create_collection()
     book = {
         'schema': 'PlainText',
         'properties': {
             'name': 'The Book',
             'fileName': 'book.txt',
         }
     }
     self.book = self.create_entity(book, self.col)
     self.book_id = self.col.ns.sign(self.book.id)
     self.data = {
         'schema': 'LegalEntity',
         'properties': {
             'name': 'Winnie the Pooh',
             'country': 'pa',
             'proof': self.book_id,
             'incorporationDate': datetime.datetime(1926, 12,
                                                    24).isoformat()  # noqa
         }
     }
     self.ent = self.create_entity(self.data, self.col)
     self.id = self.col.ns.sign(self.ent.id)
     self.data2 = {
         'schema': 'LegalEntity',
         'properties': {
             'name': 'Tom & Jerry',
             'country': 'pa',
             'proof': self.book_id,
             'incorporationDate': datetime.datetime(1940, 2,
                                                    10).isoformat()  # noqa
         }
     }
     self.ent2 = self.create_entity(self.data2, self.col)
     self.id2 = self.col.ns.sign(self.ent2.id)
     db.session.commit()
     self.col_id = str(self.col.id)
     index_entity(self.book)
     index_entity(self.ent)
     index_entity(self.ent2)
Ejemplo n.º 8
0
 def setUp(self):
     super(EntitiesApiTestCase, self).setUp()
     self.rolex = self.create_user(foreign_id="user_3")
     self.col = self.create_collection()
     book = {
         "schema": "PlainText",
         "properties": {
             "name": "The Book",
             "fileName": "book.txt",
         },
     }
     self.book = self.create_entity(book, self.col)
     self.book_id = self.col.ns.sign(self.book.id)
     self.data = {
         "schema": "LegalEntity",
         "properties": {
             "name": "Winnie the Pooh",
             "country": "pa",
             "proof": self.book_id,
             "incorporationDate": datetime.datetime(1926, 12,
                                                    24).isoformat(),  # noqa
         },
     }
     self.ent = self.create_entity(self.data, self.col)
     self.id = self.col.ns.sign(self.ent.id)
     self.data2 = {
         "schema": "LegalEntity",
         "properties": {
             "name": "Tom & Jerry",
             "country": "pa",
             "proof": self.book_id,
             "incorporationDate": datetime.datetime(1940, 2,
                                                    10).isoformat(),  # noqa
         },
     }
     self.ent2 = self.create_entity(self.data2, self.col)
     self.id2 = self.col.ns.sign(self.ent2.id)
     db.session.commit()
     self.col_id = str(self.col.id)
     index_entity(self.book)
     index_entity(self.ent)
     index_entity(self.ent2)
Ejemplo n.º 9
0
    def setUp(self):
        super(XrefApiTestCase, self).setUp()
        self.creator = self.create_user(foreign_id='creator')
        self.outsider = self.create_user(foreign_id='outsider')

        # First public collection and entities
        self.residents = self.create_collection(
            label='Residents of Habitat Ring',
            foreign_id='test_residents',
            creator=self.creator)
        self.grant_publish(self.residents)

        self.ent = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Elim Garak',
                }
            }, self.residents)

        self.ent2 = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Leeta',
                }
            }, self.residents)

        # Second public collection and entities
        self.dabo = self.create_collection(label='Dabo Girls',
                                           foreign_id='test_dabo',
                                           creator=self.creator)
        self.grant_publish(self.dabo)

        self.ent3 = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'MPella',
                }
            }, self.dabo)

        self.ent4 = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Leeta',
                }
            }, self.dabo)

        self.ent5 = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Mardah',
                }
            }, self.dabo)

        # Private collection and entities
        self.obsidian = self.create_collection(label='Obsidian Order',
                                               foreign_id='test_obsidian',
                                               creator=self.creator)

        self.ent6 = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Elim Garak',
                }
            }, self.obsidian)

        self.ent7 = self.create_entity(
            {
                'schema': 'Person',
                'properties': {
                    'name': 'Enabran Tain',
                }
            }, self.obsidian)

        db.session.commit()
        index_entity(self.ent)
        index_entity(self.ent2)
        index_entity(self.ent3)
        index_entity(self.ent4)
        index_entity(self.ent5)
        index_entity(self.ent6)
        index_entity(self.ent7)
        self.stage = get_stage(self.residents, OP_XREF)
Ejemplo n.º 10
0
def update_entity(entity, sync=False):
    data = index.index_entity(entity, sync=sync)
    refresh_collection(entity.collection, sync=sync)
    return data
Ejemplo n.º 11
0
def create_entity(data, collection, role=None, sync=False):
    entity = Entity.create(data, collection)
    db.session.commit()
    data = index.index_entity(entity, sync=sync)
    refresh_entity(entity)
    return data
Ejemplo n.º 12
0
def create_entity(data, collection, role=None, sync=False):
    entity = Entity.create(data, collection)
    db.session.commit()
    data = index.index_entity(entity, sync=sync)
    refresh_entity(entity)
    return data
Ejemplo n.º 13
0
    def setUp(self):
        super(ProfilesApiTestCase, self).setUp()
        self.rolex = self.create_user(foreign_id="rolex")
        self.col1 = self.create_collection()
        self.grant(self.col1, self.rolex, True, True)
        authz = Authz.from_role(self.rolex)
        self.profile = EntitySet.create(
            {
                "label": "x",
                "type": EntitySet.PROFILE
            }, self.col1, authz)
        ent1 = {
            "schema": "LegalEntity",
            "properties": {
                "name": "Donald Trump",
                "address": "721 Fifth Avenue, New York, NY",
                "phone": "+12024561414",
            },
        }
        self.ent1 = self.create_entity(ent1, self.col1)
        index_entity(self.ent1)
        EntitySetItem.save(self.profile,
                           self.ent1.id,
                           collection_id=self.col1.id)

        self.col2 = self.create_collection()
        self.grant_publish(self.col2)
        ent2 = {
            "schema": "Person",
            "properties": {
                "name": "Donald J. Trump",
                "position": "45th President of the US",
                "phone": "+12024561414",
            },
        }
        self.ent2 = self.create_entity(ent2, self.col2)
        index_entity(self.ent2)
        EntitySetItem.save(self.profile,
                           self.ent2.id,
                           collection_id=self.col2.id)

        ent_false = {
            "schema": "LegalEntity",
            "properties": {
                "name": "Donald Trump, Jr",
                "email": "*****@*****.**"
            },
        }
        self.ent_false = self.create_entity(ent_false, self.col2)
        index_entity(self.ent_false)
        EntitySetItem.save(
            self.profile,
            self.ent_false.id,
            collection_id=self.col2.id,
            judgement=Judgement.NEGATIVE,
        )

        self.col3 = self.create_collection()
        ent3 = {
            "schema": "LegalEntity",
            "properties": {
                "name": "Donald John Trump",
                "birthDate": "1964"
            },
        }
        self.ent3 = self.create_entity(ent3, self.col3)
        index_entity(self.ent3)
        EntitySetItem.save(self.profile,
                           self.ent3.id,
                           collection_id=self.col3.id)
        db.session.commit()
Ejemplo n.º 14
0
def update_entity(entity, sync=False):
    # TODO: delete from index upon type change.
    data = index.index_entity(entity, sync=sync)
    refresh_entity(entity)
    return data
Ejemplo n.º 15
0
def update_entity(entity, sync=False):
    data = index.index_entity(entity, sync=sync)
    refresh_entity(entity)
    return data
Ejemplo n.º 16
0
def index_entities():
    q = db.session.query(Entity)
    for entity in q:
        index.index_entity(entity, sync=False)
Ejemplo n.º 17
0
def update_entity(entity, sync=False):
    index.index_entity(entity, sync=sync)
    refresh_entity(entity)
Ejemplo n.º 18
0
def update_entity(entity, sync=False):
    # TODO: delete from index upon type change.
    data = index.index_entity(entity, sync=sync)
    refresh_entity(entity)
    return data
Ejemplo n.º 19
0
def update_entity(entity, sync=False):
    index.index_entity(entity, sync=sync)
    refresh_entity(entity.signed_id, sync=sync)
    refresh_collection(entity.collection_id, sync=sync)