| |
@@ -0,0 +1,221 @@
|
| |
+ import pytest
|
| |
+ import requests_mock
|
| |
+
|
| |
+ from module_diff.pdc import PDC
|
| |
+
|
| |
+
|
| |
+ module1_url = ("https://pdc.fedoraproject.org/rest_api/v1"
|
| |
+ "/unreleasedvariants/"
|
| |
+ "?page_size=1&variant_uid=mariadb-10.2-20171019133930")
|
| |
+
|
| |
+ module2_url = ("https://pdc.fedoraproject.org/rest_api/v1"
|
| |
+ "/unreleasedvariants/"
|
| |
+ "?page_size=1&variant_uid=mariadb-10.2-20171103103655")
|
| |
+
|
| |
+ module_diff_ns_url = ("https://pdc.fedoraproject.org/rest_api/v1"
|
| |
+ "/unreleasedvariants/"
|
| |
+ "?page_size=1&variant_uid=platform-f27-20171011150016")
|
| |
+
|
| |
+
|
| |
+ @pytest.mark.usefixtures("pdc_json_res")
|
| |
+ class TestModule(object):
|
| |
+ """
|
| |
+ Test for the Module Class
|
| |
+ """
|
| |
+
|
| |
+ def test_get_diff_no_diff(self, pdc_json_res):
|
| |
+ """ Test if we dont have any diff between modules. """
|
| |
+
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+ module2_res = pdc_json_res.get()
|
| |
+ module2_res["results"][0]["koji_tag"] = "module-15d35d06c29b1848"
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ mock_http.register_uri("GET", module2_url, json=module2_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+ module2 = pdc.get_module("mariadb-10.2-20171103103655")
|
| |
+
|
| |
+ diff = module1.get_diff(module2, reused=True)
|
| |
+
|
| |
+ assert diff["added_rpms"] == []
|
| |
+ assert diff["removed_rpms"] == []
|
| |
+ assert diff["upgraded_rpms"] == []
|
| |
+ assert diff["downgraded_rpms"] == []
|
| |
+ assert len(diff["reused_rpms"]) == 7
|
| |
+
|
| |
+ def test_get_diff(self, pdc_json_res):
|
| |
+ """ Testing different kinds of changes in modules """
|
| |
+
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+ module2_res = pdc_json_res.get()
|
| |
+ module1_res["results"][0]["rpms"].remove(
|
| |
+ "mariadb-connect-engine-3:10.2.9-3.module_629c669e.x86_64.rpm")
|
| |
+ module2_res["results"][0]["koji_tag"] = "module-15d35d06c29b1848"
|
| |
+ module2_res["results"][0]["rpms"] = [
|
| |
+ "mariadb-debugsource-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-connect-engine-debuginfo-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-debuginfo-3:11.2.9-3.module_15d35d06.x86_64.rpm",
|
| |
+ "mariadb-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-devel-3:9.2.9-3.module_15d35d06.x86_64.rpm",
|
| |
+ "mariadb-connect-engine-3:10.2.9-3.module_15d35d06.x86_64.rpm"
|
| |
+ ]
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ mock_http.register_uri("GET", module2_url, json=module2_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+ module2 = pdc.get_module("mariadb-10.2-20171103103655")
|
| |
+
|
| |
+ diff = module1.get_diff(module2, reused=True)
|
| |
+
|
| |
+ assert diff["added_rpms"] == [
|
| |
+ "mariadb-connect-engine-3:10.2.9-3.module_15d35d06.x86_64.rpm"]
|
| |
+ assert diff["removed_rpms"] == ["mariadb-3:10.2.9-3.module_629c669e.src.rpm"]
|
| |
+ assert diff["upgraded_rpms"] == [
|
| |
+ ('mariadb-debuginfo-3:10.2.9-3.module_629c669e.x86_64.rpm',
|
| |
+ 'mariadb-debuginfo-3:11.2.9-3.module_15d35d06.x86_64.rpm')]
|
| |
+ assert diff["downgraded_rpms"] == [
|
| |
+ ('mariadb-devel-3:10.2.9-3.module_629c669e.x86_64.rpm',
|
| |
+ 'mariadb-devel-3:9.2.9-3.module_15d35d06.x86_64.rpm')]
|
| |
+ assert len(diff["reused_rpms"]) == 3
|
| |
+
|
| |
+ def test_get_diff_rpm_version_change(self, pdc_json_res):
|
| |
+ """ Testing if a version changes """
|
| |
+
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+ module2_res = pdc_json_res.get()
|
| |
+ module2_res["results"][0]["koji_tag"] = "module-15d35d06c29b1848"
|
| |
+ module2_res["results"][0]["rpms"] = [
|
| |
+ "mariadb-3:10.2.9-3.module_629c669e.src.rpm",
|
| |
+ "mariadb-debugsource-3:11.2.9-3.module_15d35d06.x86_64.rpm",
|
| |
+ "mariadb-connect-engine-debuginfo-3:10.2.8-3.module_15d35d06.x86_64.rpm",
|
| |
+ "mariadb-debuginfo-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-devel-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-connect-engine-3:10.2.9-3.module_629c669e.x86_64.rpm"
|
| |
+ ]
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ mock_http.register_uri("GET", module2_url, json=module2_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+ module2 = pdc.get_module("mariadb-10.2-20171103103655")
|
| |
+
|
| |
+ diff = module1.get_diff(module2, reused=True)
|
| |
+
|
| |
+ assert diff["added_rpms"] == []
|
| |
+ assert diff["removed_rpms"] == []
|
| |
+ assert diff["upgraded_rpms"] == [
|
| |
+ ('mariadb-debugsource-3:10.2.9-3.module_629c669e.x86_64.rpm',
|
| |
+ 'mariadb-debugsource-3:11.2.9-3.module_15d35d06.x86_64.rpm')]
|
| |
+ assert diff["downgraded_rpms"] == [
|
| |
+ ('mariadb-connect-engine-debuginfo-3:10.2.9-3.module_629c669e.x86_64.rpm',
|
| |
+ 'mariadb-connect-engine-debuginfo-3:10.2.8-3.module_15d35d06.x86_64.rpm')]
|
| |
+ assert len(diff["reused_rpms"]) == 5
|
| |
+
|
| |
+ def test_get_diff_rpm_removed(self, pdc_json_res):
|
| |
+ """ Testing if the module changes of an RPM """
|
| |
+
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+ module2_res = pdc_json_res.get()
|
| |
+ module2_res["results"][0]["koji_tag"] = "module-15d35d06c29b1848"
|
| |
+ module2_res["results"][0]["rpms"].remove("mariadb-3:10.2.9-3.module_629c669e.src.rpm")
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ mock_http.register_uri("GET", module2_url, json=module2_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+ module2 = pdc.get_module("mariadb-10.2-20171103103655")
|
| |
+
|
| |
+ diff = module1.get_diff(module2, reused=True)
|
| |
+
|
| |
+ assert diff["added_rpms"] == []
|
| |
+ assert diff["removed_rpms"] == ["mariadb-3:10.2.9-3.module_629c669e.src.rpm"]
|
| |
+ assert diff["upgraded_rpms"] == []
|
| |
+ assert diff["downgraded_rpms"] == []
|
| |
+ assert len(diff["reused_rpms"]) == 6
|
| |
+
|
| |
+ def test_get_diff_different_ns(self, pdc_json_res):
|
| |
+ """
|
| |
+ If we have different name and stream between compared modules an error should be raised
|
| |
+ """
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+ module2_res = pdc_json_res.get()
|
| |
+ module2_res["results"][0]["variant_uid"] = "platform-f27-20171011150016"
|
| |
+ module2_res["results"][0]["variant_name"] = "platform"
|
| |
+ module2_res["results"][0]["variant_version"] = "f27"
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ mock_http.register_uri("GET", module_diff_ns_url, json=module2_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+ module2 = pdc.get_module("platform-f27-20171011150016")
|
| |
+
|
| |
+ with pytest.raises(ValueError):
|
| |
+ module1.get_diff(module2)
|
| |
+
|
| |
+ def test_get_diff_change_dist_tag(self, pdc_json_res):
|
| |
+ """
|
| |
+ Testing if a distag changes between modules
|
| |
+ """
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+ module2_res = pdc_json_res.get()
|
| |
+ module2_res["results"][0]["koji_tag"] = "module-15d35d06c29b1848"
|
| |
+ module2_res["results"][0]["rpms"] = [
|
| |
+ "mariadb-3:10.2.9-3.module_629c669e.src.rpm",
|
| |
+ "mariadb-debugsource-3:10.2.9-3.module_15d35d06.x86_64.rpm",
|
| |
+ "mariadb-connect-engine-debuginfo-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-debuginfo-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-devel-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-connect-engine-3:10.2.9-3.module_629c669e.x86_64.rpm"
|
| |
+ ]
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ mock_http.register_uri("GET", module2_url, json=module2_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+ module2 = pdc.get_module("mariadb-10.2-20171103103655")
|
| |
+
|
| |
+ diff = module1.get_diff(module2, reused=True, dist=True)
|
| |
+
|
| |
+ assert diff["added_rpms"] == []
|
| |
+ assert diff["removed_rpms"] == []
|
| |
+ assert diff["upgraded_rpms"] == []
|
| |
+ assert diff["downgraded_rpms"] == []
|
| |
+ assert len(diff["reused_rpms"]) == 6
|
| |
+ assert diff["changed_distag_rpms"] == [
|
| |
+ ("mariadb-debugsource-3:10.2.9-3.module_629c669e.x86_64.rpm",
|
| |
+ "mariadb-debugsource-3:10.2.9-3.module_15d35d06.x86_64.rpm")]
|
| |
+
|
| |
+ def test_get_rpm_md(self, pdc_json_res):
|
| |
+ """
|
| |
+ Testing to get correct metadata from name of a rpm file.
|
| |
+ """
|
| |
+ module1_res = pdc_json_res.get()
|
| |
+
|
| |
+ with requests_mock.mock() as mock_http:
|
| |
+ mock_http.register_uri("GET", module1_url, json=module1_res)
|
| |
+ pdc = PDC()
|
| |
+ module1 = pdc.get_module("mariadb-10.2-20171019133930")
|
| |
+
|
| |
+ rpm = "python3-hawkey-debuginfo-0:0.10.1-2.module_80d712e7.modularity.1.x86_64.rpm"
|
| |
+
|
| |
+ md = module1.get_rpm_md(rpm)
|
| |
+
|
| |
+ expected_md = {'arch': 'x86_64',
|
| |
+ 'dist_tag': 'module_80d712e7',
|
| |
+ 'epoch': '0',
|
| |
+ 'full_name': 'python3-hawkey-debuginfo-0:0.10.1-2.module_80d712e7.modularity.1.x86_64.rpm',
|
| |
+ 'name': 'python3-hawkey-debuginfo',
|
| |
+ 'release': '2.module_80d712e7.modularityx86_64rpm',
|
| |
+ 'version': '0.10.1'}
|
| |
+
|
| |
+ assert md == expected_md
|
| |
Initial commit.
Signed-off-by: Martin Curlej mcurlej@redhat.com