From 1d2cdf95b1e8243d2a49ae5ebed8287cd7fd1ce5 Mon Sep 17 00:00:00 2001 From: prklm10 Date: Fri, 25 Oct 2024 14:18:52 +0530 Subject: [PATCH] adding support for label --- percy/lib/app_percy.py | 3 +++ percy/lib/cli_wrapper.py | 7 ++++--- percy/providers/generic_provider.py | 7 ++++--- tests/test_cli_wrapper.py | 8 ++++++-- tests/test_generic_provider.py | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/percy/lib/app_percy.py b/percy/lib/app_percy.py index 7bfbe5a..ab705f5 100644 --- a/percy/lib/app_percy.py +++ b/percy/lib/app_percy.py @@ -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') diff --git a/percy/lib/cli_wrapper.py b/percy/lib/cli_wrapper.py index a580066..be024c6 100644 --- a/percy/lib/cli_wrapper.py +++ b/percy/lib/cli_wrapper.py @@ -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() @@ -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 { @@ -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 } diff --git a/percy/providers/generic_provider.py b/percy/providers/generic_provider.py index d1997c1..a2c85d2 100644 --- a/percy/providers/generic_provider.py +++ b/percy/providers/generic_provider.py @@ -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): @@ -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): diff --git a/tests/test_cli_wrapper.py b/tests/test_cli_wrapper.py index 39167a4..2e772c1 100644 --- a/tests/test_cli_wrapper.py +++ b/tests/test_cli_wrapper.py @@ -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) @@ -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): @@ -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) @@ -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) diff --git a/tests/test_generic_provider.py b/tests/test_generic_provider.py index b6ebe67..8a5b818 100644 --- a/tests/test_generic_provider.py +++ b/tests/test_generic_provider.py @@ -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)