2017-07-27 16:30:26 +01:00
|
|
|
import pytest
|
2017-05-04 09:30:55 +01:00
|
|
|
|
2021-06-14 12:40:12 +01:00
|
|
|
from app.utils import get_logo_cdn_domain, merge_jsonlike
|
2017-04-20 14:55:14 +01:00
|
|
|
|
|
|
|
|
|
2017-07-24 15:20:40 +01:00
|
|
|
def test_get_cdn_domain_on_localhost(client, mocker):
|
|
|
|
|
mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'http://localhost:6012'})
|
2018-11-29 11:41:13 +00:00
|
|
|
domain = get_logo_cdn_domain()
|
2017-07-24 15:20:40 +01:00
|
|
|
assert domain == 'static-logos.notify.tools'
|
|
|
|
|
|
|
|
|
|
|
2017-07-28 15:19:20 +01:00
|
|
|
def test_get_cdn_domain_on_non_localhost(client, mocker):
|
2017-07-24 15:20:40 +01:00
|
|
|
mocker.patch.dict('app.current_app.config', values={'ADMIN_BASE_URL': 'https://some.admintest.com'})
|
2018-11-29 11:41:13 +00:00
|
|
|
domain = get_logo_cdn_domain()
|
2017-07-24 15:20:40 +01:00
|
|
|
assert domain == 'static-logos.admintest.com'
|
2018-02-06 10:55:29 +00:00
|
|
|
|
|
|
|
|
|
2020-08-13 12:38:12 +01:00
|
|
|
@pytest.mark.parametrize("source_object, destination_object, expected_result", [
|
|
|
|
|
# simple dicts:
|
|
|
|
|
({"a": "b"}, {"c": "d"}, {"a": "b", "c": "d"}),
|
|
|
|
|
# dicts with nested dict, both under same key, additive behaviour:
|
|
|
|
|
({"a": {"b": "c"}}, {"a": {"e": "f"}}, {"a": {"b": "c", "e": "f"}}),
|
2021-01-21 16:49:12 +00:00
|
|
|
# same key in both dicts, value is a string, destination supercedes source:
|
2020-08-13 12:38:12 +01:00
|
|
|
({"a": "b"}, {"a": "c"}, {"a": "c"}),
|
2021-01-22 15:40:28 +00:00
|
|
|
# nested dict added to new key of dict, additive behaviour:
|
|
|
|
|
({"a": "b"}, {"c": {"d": "e"}}, {"a": "b", "c": {"d": "e"}}),
|
2021-01-21 16:49:12 +00:00
|
|
|
# lists with same length but different items, destination supercedes source:
|
|
|
|
|
(["b", "c", "d"], ["b", "e", "f"], ["b", "e", "f"]),
|
2020-08-13 12:38:12 +01:00
|
|
|
# lists in dicts behave as top level lists
|
2021-01-21 16:49:12 +00:00
|
|
|
({"a": ["b", "c", "d"]}, {"a": ["b", "e", "f"]}, {"a": ["b", "e", "f"]}),
|
|
|
|
|
# lists with same string in both, at different positions, result in duplicates keeping their positions
|
|
|
|
|
(["a", "b", "c", "d"], ["d", "e", "f"], ["d", "e", "f", "d"]),
|
2020-08-13 12:38:12 +01:00
|
|
|
# lists with same dict in both result in a list with one instance of that dict
|
|
|
|
|
([{"b": "c"}], [{"b": "c"}], [{"b": "c"}]),
|
|
|
|
|
# if dicts in lists have different values, they are not merged
|
2021-01-21 16:49:12 +00:00
|
|
|
([{"b": "c"}], [{"b": "e"}], [{"b": "e"}]),
|
2021-01-22 15:40:28 +00:00
|
|
|
# if nested dicts in lists have different keys, additive behaviour
|
|
|
|
|
([{"b": "c"}], [{"d": {"e": "f"}}], [{"b": "c", "d": {"e": "f"}}]),
|
2021-01-26 12:16:08 +00:00
|
|
|
# if dicts in destination list but not source, they just get added to end of source
|
|
|
|
|
([{"a": "b"}], [{"a": "b"}, {"a": "b"}, {"c": "d"}], [{"a": "b"}, {"a": "b"}, {"c": "d"}]),
|
2020-08-13 12:38:12 +01:00
|
|
|
# merge a dict with a null object returns that dict (does not work the other way round)
|
2021-01-22 15:40:28 +00:00
|
|
|
({"a": {"b": "c"}}, None, {"a": {"b": "c"}}),
|
|
|
|
|
# double nested dicts, new adds new Boolean key: value, additive behaviour
|
|
|
|
|
({"a": {"b": {"c": "d"}}}, {"a": {"b": {"e": True}}}, {"a": {"b": {"c": "d", "e": True}}}),
|
|
|
|
|
# double nested dicts, both have same key, different values, destination supercedes source
|
|
|
|
|
({"a": {"b": {"c": "d"}}}, {"a": {"b": {"c": "e"}}}, {"a": {"b": {"c": "e"}}})
|
2020-08-13 12:38:12 +01:00
|
|
|
])
|
|
|
|
|
def test_merge_jsonlike_merges_jsonlike_objects_correctly(source_object, destination_object, expected_result):
|
|
|
|
|
merge_jsonlike(source_object, destination_object)
|
|
|
|
|
assert source_object == expected_result
|