コード例 #1
0
def test_make_linked_property(dataset):
    # make a new model
    model = dataset.create_model("my_model_{}".format(make_id()),
                                 schema=[ModelProperty("name", title=True)])

    # create a linked property linking to that model,
    # and make sure the link initialized correctly
    link1 = LinkedModelProperty("link1", model, "1st linked property")

    dct1 = link1.as_dict()
    assert dct1["name"] == "link1"
    assert dct1["displayName"] == "1st linked property"
    assert dct1["to"] == model.id

    # make a linked property from a dict,
    # and make sure it initialized correctly
    link2 = LinkedModelProperty.from_dict({
        "link": {
            "name": "link2",
            "displayName": "2nd linked property",
            "to": model.id,
            "id": "XXX-XXX-XXX",
            "position": 0,
        }
    })
    assert link2.id == "XXX-XXX-XXX"
    assert link2.position == 0

    dct2 = link2.as_dict()
    assert dct2["name"] == "link2"
    assert dct2["displayName"] == "2nd linked property"
    assert dct2["to"] == model.id
コード例 #2
0
def test_make_linked_property(dataset):
    # make a new model
    model = dataset.create_model('my_model_{}'.format(uuid4()),
                                 schema=[ModelProperty('name', title=True)])

    # create a linked property linking to that model,
    # and make sure the link initialized correctly
    link1 = LinkedModelProperty('link1', model, '1st linked property')

    dct1 = link1.as_dict()
    assert dct1['name'] == 'link1'
    assert dct1['displayName'] == '1st linked property'
    assert dct1['to'] == model.id

    # make a linked property from a dict,
    # and make sure it initialized correctly
    link2 = LinkedModelProperty.from_dict({
        'link': {
            'name': 'link2',
            'displayName': '2nd linked property',
            'to': model.id,
            'id': 'XXX-XXX-XXX',
            'position': 0
        }
    })
    assert link2.id == 'XXX-XXX-XXX'
    assert link2.position == 0

    dct2 = link2.as_dict()
    assert dct2['name'] == 'link2'
    assert dct2['displayName'] == '2nd linked property'
    assert dct2['to'] == model.id
コード例 #3
0
ファイル: concepts.py プロジェクト: tgbugs/blackfynn-python
 def get_topology(self, dataset):
     dataset_id = self._get_id(dataset)
     resp = self._get(
         self._uri('/{dataset_id}/concepts/schema/graph',
                   dataset_id=dataset_id))
     # What is returned is a list mixing
     results = {
         'models': [],
         'relationships': [],
         'linked_properties': []
     }
     for r in resp:
         r['dataset_id'] = r.get('dataset_id', dataset_id)
         if r.get('type')  == 'schemaRelationship':
             # This is a relationship
             results['relationships'].append(
                 Relationship.from_dict(r, api=self.session))
         elif r.get('type')  == 'schemaLinkedProperty':
             # This is a linked property type
             results['linked_properties'].append(
                 LinkedModelProperty.from_dict(r))
         else:
             # This is a model
             r['schema'] = self.get_properties(dataset, r['id'])
             r['linked'] = self.get_linked_properties(dataset, r['id'])
             results['models'].append(Model.from_dict(r, api=self.session))
     return results
コード例 #4
0
ファイル: concepts.py プロジェクト: tgbugs/blackfynn-python
 def create_linked_properties(self, dataset, concept, props):
     dataset_id = self._get_id(dataset)
     concept_id = self._get_id(concept)
     for p in props:
         assert p.name not in self.get_linked_properties(dataset, concept), "Linked property '{}' already exists".format(p.name)
     resp = self._post(self._uri('/{dataset_id}/concepts/{id}/linked/bulk', dataset_id=dataset_id, id=concept_id), json=[p.as_dict() for p in props])
     return [LinkedModelProperty.from_dict(r) for r in resp]
