tests: Expand test coverage of the v0 and v1 sources API

This commit is contained in:
Brian C. Lane 2019-08-08 11:57:42 -07:00
parent 0935a10a0b
commit 40bb80f10f
4 changed files with 212 additions and 0 deletions

View File

@ -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 = []

View File

@ -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 = []

View File

@ -1,4 +1,5 @@
name = "single-repo" name = "single-repo"
id = "single-repo"
url = "file:///tmp/lorax-empty-repo/" url = "file:///tmp/lorax-empty-repo/"
type = "yum-baseurl" type = "yum-baseurl"
check_ssl = false check_ssl = false

View File

@ -663,6 +663,49 @@ class ServerTestCase(unittest.TestCase):
self.assertTrue("name" in sources["lorax-3"]) self.assertTrue("name" in sources["lorax-3"])
self.assertEqual(sources["lorax-3"]["name"], "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): def test_projects_source_01_info(self):
"""Test /api/v1/projects/source/info""" """Test /api/v1/projects/source/info"""
resp = self.server.get("/api/v1/projects/source/info/lorax-3") 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.assertTrue("name" in sources["lorax-3"])
self.assertEqual(sources["lorax-3"]["name"], "Lorax test repo 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): def test_projects_source_00_new_json(self):
"""Test /api/v0/projects/source/new with a new json source""" """Test /api/v0/projects/source/new with a new json source"""
json_source = open("./tests/pylorax/source/test-repo.json").read() 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.assertEqual(repo["check_ssl"], False)
self.assertTrue("gpgkey_urls" not in repo) 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): def test_projects_source_00_bad_url(self):
"""Test /api/v0/projects/source/new with a new source that has an invalid url""" """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() toml_source = open("./tests/pylorax/source/bad-repo.toml").read()
@ -804,6 +942,17 @@ class ServerTestCase(unittest.TestCase):
data = json.loads(resp.data) data = json.loads(resp.data)
self.assertEqual(data["status"], False) 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): def test_projects_source_01_delete_system(self):
"""Test /api/v0/projects/source/delete a system source""" """Test /api/v0/projects/source/delete a system source"""
if self.rawhide: if self.rawhide:
@ -1507,11 +1656,59 @@ class ServerTestCase(unittest.TestCase):
resp = self.server.get("/api/v0/projects/source/info/" + UTF8_TEST_STRING) resp = self.server.get("/api/v0/projects/source/info/" + UTF8_TEST_STRING)
self.assertInputError(resp) 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): def test_projects_source_info_v1_input(self):
"""Test the /api/v1/projects/source/info input character checking""" """Test the /api/v1/projects/source/info input character checking"""
resp = self.server.get("/api/v1/projects/source/info/" + UTF8_TEST_STRING) resp = self.server.get("/api/v1/projects/source/info/" + UTF8_TEST_STRING)
self.assertInputError(resp) 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): def test_projects_source_delete_input(self):
"""Test the projects/source/delete input character checking""" """Test the projects/source/delete input character checking"""
resp = self.server.delete("/api/v0/projects/source/delete/" + UTF8_TEST_STRING) resp = self.server.delete("/api/v0/projects/source/delete/" + UTF8_TEST_STRING)