diff --git a/tests/pylorax/source/replace-fedora.toml b/tests/pylorax/source/replace-fedora.toml new file mode 100644 index 00000000..ab0a795a --- /dev/null +++ b/tests/pylorax/source/replace-fedora.toml @@ -0,0 +1,7 @@ +name = "fedora" +id = "fedora" +url = "file:///tmp/lorax-empty-repo/" +type = "yum-baseurl" +check_ssl = false +check_gpg = true +gpgkey_urls = [] diff --git a/tests/pylorax/source/replace-rawhide.toml b/tests/pylorax/source/replace-rawhide.toml new file mode 100644 index 00000000..50802fad --- /dev/null +++ b/tests/pylorax/source/replace-rawhide.toml @@ -0,0 +1,7 @@ +name = "rawhide" +id = "rawhide" +url = "file:///tmp/lorax-empty-repo/" +type = "yum-baseurl" +check_ssl = false +check_gpg = true +gpgkey_urls = [] diff --git a/tests/pylorax/source/replace-repo.toml b/tests/pylorax/source/replace-repo.toml index d0b1ef8d..a8dc5883 100644 --- a/tests/pylorax/source/replace-repo.toml +++ b/tests/pylorax/source/replace-repo.toml @@ -1,4 +1,5 @@ name = "single-repo" +id = "single-repo" url = "file:///tmp/lorax-empty-repo/" type = "yum-baseurl" check_ssl = false diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index f5dc38b1..6d692632 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -663,6 +663,49 @@ class ServerTestCase(unittest.TestCase): self.assertTrue("name" in sources["lorax-3"]) self.assertEqual(sources["lorax-3"]["name"], "lorax-3") + def test_projects_source_00_info_comma(self): + """Test /api/v0/projects/source/info/lorax-3,lorax-2""" + resp = self.server.get("/api/v0/projects/source/info/lorax-3,lorax-2") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data["sources"]) + sources = data["sources"] + self.assertEqual(len(sources), 2) + self.assertTrue("lorax-3" in sources) + self.assertTrue("id" not in sources["lorax-3"]) + self.assertTrue("name" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["name"], "lorax-3") + + self.assertTrue("lorax-2" in sources) + self.assertTrue("id" not in sources["lorax-2"]) + self.assertTrue("name" in sources["lorax-2"]) + self.assertEqual(sources["lorax-2"]["name"], "lorax-2") + + def test_projects_source_00_info_toml(self): + """Test /api/v0/projects/source/info TOML output""" + resp = self.server.get("/api/v0/projects/source/info/lorax-3?format=toml") + data = toml.loads(resp.data) + self.assertNotEqual(data, None) + print(data) + sources = data + self.assertTrue("lorax-3" in sources) + self.assertTrue("id" not in sources["lorax-3"]) + self.assertTrue("name" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["name"], "lorax-3") + + def test_projects_source_00_info_wild(self): + """Test /api/v0/projects/source/info/* wildcard""" + resp = self.server.get("/api/v0/projects/source/info/*") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data["sources"]) + sources = data["sources"] + self.assertTrue(len(sources) > 1) + self.assertTrue("lorax-3" in sources) + self.assertTrue("id" not in sources["lorax-3"]) + self.assertTrue("name" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["name"], "lorax-3") + def test_projects_source_01_info(self): """Test /api/v1/projects/source/info""" resp = self.server.get("/api/v1/projects/source/info/lorax-3") @@ -675,6 +718,53 @@ class ServerTestCase(unittest.TestCase): self.assertTrue("name" in sources["lorax-3"]) self.assertEqual(sources["lorax-3"]["name"], "Lorax test repo 3") + def test_projects_source_01_info_comma(self): + """Test /api/v1/projects/source/info/lorax-3,lorax-2""" + resp = self.server.get("/api/v1/projects/source/info/lorax-3,lorax-2") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data["sources"]) + sources = data["sources"] + self.assertEqual(len(sources), 2) + self.assertTrue("lorax-3" in sources) + self.assertTrue("id" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["id"], "lorax-3") + self.assertTrue("name" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["name"], "Lorax test repo 3") + + self.assertTrue("lorax-2" in sources) + self.assertTrue("id" in sources["lorax-2"]) + self.assertEqual(sources["lorax-2"]["id"], "lorax-2") + self.assertTrue("name" in sources["lorax-2"]) + self.assertEqual(sources["lorax-2"]["name"], "Lorax test repo 2") + + def test_projects_source_01_info_toml(self): + """Test /api/v1/projects/source/info TOML output""" + resp = self.server.get("/api/v1/projects/source/info/lorax-3?format=toml") + data = toml.loads(resp.data) + self.assertNotEqual(data, None) + print(data) + sources = data + self.assertTrue("lorax-3" in sources) + self.assertTrue("id" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["id"], "lorax-3") + self.assertTrue("name" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["name"], "Lorax test repo 3") + + def test_projects_source_01_info_wild(self): + """Test /api/v1/projects/source/info/* wildcard""" + resp = self.server.get("/api/v1/projects/source/info/*") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data["sources"]) + sources = data["sources"] + self.assertTrue(len(sources) > 1) + self.assertTrue("lorax-3" in sources) + self.assertTrue("id" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["id"], "lorax-3") + self.assertTrue("name" in sources["lorax-3"]) + self.assertEqual(sources["lorax-3"]["name"], "Lorax test repo 3") + def test_projects_source_00_new_json(self): """Test /api/v0/projects/source/new with a new json source""" json_source = open("./tests/pylorax/source/test-repo.json").read() @@ -793,6 +883,54 @@ class ServerTestCase(unittest.TestCase): self.assertEqual(repo["check_ssl"], False) self.assertTrue("gpgkey_urls" not in repo) + def test_projects_source_00_replace_system(self): + """Test /api/v0/projects/source/new with a replacement system source""" + if self.rawhide: + toml_source = open("./tests/pylorax/source/replace-rawhide.toml").read() + else: + toml_source = open("./tests/pylorax/source/replace-fedora.toml").read() + self.assertTrue(len(toml_source) > 0) + resp = self.server.post("/api/v0/projects/source/new", + data=toml_source, + content_type="text/x-toml") + self.assertEqual(resp.status_code, 400) + data = json.loads(resp.data) + self.assertEqual(data["status"], False) + + def test_projects_source_01_replace(self): + """Test /api/v1/projects/source/new with a replacement source""" + toml_source = open("./tests/pylorax/source/replace-repo.toml").read() + self.assertTrue(len(toml_source) > 0) + resp = self.server.post("/api/v1/projects/source/new", + data=toml_source, + content_type="text/x-toml") + data = json.loads(resp.data) + self.assertEqual(data, {"status":True}) + + # Check to see if it was really changed + resp = self.server.get("/api/v1/projects/source/info/single-repo") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + sources = data["sources"] + self.assertTrue("single-repo" in sources) + repo = sources["single-repo"] + self.assertEqual(repo["check_ssl"], False) + self.assertTrue("gpgkey_urls" not in repo) + + def test_projects_source_01_replace_system(self): + """Test /api/v1/projects/source/new with a replacement system source""" + if self.rawhide: + toml_source = open("./tests/pylorax/source/replace-rawhide.toml").read() + else: + toml_source = open("./tests/pylorax/source/replace-fedora.toml").read() + self.assertTrue(len(toml_source) > 0) + resp = self.server.post("/api/v1/projects/source/new", + data=toml_source, + content_type="text/x-toml") + self.assertEqual(resp.status_code, 400) + data = json.loads(resp.data) + self.assertEqual(data["status"], False) + def test_projects_source_00_bad_url(self): """Test /api/v0/projects/source/new with a new source that has an invalid url""" toml_source = open("./tests/pylorax/source/bad-repo.toml").read() @@ -804,6 +942,17 @@ class ServerTestCase(unittest.TestCase): data = json.loads(resp.data) self.assertEqual(data["status"], False) + def test_projects_source_01_bad_url(self): + """Test /api/v1/projects/source/new with a new source that has an invalid url""" + toml_source = open("./tests/pylorax/source/bad-repo.toml").read() + self.assertTrue(len(toml_source) > 0) + resp = self.server.post("/api/v1/projects/source/new", + data=toml_source, + content_type="text/x-toml") + self.assertEqual(resp.status_code, 400) + data = json.loads(resp.data) + self.assertEqual(data["status"], False) + def test_projects_source_01_delete_system(self): """Test /api/v0/projects/source/delete a system source""" if self.rawhide: @@ -1507,11 +1656,59 @@ class ServerTestCase(unittest.TestCase): resp = self.server.get("/api/v0/projects/source/info/" + UTF8_TEST_STRING) self.assertInputError(resp) + # Test failure for bad format characters + resp = self.server.get("/api/v0/projects/source/info/lorax-3?format=" + UTF8_TEST_STRING) + self.assertInputError(resp) + + def test_projects_source_info_unknown(self): + """Test the /api/v0/projects/source/info unknown source""" + resp = self.server.get("/api/v0/projects/source/info/notasource") + data = json.loads(resp.data) + print(data) + self.assertNotEqual(data, None) + self.assertTrue(len(data["errors"]) > 0) + self.assertTrue("is not a valid source" in data["errors"][0]["msg"]) + + def test_projects_source_info_unknown_toml(self): + """Test the /api/v0/projects/source/info unknown source TOML output""" + resp = self.server.get("/api/v0/projects/source/info/notasource?format=toml") + data = json.loads(resp.data) + print(data) + self.assertNotEqual(data, None) + self.assertEqual(resp.status_code, 400) + self.assertEqual(data["status"], False) + self.assertTrue(len(data["errors"]) > 0) + self.assertTrue("is not a valid source" in data["errors"][0]["msg"]) + def test_projects_source_info_v1_input(self): """Test the /api/v1/projects/source/info input character checking""" resp = self.server.get("/api/v1/projects/source/info/" + UTF8_TEST_STRING) self.assertInputError(resp) + # Test failure for bad format characters + resp = self.server.get("/api/v1/projects/source/info/lorax-3?format=" + UTF8_TEST_STRING) + self.assertInputError(resp) + + def test_projects_source_info_v1_unknown(self): + """Test the /api/v1/projects/source/info unknown source""" + resp = self.server.get("/api/v1/projects/source/info/notasource") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data) + self.assertTrue(len(data["errors"]) > 0) + self.assertTrue("is not a valid source" in data["errors"][0]["msg"]) + + def test_projects_source_info_v1_unknown_toml(self): + """Test the /api/v1/projects/source/info unknown source TOML output""" + resp = self.server.get("/api/v1/projects/source/info/notasource?format=toml") + data = json.loads(resp.data) + self.assertNotEqual(data, None) + print(data) + self.assertEqual(resp.status_code, 400) + self.assertEqual(data["status"], False) + self.assertTrue(len(data["errors"]) > 0) + self.assertTrue("is not a valid source" in data["errors"][0]["msg"]) + def test_projects_source_delete_input(self): """Test the projects/source/delete input character checking""" resp = self.server.delete("/api/v0/projects/source/delete/" + UTF8_TEST_STRING)