コード例 #5
0
def test_add_linked_property_bulk(dataset):
    # Link one model to three others
    source = dataset.create_model("source_model_{}".format(make_id()),
                                  schema=[ModelProperty("name", title=True)])
    target = dataset.create_model("target_model_{}".format(make_id()),
                                  schema=[ModelProperty("name", title=True)])
    link1 = LinkedModelProperty("link1", target, "bulk-added")
    link2 = LinkedModelProperty("link2", target, "bulk-added")
    link3 = LinkedModelProperty("link3", target, "bulk-added")
    source.add_linked_properties([link1, link2, link3])

    # Make sure newly created links are accessible through the API
    bulk = [
        x for x in dataset.get_topology()["linked_properties"]
        if x.display_name == "bulk-added"
    ]
    assert len(bulk) == 3
    assert len(source.linked) == 3
コード例 #6
0
def test_add_linked_property_bulk(dataset):
    # Link one model to three others
    source = dataset.create_model('source_model_{}'.format(uuid4()),
                                  schema=[ModelProperty('name', title=True)])
    target = dataset.create_model('target_model_{}'.format(uuid4()),
                                  schema=[ModelProperty('name', title=True)])
    link1 = LinkedModelProperty('link1', target, 'bulk-added')
    link2 = LinkedModelProperty('link2', target, 'bulk-added')
    link3 = LinkedModelProperty('link3', target, 'bulk-added')
    source.add_linked_properties([link1, link2, link3])

    # Make sure newly created links are accessible through the API
    bulk = [
        x for x in dataset.get_topology()['linked_properties']
        if x.display_name == 'bulk-added'
    ]
    assert len(bulk) == 3
    assert len(source.linked) == 3
コード例 #7
0
 def get_linked_properties(self, dataset, concept):
     dataset_id = self._get_id(dataset)
     concept_id = self._get_id(concept)
     resp = self._get(
         self._uri(
             "/{dataset_id}/concepts/{id}/linked",
             dataset_id=dataset_id,
             id=concept_id,
         ))
     return {
         r["link"]["name"]: LinkedModelProperty.from_dict(r)
         for r in resp
     }
コード例 #8
0
 def update_linked_property(self, dataset, concept, prop):
     dataset_id = self._get_id(dataset)
     concept_id = self._get_id(concept)
     prop_id = self._get_id(prop)
     resp = self._put(
         self._uri(
             "/{dataset_id}/concepts/{id}/linked/{prop_id}",
             dataset_id=dataset_id,
             id=concept_id,
             prop_id=prop_id,
         ),
         json=prop.as_dict(),
     )
     return LinkedModelProperty.from_dict(resp)
コード例 #9
0
 def create_linked_property(self, dataset, concept, prop):
     dataset_id = self._get_id(dataset)
     concept_id = self._get_id(concept)
     assert prop.name not in self.get_linked_properties(
         dataset,
         concept), "Linked property '{}' already exists".format(prop.name)
     resp = self._post(
         self._uri(
             "/{dataset_id}/concepts/{id}/linked",
             dataset_id=dataset_id,
             id=concept_id,
         ),
         json=prop.as_dict(),
     )
     return LinkedModelProperty.from_dict(resp)
コード例 #10
0
 def get_topology(self, dataset):
     dataset_id = self._get_id(dataset)
     resp = self._get(
         self._uri("/{dataset_id}/concepts/schema/graph",
                   dataset_id=dataset_id))
     # What is returned is a list mixing
     results = {"models": [], "relationships": [], "linked_properties": []}
     for r in resp:
         r["dataset_id"] = r.get("dataset_id", dataset_id)
         if r.get("type") == "schemaRelationship":
             # This is a relationship
             results["relationships"].append(
                 Relationship.from_dict(r, api=self.session))
         elif r.get("type") == "schemaLinkedProperty":
             # This is a linked property type
             results["linked_properties"].append(
                 LinkedModelProperty.from_dict(r))
         else:
             # This is a model
             r["schema"] = self.get_properties(dataset, r["id"])
             r["linked"] = self.get_linked_properties(dataset, r["id"])
             results["models"].append(Model.from_dict(r, api=self.session))
     return results
コード例 #11
0
ファイル: concepts.py プロジェクト: tgbugs/blackfynn-python
 def get_linked_properties(self, dataset, concept):
     dataset_id = self._get_id(dataset)
     concept_id = self._get_id(concept)
     resp = self._get(self._uri('/{dataset_id}/concepts/{id}/linked', dataset_id=dataset_id, id=concept_id))
     return {r['link']['name']: LinkedModelProperty.from_dict(r) for r in resp}