1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2019-2022 AT&T Intellectual Property. All rights reserved.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
17 from distributor import registry_client as rc
20 def test_add_url_from_link():
21 test = {"link": {"href": "bar"}, "name": "jane", "age": 33, "innerTest": {"link": {"href": "baz"}, "name": "bob"}}
22 result = rc._add_url_from_link("http://foo", test)
24 assert result["selfUrl"] == "http://foo/bar"
25 assert result["innerTest"]["selfUrl"] == "http://foo/baz"
28 def test_get_buckets(monkeypatch):
29 def fake_get_json(url):
30 if url == "http://registry/buckets":
34 monkeypatch.setattr(distributor.registry_client, "_get_json", fake_get_json)
36 assert [] == rc.get_buckets("http://registry")
37 assert [] == rc.get_buckets("http://registry/")
40 def test_find_flow(monkeypatch):
41 def fake_get_buckets(url):
42 return [{"selfUrl": "{0}/buckets/123".format(url)}]
44 monkeypatch.setattr(distributor.registry_client, "get_buckets", fake_get_buckets)
46 def fake_get_flows(registry_url, url):
47 if url == "http://registry/buckets/123":
48 return [{"identifier": "abc"}]
51 monkeypatch.setattr(distributor.registry_client, "get_flows", fake_get_flows)
53 assert rc.find_flow("http://registry", "abc")["identifier"] == "abc"
56 def test_flow_versions(monkeypatch):
57 def fake_get_json_many(url):
58 if url == "http://registry/buckets/123/flows/abc/versions":
59 return [{"version": 1}, {"version": 3}, {"version": 2}]
63 monkeypatch.setattr(distributor.registry_client, "_get_json", fake_get_json_many)
65 assert [3, 2, 1] == rc.get_flow_versions("http://registry/buckets/123/flows/abc/")
68 def test_get_flow_diff_latest(monkeypatch):
69 def fake_get_flow_versions(url):
72 monkeypatch.setattr(distributor.registry_client, "get_flow_versions", fake_get_flow_versions)
74 assert None == rc.get_flow_diff_latest("http://registry", "http://registry/buckets/123/flows/abc/")