-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for fuzzy case-insensitive match in PropertyRef
Signed-off-by: Alex Chantavy <[email protected]>
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
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
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
44 changes: 44 additions & 0 deletions
44
tests/data/graph/querybuilder/sample_models/fake_emps_githubusers_fuzzy.py
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,44 @@ | ||
from dataclasses import dataclass | ||
|
||
from cartography.models.core.common import PropertyRef | ||
from cartography.models.core.nodes import CartographyNodeProperties | ||
from cartography.models.core.nodes import CartographyNodeSchema | ||
from cartography.models.core.relationships import CartographyRelProperties | ||
from cartography.models.core.relationships import CartographyRelSchema | ||
from cartography.models.core.relationships import LinkDirection | ||
from cartography.models.core.relationships import make_target_node_matcher | ||
from cartography.models.core.relationships import OtherRelationships | ||
from cartography.models.core.relationships import TargetNodeMatcher | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FakeEmp2ToGitHubUserRelProperties(CartographyRelProperties): | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FakeEmp2ToGitHubUser(CartographyRelSchema): | ||
target_node_label: str = 'GitHubUser' | ||
target_node_matcher: TargetNodeMatcher = make_target_node_matcher( | ||
{'username': PropertyRef('github_username', fuzzy_and_ignore_case=True)}, | ||
) | ||
direction: LinkDirection = LinkDirection.OUTWARD | ||
rel_label: str = "IDENTITY_GITHUB" | ||
properties: FakeEmp2ToGitHubUserRelProperties = FakeEmp2ToGitHubUserRelProperties() | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FakeEmp2NodeProperties(CartographyNodeProperties): | ||
id: PropertyRef = PropertyRef('id') | ||
lastupdated: PropertyRef = PropertyRef('lastupdated', set_in_kwargs=True) | ||
email: PropertyRef = PropertyRef('email') | ||
github_username: PropertyRef = PropertyRef('github_username') | ||
|
||
|
||
@dataclass(frozen=True) | ||
class FakeEmp2Schema(CartographyNodeSchema): | ||
label: str = 'FakeEmployee2' | ||
properties: FakeEmp2NodeProperties = FakeEmp2NodeProperties() | ||
other_relationships: OtherRelationships = OtherRelationships([ | ||
FakeEmp2ToGitHubUser(), | ||
]) |
27 changes: 27 additions & 0 deletions
27
tests/integration/cartography/graph/test_querybuilder_fuzzy_case_insensitive.py
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,27 @@ | ||
from cartography.client.core.tx import load | ||
from cartography.intel.github.users import load_organization_users | ||
from tests.data.graph.querybuilder.sample_data.case_insensitive_prop_ref import FAKE_EMPLOYEE_DATA | ||
from tests.data.graph.querybuilder.sample_data.case_insensitive_prop_ref import FAKE_GITHUB_ORG_DATA | ||
from tests.data.graph.querybuilder.sample_data.case_insensitive_prop_ref import FAKE_GITHUB_USER_DATA | ||
from tests.data.graph.querybuilder.sample_models.fake_emps_githubusers_fuzzy import FakeEmp2Schema | ||
from tests.integration.util import check_rels | ||
|
||
TEST_UPDATE_TAG = 123456789 | ||
|
||
|
||
def test_load_team_members_data_fuzzy(neo4j_session): | ||
# Arrange: Load some fake GitHubUser nodes to the graph | ||
load_organization_users( | ||
neo4j_session, | ||
FAKE_GITHUB_USER_DATA, | ||
FAKE_GITHUB_ORG_DATA, | ||
TEST_UPDATE_TAG, | ||
) | ||
|
||
# Act: Create team members | ||
load(neo4j_session, FakeEmp2Schema(), FAKE_EMPLOYEE_DATA, lastupdated=TEST_UPDATE_TAG) | ||
|
||
# Assert we can create relationships using a fuzzy, case insensitive match | ||
assert check_rels(neo4j_session, 'FakeEmployee2', 'email', 'GitHubUser', 'username', 'IDENTITY_GITHUB') == { | ||
('[email protected]', 'HjsimPson'), ('[email protected]', 'mbsimp-son'), | ||
} |
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