Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Commit c6daea4

Browse files
committed
Allow to set json key by specifying a metadata name
1 parent 6fc067d commit c6daea4

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

eyes_common/applitools/common/utils/json_utils.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,21 @@ def attr_from_response(response, cls):
6363
return attr_from_json(response.text, cls)
6464

6565

66+
# Uses for replacing of regular attr.name to specified in metadata
67+
REPLACE_TO_DICT = dict()
68+
69+
6670
class _CamelCasedDict(dict):
6771
def __setitem__(self, key, value):
68-
key = underscore_to_camelcase(key)
72+
if key in REPLACE_TO_DICT:
73+
# use key specified in metadata
74+
old_key = key
75+
key = REPLACE_TO_DICT[old_key]
76+
del REPLACE_TO_DICT[old_key]
77+
else:
78+
# convert key into camel case format
79+
key = underscore_to_camelcase(key)
80+
# process Enum's
6981
if hasattr(value, "value"):
7082
value = value.value
7183
super(_CamelCasedDict, self).__setitem__(key, value)
@@ -78,7 +90,11 @@ def _filter(attr_, value):
7890
if value is None:
7991
return False
8092
return True
81-
if attr_.metadata.get(JsonInclude.THIS) or attr_.metadata.get(JsonInclude.NAME):
93+
if attr_.metadata.get(JsonInclude.THIS):
94+
return True
95+
if attr_.metadata.get(JsonInclude.NAME):
96+
# set key from metadata which would be used by default
97+
REPLACE_TO_DICT[attr_.name] = attr_.metadata[JsonInclude.NAME]
8298
return True
8399
return False
84100

tests/unit/eyes_selenium/test_eyes.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import json
2+
13
import pytest
24
from mock import patch
35

4-
from applitools.common import MatchLevel, StitchMode
6+
from applitools.common import MatchLevel, StitchMode, BatchInfo
7+
from applitools.common.utils import json_utils
58
from applitools.core import NullScaleProvider
69
from applitools.selenium import Eyes
710
from applitools.selenium.visual_grid import VisualGridRunner
811

912

10-
def get_start_session_info_from_open(eyes, driver):
13+
def open_and_get_start_session_info(eyes, driver):
1114
eyes.api_key = "Some API KEY"
1215
eyes._is_viewport_size_set = True
1316

@@ -83,7 +86,7 @@ def test_baseline_name(eyes, driver_mock):
8386
assert eyes.configuration.baseline_branch_name == "Baseline"
8487

8588
if not eyes._visual_grid_eyes:
86-
session_info = get_start_session_info_from_open(eyes, driver_mock)
89+
session_info = open_and_get_start_session_info(eyes, driver_mock)
8790
assert session_info.baseline_branch_name == "Baseline"
8891

8992

@@ -93,7 +96,7 @@ def test_branch_name(eyes, driver_mock):
9396
assert eyes.configuration.branch_name == "Branch"
9497

9598
if not eyes._visual_grid_eyes:
96-
session_info = get_start_session_info_from_open(eyes, driver_mock)
99+
session_info = open_and_get_start_session_info(eyes, driver_mock)
97100
assert session_info.branch_name == "Branch"
98101

99102

@@ -103,5 +106,16 @@ def test_baseline_env_name(eyes, driver_mock):
103106
assert eyes.configuration.baseline_env_name == "Baseline Env"
104107

105108
if not eyes._visual_grid_eyes:
106-
session_info = get_start_session_info_from_open(eyes, driver_mock)
109+
session_info = open_and_get_start_session_info(eyes, driver_mock)
107110
assert session_info.baseline_env_name == "Baseline Env"
111+
112+
113+
def test_batch_info_sequence_name(eyes, driver_mock):
114+
eyes.batch = BatchInfo("Batch Info")
115+
eyes.batch.sequence_name = "Sequence"
116+
117+
if not eyes._visual_grid_eyes:
118+
session_info = open_and_get_start_session_info(eyes, driver_mock)
119+
info_json = json_utils.to_json(session_info)
120+
batch_info = json.loads(info_json)["startInfo"]["batchInfo"]
121+
assert batch_info["batchSequenceName"] == "Sequence"

0 commit comments

Comments
 (0)