-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add upsert for entities and relationships (#55)
* Upsert method for entities. * Upsert method for relationships. * Upsert flag when using the CSV uploader for entities and relationships.
- Loading branch information
Showing
17 changed files
with
286 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.1.0 | ||
2.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
|
||
from exabel_data_sdk.client.api.data_classes.entity import Entity | ||
from exabel_data_sdk.client.api.entity_api import EntityApi | ||
from exabel_data_sdk.tests.client.api.mock_entity_api import MockEntityApi | ||
|
||
|
||
class TestEntityApi(unittest.TestCase): | ||
def test_upsert(self): | ||
for assume_exists in (True, False): | ||
entity_api: EntityApi = MockEntityApi() | ||
expected = Entity( | ||
name="entityTypes/company/entities/Amazon", | ||
display_name="Amazon", | ||
) | ||
created_entity = entity_api.upsert_entity(expected, assume_exists) | ||
self.assertEqual(expected, created_entity) | ||
updated_entity = entity_api.upsert_entity(expected, assume_exists) | ||
self.assertEqual(expected, updated_entity) | ||
|
||
def test_upsert_replaces_resource(self): | ||
for assume_exists in (True, False): | ||
entity_api: EntityApi = MockEntityApi() | ||
old_entity = Entity( | ||
name="entityTypes/company/entities/Amazon", | ||
display_name="Amazon's old display name", | ||
description="Amazon's old description", | ||
properties={"old_property": "old_value"}, | ||
) | ||
expected = Entity( | ||
name="entityTypes/company/entities/Amazon", | ||
display_name="Amazon", | ||
description="Amazon's new description", | ||
) | ||
entity_api.create_entity(old_entity, old_entity.get_entity_type()) | ||
entity_api.upsert_entity(expected, assume_exists) | ||
actual_entity = entity_api.get_entity(expected.name) | ||
self.assertEqual(expected, actual_entity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import unittest | ||
|
||
from exabel_data_sdk.client.api.data_classes.relationship import Relationship | ||
from exabel_data_sdk.client.api.relationship_api import RelationshipApi | ||
from exabel_data_sdk.tests.client.api.mock_relationship_api import MockRelationshipApi | ||
|
||
AMAZON = "entityTypes/company/entities/Amazon" | ||
USA = "entityTypes/country/entities/USA" | ||
RELATIONHIP_TYPE = "relationshipTypes/LOCATED_IN" | ||
|
||
|
||
class TestRelationshipApi(unittest.TestCase): | ||
def test_upsert(self): | ||
for assume_exists in (True, False): | ||
relationship_api: RelationshipApi = MockRelationshipApi() | ||
expected = Relationship( | ||
relationship_type=RELATIONHIP_TYPE, | ||
from_entity=AMAZON, | ||
to_entity=USA, | ||
) | ||
created_relationship = relationship_api.upsert_relationship(expected, assume_exists) | ||
self.assertEqual(expected, created_relationship) | ||
updated_relationship = relationship_api.upsert_relationship(expected, assume_exists) | ||
self.assertEqual(expected, updated_relationship) | ||
|
||
def test_upsert_replaces_resource(self): | ||
for assume_exists in (True, False): | ||
relationship_api: RelationshipApi = MockRelationshipApi() | ||
old_relationship = Relationship( | ||
relationship_type=RELATIONHIP_TYPE, | ||
from_entity=AMAZON, | ||
to_entity=USA, | ||
description="Old relationship description", | ||
properties={"old_property": "old_value"}, | ||
) | ||
expected = Relationship( | ||
relationship_type=RELATIONHIP_TYPE, | ||
from_entity=AMAZON, | ||
to_entity=USA, | ||
description="New relationship description", | ||
) | ||
relationship_api.create_relationship(old_relationship) | ||
relationship_api.upsert_relationship(expected, assume_exists) | ||
actual_relationship = relationship_api.get_relationship( | ||
expected.relationship_type, expected.from_entity, expected.to_entity | ||
) | ||
self.assertEqual(expected, actual_relationship) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
brand,description | ||
Spring & Vine,Shampoo bars | ||
The Coconut Tree,Sri Lankan street food | ||
Spring & Vine,This entry will be ignored because it's a duplicate | ||
Spring & Vine,This entry might be ignored because it's a duplicate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
entity_from,brand,description | ||
entityTypes/company/company_x,Spring & Vine,Owned since 2019 | ||
entityTypes/company/company_x,Spring & Vine,This entry will be ignored because it's a duplicate | ||
entityTypes/company/company_x,Spring & Vine,This entry might be ignored because it's a duplicate | ||
entityTypes/company/company_y,The Coconut Tree,Acquired for $200M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.