Skip to content

Commit

Permalink
Improve template test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mfosterw committed Jan 14, 2024
1 parent 9af1de0 commit f94ba08
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions democrasite/webiscite/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .factories import BillFactory


class TestWebisciteTemplates:
def test_bill_detail_open(self, bill: Bill, client: Client):
class TestBillDetailTemplate:
def test_bill_open(self, bill: Bill, client: Client):
response = client.get(reverse("webiscite:bill-detail", args=(bill.id,)))

assert b"Log in to vote" in response.content
Expand All @@ -21,7 +21,7 @@ def test_bill_detail_open(self, bill: Bill, client: Client):
assert b"svg" in response.content
assert bill.get_state_display().encode() not in response.content

def test_bill_detail_closed(self, client: Client, user):
def test_bill_closed(self, client: Client, user):
bill = BillFactory(state=Bill.CLOSED, author=user)

response = client.get(reverse("webiscite:bill-detail", args=(bill.id,)))
Expand All @@ -33,7 +33,7 @@ def test_bill_detail_closed(self, client: Client, user):
assert b"svg" not in response.content
assert bill.get_state_display().encode() in response.content

def test_bill_detail_approved(self, client: Client, user):
def test_bill_approved(self, client: Client, user):
bill = BillFactory(state=Bill.APPROVED, author=user, constitutional=True)

response = client.get(reverse("webiscite:bill-detail", args=(bill.id,)))
Expand All @@ -46,6 +46,8 @@ def test_bill_detail_approved(self, client: Client, user):
assert bill.get_state_display().encode() in response.content
assert b"Constitution" in response.content


class TestBillUpdateTemplate:
def test_bill_form(self, bill: Bill, client: Client):
client.force_login(bill.author)

Expand All @@ -54,7 +56,9 @@ def test_bill_form(self, bill: Bill, client: Client):
assert response.status_code == 200
assert response.templates[0].name == "webiscite/bill_form.html"

def test_bill_list_empty(self, client: Client):

class TestBillListTemplate:
def test_empty(self, client: Client):
response = client.get(reverse("webiscite:index"))

assert response.status_code == 200
Expand All @@ -63,15 +67,24 @@ def test_bill_list_empty(self, client: Client):
assert b"you haven't proposed any bills" not in response.content
assert b"you haven't voted on any bills" not in response.content

def test_bill_list_logged_out(self, bill: Bill, client: Client):
def test_logged_out(self, bill: Bill, client: Client):
response = client.get(reverse("webiscite:index"))

assert response.status_code == 200
assert bill.name.encode() in response.content
assert b"Log in to vote" in response.content
assert b"vote.js" not in response.content

def test_bill_list_logged_in(self, bill: Bill, client: Client, user):
def test_amendment(self, client: Client):
bill = BillFactory(constitutional=True)

response = client.get(reverse("webiscite:index"))

assert response.status_code == 200
assert bill.name.encode() in response.content
assert b"Constitution" in response.content

def test_logged_in(self, bill: Bill, client: Client, user):
client.force_login(user)

response = client.get(reverse("webiscite:index"))
Expand All @@ -90,7 +103,18 @@ def test_my_bills_empty(self, client: Client, user):
assert b"you haven't proposed any bills" in response.content
assert b"you haven't voted on any bills" not in response.content

def test_my_bills_populated(self, bill: Bill, client: Client):
def test_my_bills_approved(self, client: Client):
bill = BillFactory(state=Bill.APPROVED)
client.force_login(bill.author)

response = client.get(reverse("webiscite:my-bills"))

assert response.status_code == 200
assert b"Log in to vote" not in response.content
assert b"vote.js" in response.content

def test_my_bills_failed(self, client: Client):
bill = BillFactory(state=Bill.FAILED)
client.force_login(bill.author)

response = client.get(reverse("webiscite:my-bills"))
Expand Down

0 comments on commit f94ba08

Please sign in to comment.