Skip to content

Commit

Permalink
adding support for label
Browse files Browse the repository at this point in the history
  • Loading branch information
prklm10 committed Oct 25, 2024
1 parent 90cae0b commit 1d2cdf9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions percy/lib/app_percy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def screenshot(self, name: str, **kwargs):
test_case = kwargs.get('test_case')
if test_case and not isinstance(test_case, str):
raise TypeError('Argument test_case should be a string')
labels = kwargs.get('labels')
if labels and not isinstance(labels, str):
raise TypeError('Argument labels should be a string')
th_test_case_execution_id = kwargs.get('th_test_case_execution_id')
if th_test_case_execution_id and not isinstance(th_test_case_execution_id, str):
raise TypeError('Argument th_test_case_execution_id should be a string')
Expand Down
7 changes: 4 additions & 3 deletions percy/lib/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def is_percy_enabled():
return False

def post_screenshots(self, name, tag, tiles, external_debug_url=None,
ignored_elements_data=None, considered_elements_data=None, sync=None, test_case=None, th_test_case_execution_id=None
ignored_elements_data=None, considered_elements_data=None, sync=None, test_case=None, labels=None, th_test_case_execution_id=None
):
body = self._request_body(name, tag, tiles, external_debug_url,
ignored_elements_data, considered_elements_data, sync, test_case, th_test_case_execution_id
ignored_elements_data, considered_elements_data, sync, test_case, labels, th_test_case_execution_id
)

body['client_info'] = Environment._get_client_info()
Expand Down Expand Up @@ -105,7 +105,7 @@ def post_poa_screenshots(self, name, session_id, command_executor_url, capabilit

@staticmethod
def _request_body(name, tag, tiles, external_debug_url, ignored_elements_data,
considered_elements_data, sync, test_case, th_test_case_execution_id
considered_elements_data, sync, test_case, labels, th_test_case_execution_id
):
tiles = list(map(dict, tiles))
return {
Expand All @@ -117,5 +117,6 @@ def _request_body(name, tag, tiles, external_debug_url, ignored_elements_data,
"considered_elements_data": considered_elements_data,
"sync": sync,
"test_case": test_case,
"labels": labels,
"th_test_case_execution_id": th_test_case_execution_id
}
7 changes: 4 additions & 3 deletions percy/providers/generic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def screenshot(self, name, **kwargs):
}
sync = kwargs.get("sync", None)
test_case = kwargs.get("test_case", None)
labels = kwargs.get("labels", None)
th_test_case_execution_id = kwargs.get("th_test_case_execution_id", None)
return self._post_screenshots(name, tag, tiles, self.get_debug_url(), ignore_regions,
consider_regions, sync, test_case, th_test_case_execution_id
consider_regions, sync, test_case, labels, th_test_case_execution_id
)

def _get_tag(self, **kwargs):
Expand Down Expand Up @@ -160,9 +161,9 @@ def get_regions_by_location(self, elements_array, custom_locations):
log(f"Values passed in custom ignored region at index: {idx} is not valid")

@staticmethod
def _post_screenshots(name, tag, tiles, debug_url, ignored_regions, considered_regions, sync, test_case, th_test_case_execution_id):
def _post_screenshots(name, tag, tiles, debug_url, ignored_regions, considered_regions, sync, test_case, labels, th_test_case_execution_id):
response = CLIWrapper().post_screenshots(name, tag, tiles, debug_url, ignored_regions,
considered_regions, sync, test_case, th_test_case_execution_id)
considered_regions, sync, test_case, labels, th_test_case_execution_id)
return response

def _write_screenshot(self, png_bytes, directory):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ def test_request_body(self):
name = "some-name"
debug_url = "debug-url"
test_case = 'test-case-1'
labels = 'app;testing'
th_test_case_execution_id = 'uuid-1231'
response = self.cli_wrapper._request_body(
name, tag, [tile], debug_url, self.ignored_elements_data, self.considered_elements_data, False,
test_case, th_test_case_execution_id
test_case, labels, th_test_case_execution_id
)
self.assertEqual(response["name"], name)
self.assertEqual(response["external_debug_url"], debug_url)
Expand All @@ -123,6 +124,7 @@ def test_request_body(self):
)
self.assertEqual(response["sync"], False)
self.assertEqual(response["test_case"], test_case)
self.assertEqual(response["labels"], labels)
self.assertEqual(response["th_test_case_execution_id"], th_test_case_execution_id)

def test_request_body_when_optional_values_are_null(self):
Expand All @@ -133,10 +135,11 @@ def test_request_body_when_optional_values_are_null(self):
ignored_elements_data = None
considered_elements_data = None
test_case = None
labels = None
th_test_case_execution_id = None
response = self.cli_wrapper._request_body(
name, tag, [tile], debug_url, ignored_elements_data, considered_elements_data, True,
test_case, th_test_case_execution_id
test_case, labels, th_test_case_execution_id
)
self.assertEqual(response["name"], name)
self.assertEqual(response["external_debug_url"], debug_url)
Expand All @@ -145,4 +148,5 @@ def test_request_body_when_optional_values_are_null(self):
self.assertEqual(response["ignored_elements_data"], None)
self.assertEqual(response["sync"], True)
self.assertEqual(response["test_case"], test_case)
self.assertEqual(response["labels"], labels)
self.assertEqual(response["th_test_case_execution_id"], th_test_case_execution_id)
2 changes: 1 addition & 1 deletion tests/test_generic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_post_screenshots(self):
tag = self.generic_provider._get_tag()
tiles = self.generic_provider._get_tiles()
response = self.generic_provider._post_screenshots(
"screenshot 1", tag, tiles, "", [], [], False, None, None
"screenshot 1", tag, tiles, "", [], [], False, None, None, None
)
self.assertEqual(response, self.comparison_response)

Expand Down

0 comments on commit 1d2cdf9

Please sign in to comment.