Add tests for limit=0 routes

Passing ?limit=0 to the blueprints/list, blueprints/changes,
projects/list, modules/list should always return the total possible
results, not 0.

Also move the composer-cli test_diff to the end so that it will work
consistently. Do this by naming it test_z_diff.
This commit is contained in:
Brian C. Lane 2018-08-23 16:17:33 -07:00
parent 0a76d635ca
commit 972b5c4142
2 changed files with 46 additions and 15 deletions

View File

@ -73,21 +73,6 @@ class BlueprintsTest(unittest.TestCase):
self.assertTrue("example-http-server" in output) self.assertTrue("example-http-server" in output)
self.assertTrue("Recipe example-http-server, version 0.0.1 saved." in output) self.assertTrue("Recipe example-http-server, version 0.0.1 saved." in output)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_diff(self):
"""blueprints diff"""
# Get the oldest commit, it should be 2nd to last line
with captured_output() as (out, _):
rc = blueprints_changes("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip().splitlines()
first_commit = output[-2].split()[1]
with captured_output() as (out, _):
rc = blueprints_diff("/run/weldr/api.socket", 0, ["example-http-server", first_commit, "HEAD"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("Changed Version" in output)
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server") @unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_save_0(self): def test_save_0(self):
"""blueprints save""" """blueprints save"""
@ -172,3 +157,20 @@ class BlueprintsTest(unittest.TestCase):
"""blueprints workspace""" """blueprints workspace"""
rc = blueprints_push("/run/weldr/api.socket", 0, ["example-http-server.toml"], show_json=False) rc = blueprints_push("/run/weldr/api.socket", 0, ["example-http-server.toml"], show_json=False)
self.assertTrue(rc == 0) self.assertTrue(rc == 0)
# XXX MUST COME LAST
# XXX which is what _z_ ensures
@unittest.skipUnless(os.path.exists("/run/weldr/api.socket"), "Test requires a running API server")
def test_z_diff(self):
"""blueprints diff"""
# Get the oldest commit, it should be 2nd to last line
with captured_output() as (out, _):
rc = blueprints_changes("/run/weldr/api.socket", 0, ["example-http-server"], show_json=False)
output = out.getvalue().strip().splitlines()
first_commit = output[-2].split()[1]
with captured_output() as (out, _):
rc = blueprints_diff("/run/weldr/api.socket", 0, ["example-http-server", first_commit, "HEAD"], show_json=False)
output = out.getvalue().strip()
self.assertTrue(rc == 0)
self.assertTrue("Changed Version" in output)

View File

@ -141,6 +141,13 @@ class ServerTestCase(unittest.TestCase):
data = json.loads(resp.data) data = json.loads(resp.data)
self.assertEqual(data, list_dict) self.assertEqual(data, list_dict)
# Make sure limit=0 still returns the correct total
resp = self.server.get("/api/v0/blueprints/list?limit=0")
data = json.loads(resp.data)
self.assertEqual(data["limit"], 0)
self.assertEqual(data["offset"], 0)
self.assertEqual(data["total"], list_dict["total"])
def test_03_blueprints_info_1(self): def test_03_blueprints_info_1(self):
"""Test the /api/v0/blueprints/info route with one blueprint""" """Test the /api/v0/blueprints/info route with one blueprint"""
info_dict_1 = {"changes":[{"changed":False, "name":"example-http-server"}], info_dict_1 = {"changes":[{"changed":False, "name":"example-http-server"}],
@ -214,6 +221,13 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(data["blueprints"][0]["name"], "example-http-server") self.assertEqual(data["blueprints"][0]["name"], "example-http-server")
self.assertEqual(len(data["blueprints"][0]["changes"]), 1) self.assertEqual(len(data["blueprints"][0]["changes"]), 1)
# Make sure limit=0 still returns the correct total
resp = self.server.get("/api/v0/blueprints/changes/example-http-server?limit=0")
data = json.loads(resp.data)
self.assertEqual(data["limit"], 0)
self.assertEqual(data["offset"], 0)
self.assertEqual(data["blueprints"][0]["total"], 1)
def test_04a_blueprints_diff_empty_ws(self): def test_04a_blueprints_diff_empty_ws(self):
"""Test the /api/v0/diff/NEWEST/WORKSPACE with empty workspace""" """Test the /api/v0/diff/NEWEST/WORKSPACE with empty workspace"""
resp = self.server.get("/api/v0/blueprints/diff/example-glusterfs/NEWEST/WORKSPACE") resp = self.server.get("/api/v0/blueprints/diff/example-glusterfs/NEWEST/WORKSPACE")
@ -515,6 +529,13 @@ class ServerTestCase(unittest.TestCase):
projects = data.get("projects") projects = data.get("projects")
self.assertEqual(len(projects) > 10, True) self.assertEqual(len(projects) > 10, True)
expected_total = data["total"]
# Make sure limit=0 still returns the correct total
resp = self.server.get("/api/v0/projects/list?limit=0")
data = json.loads(resp.data)
self.assertEqual(data["total"], expected_total)
def test_projects_info(self): def test_projects_info(self):
"""Test /api/v0/projects/info/<project_names>""" """Test /api/v0/projects/info/<project_names>"""
resp = self.server.get("/api/v0/projects/info/bash") resp = self.server.get("/api/v0/projects/info/bash")
@ -676,6 +697,8 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(len(modules) > 10, True) self.assertEqual(len(modules) > 10, True)
self.assertEqual(modules[0]["group_type"], "rpm") self.assertEqual(modules[0]["group_type"], "rpm")
expected_total = data["total"]
resp = self.server.get("/api/v0/modules/list/d*") resp = self.server.get("/api/v0/modules/list/d*")
data = json.loads(resp.data) data = json.loads(resp.data)
self.assertNotEqual(data, None) self.assertNotEqual(data, None)
@ -683,6 +706,12 @@ class ServerTestCase(unittest.TestCase):
self.assertEqual(len(modules) > 0, True) self.assertEqual(len(modules) > 0, True)
self.assertEqual(modules[0]["name"].startswith("d"), True) self.assertEqual(modules[0]["name"].startswith("d"), True)
# Make sure limit=0 still returns the correct total
resp = self.server.get("/api/v0/modules/list?limit=0")
data = json.loads(resp.data)
self.assertNotEqual(data, None)
self.assertEqual(data["total"], expected_total)
def test_modules_info(self): def test_modules_info(self):
"""Test /api/v0/modules/info""" """Test /api/v0/modules/info"""
resp = self.server.get("/api/v0/modules/info/bash") resp = self.server.get("/api/v0/modules/info/bash")