1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2019 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,
22 "innerTest": {"link": {"href": "baz"}, "name": "bob"}
24 result = rc._add_url_from_link("http://foo", test)
26 assert result["selfUrl"] == "http://foo/bar"
27 assert result["innerTest"]["selfUrl"] == "http://foo/baz"
30 def test_get_buckets(monkeypatch):
31 def fake_get_json(url):
32 if url == "http://registry/buckets":
36 monkeypatch.setattr(distributor.registry_client, "_get_json", fake_get_json)
38 assert [] == rc.get_buckets("http://registry")
39 assert [] == rc.get_buckets("http://registry/")
42 def test_find_flow(monkeypatch):
43 def fake_get_buckets(url):
44 return [{"selfUrl": "{0}/buckets/123".format(url)}]
46 monkeypatch.setattr(distributor.registry_client, "get_buckets", fake_get_buckets)
48 def fake_get_flows(registry_url, url):
49 if url == "http://registry/buckets/123":
50 return [{"identifier": "abc"}]
53 monkeypatch.setattr(distributor.registry_client, "get_flows", fake_get_flows)
55 assert rc.find_flow("http://registry", "abc")["identifier"] == "abc"
58 def test_flow_versions(monkeypatch):
59 def fake_get_json_many(url):
60 if url == "http://registry/buckets/123/flows/abc/versions":
61 return [{"version": 1}, {"version": 3}, {"version": 2}]
65 monkeypatch.setattr(distributor.registry_client, "_get_json",
68 assert [3, 2, 1] == rc.get_flow_versions("http://registry/buckets/123/flows/abc/")
71 def test_get_flow_diff_latest(monkeypatch):
72 def fake_get_flow_versions(url):
75 monkeypatch.setattr(distributor.registry_client, "get_flow_versions",
76 fake_get_flow_versions)
78 assert None == rc.get_flow_diff_latest("http://registry", "http://registry/buckets/123/flows/abc/")