Skip to content

Commit

Permalink
enhance frontend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hgy59 committed Jan 1, 2024
1 parent fed32c9 commit b2368a7
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions spkrepo/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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"))
Expand Down

0 comments on commit b2368a7

Please sign in to comment.