From b2368a7d9d0fda6084f842e63af7fa2e7380102e Mon Sep 17 00:00:00 2001 From: hgy59 Date: Mon, 1 Jan 2024 13:47:33 +0100 Subject: [PATCH] enhance frontend tests --- spkrepo/tests/test_frontend.py | 67 +++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/spkrepo/tests/test_frontend.py b/spkrepo/tests/test_frontend.py index 4bd76e8..55231c1 100644 --- a/spkrepo/tests/test_frontend.py +++ b/spkrepo/tests/test_frontend.py @@ -12,38 +12,46 @@ class IndexTestCase(BaseTestCase): def test_get_anonymous(self): response = self.client.get(url_for("frontend.index")) self.assert200(response) - self.assertIn("Login", response.data.decode()) - self.assertIn("Register", response.data.decode()) + response_data = response.data.decode() + self.assertIn("Login", response_data) + self.assertIn("Register", response_data) def test_get_logged_user(self): with self.logged_user(): response = self.client.get(url_for("frontend.index")) self.assert200(response) - self.assertIn("Logout", response.data.decode()) - self.assertIn("Profile", response.data.decode()) + response_data = response.data.decode() + self.assertIn("Logout", response_data) + self.assertIn("Profile", response_data) class PackagesTestCase(BaseTestCase): - def test_get_active(self): + + # Assert beta is not shown on Packages page + def test_get_active_not_stable(self): build = BuildFactory(version__report_url=None, active=True) db.session.commit() response = self.client.get(url_for("frontend.packages")) self.assert200(response) + response_data = response.data.decode() self.assertIn( build.version.displaynames["enu"].displayname, - response.data.decode(), + response_data, ) - self.assertNotIn("beta", response.data.decode()) + self.assertNotIn("beta", response_data) - def test_get_not_active(self): + # Assert package with only inactive version(s) is shown on Packages page + def test_get_not_active_not_stable(self): build = BuildFactory(active=False) db.session.commit() response = self.client.get(url_for("frontend.packages")) self.assert200(response) + response_data = response.data.decode() self.assertIn( build.version.displaynames["enu"].displayname, - response.data.decode(), + response_data, ) + self.assertNotIn("beta", response_data) class PackageTestCase(BaseTestCase): @@ -58,17 +66,19 @@ def test_get_active_stable(self): url_for("frontend.package", name=build.version.package.name) ) self.assert200(response) + response_data = response.data.decode() for a in build.architectures: - self.assertIn(a.code, response.data.decode()) + self.assertIn(a.code, response_data) self.assertIn( build.version.displaynames["enu"].displayname, - response.data.decode(), + response_data, ) self.assertIn( build.version.descriptions["enu"].description, - response.data.decode(), + response_data, ) - self.assertNotIn("beta", response.data.decode()) + self.assertNotIn("beta", response_data) + self.assertIn("label label-success", response_data) def test_get_not_active_stable(self): build = BuildFactory( @@ -81,17 +91,19 @@ def test_get_not_active_stable(self): url_for("frontend.package", name=build.version.package.name) ) self.assert200(response) + response_data = response.data.decode() for a in build.architectures: - self.assertIn(a.code, response.data.decode()) + self.assertIn(a.code, response_data) self.assertIn( build.version.displaynames["enu"].displayname, - response.data.decode(), + response_data, ) self.assertIn( build.version.descriptions["enu"].description, - response.data.decode(), + response_data, ) - self.assertNotIn("beta", response.data.decode()) + self.assertNotIn("beta", response_data) + self.assertIn("label label-default", response_data) def test_get_active_not_stable(self): build = BuildFactory( @@ -103,17 +115,19 @@ def test_get_active_not_stable(self): url_for("frontend.package", name=build.version.package.name) ) self.assert200(response) + response_data = response.data.decode() for a in build.architectures: - self.assertIn(a.code, response.data.decode()) + self.assertIn(a.code, response_data) self.assertIn( build.version.displaynames["enu"].displayname, - response.data.decode(), + response_data, ) self.assertIn( build.version.descriptions["enu"].description, - response.data.decode(), + response_data, ) - self.assertIn("beta", response.data.decode()) + self.assertIn("beta", response_data) + self.assertIn("label label-success", response_data) def test_get_not_active_not_stable(self): build = BuildFactory( @@ -125,17 +139,20 @@ def test_get_not_active_not_stable(self): url_for("frontend.package", name=build.version.package.name) ) self.assert200(response) + response_data = response.data.decode() for a in build.architectures: - self.assertIn(a.code, response.data.decode()) + self.assertIn(a.code, response_data) self.assertIn( build.version.displaynames["enu"].displayname, - response.data.decode(), + response_data, ) self.assertIn( build.version.descriptions["enu"].description, - response.data.decode(), + response_data, ) - self.assertIn("beta", response.data.decode()) + self.assertIn("beta", response_data) + self.assertIn("label label-default", response_data) + self.assertIn("Inactive: Manual installation only.", response_data) def test_get_no_package(self): response = self.client.get(url_for("frontend.package", name="no-package"))