Skip to content

Instantly share code, notes, and snippets.

@Bachmann1234
Last active October 22, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bachmann1234/9f2a1aec12a7d58de2e7 to your computer and use it in GitHub Desktop.
Save Bachmann1234/9f2a1aec12a7d58de2e7 to your computer and use it in GitHub Desktop.
Example client call
def test_end_to_end(ccs_host):
content = "I am the batman and I fight the joker"
content_id = "contentOne"
sub_content_id = "subcontent"
near_matcher_id = "nearMatcher"
batman_id = "batmanId"
joker_id = "jokerId"
batman_name = "batmanMatcher"
joker_name = "jokerMatcher"
field = "document"
sub_field = "footer"
sub_content = "Whatever"
batman_expression = "batman"
joker_expression = "joker"
request_context = {"client_version": "2.0.0"}
request = RequestBody(
matchers=[
ANearB(
id=near_matcher_id,
value=100,
a=Regex(
id=batman_id,
name=batman_name,
description="find the batman",
score=100,
mask=False,
expression=batman_expression
),
b=Regex(
id=joker_id,
name=joker_name,
description="Joker is scary! FIND HIM",
score=50,
mask=False,
expression=joker_expression
)
)
],
contents=[ContentInline(
id=content_id,
field=field,
data=content.encode(BASE64),
mime=MIME_TEXT,
sub_contents=[ContentInline(
id=sub_content_id,
field=sub_field,
data=sub_content.encode(BASE64)
)]
)],
request_context=request_context,
ResultConfig(
detail_level=ccs_client.constants.SIMPLE,
max_snippet_length=100,
mask=ccs_client.constants.ALL
)
)
expected_response = AnalysisResponse(
request_context=request_context,
results=[AnalyzedContent(
id=content_id,
field=field,
processed_as=TEXT,
content=content,
match_results=[
Match(
matcher_type=A_NEAR_B_MATCHER,
matcher_id=near_matcher_id,
global_location=Location(
start="9",
end="37"
),
match_detail=MatchDetail(
level="1",
excerpt=content,
masked=False,
match_location=Location(
start="9",
end="37"
)
),
sub_matches=[
Match(
matcher_type=REGEX_MATCHER,
matcher_id=batman_id,
matcher_name=batman_name,
global_location=Location(
start="9",
end="15"
),
match_detail=MatchDetail(
level="2",
excerpt=content,
masked=False,
match_location=Location(
start="9",
end="15"
)
),
sub_matches=[]
),
Match(
matcher_type=REGEX_MATCHER,
matcher_id=joker_id,
matcher_name=joker_name,
global_location=Location(
start="32",
end="37"
),
match_detail=MatchDetail(
level="2",
excerpt=content,
masked=False,
match_location=Location(
start="32",
end="37"
)
),
sub_matches=[]
)
]
),
],
sub_content=[
AnalyzedContent(
id=sub_content_id,
field=sub_field,
processed_as=TEXT,
content=sub_content,
match_results=[],
sub_content=[]
)
]
)]
)
response = make_request(request, ccs_host)
assert response == expected_response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment