Skip to content

Commit

Permalink
Tests and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 28, 2024
1 parent 8e5a858 commit 72cef68
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
14 changes: 14 additions & 0 deletions temba/orgs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,20 @@ def test_list(self):
self.assertListFetch(list_url + "?search=andy", [self.admin], context_objects=[self.admin])
self.assertListFetch(list_url + "[email protected]", [self.admin], context_objects=[self.editor])

def test_team(self):
team_url = reverse("orgs.user_team", args=[self.org.default_ticket_team.id])

# nobody can access if users feature not enabled
response = self.requestView(team_url, self.admin)
self.assertRedirect(response, reverse("orgs.org_workspace"))

self.org.features = [Org.FEATURE_USERS]
self.org.save(update_fields=("features",))

self.assertRequestDisallowed(team_url, [None, self.user, self.editor, self.agent])

self.assertListFetch(team_url, [self.admin], context_objects=[self.agent])

def test_update(self):
update_url = reverse("orgs.user_update", args=[self.agent.id])

Expand Down
67 changes: 67 additions & 0 deletions temba/tickets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,73 @@ def test_create(self):
team = Team.objects.get(name="Sales")
self.assertEqual({sales}, set(team.topics.all()))

def test_update(self):
sales = Topic.create(self.org, self.admin, "Sales")
marketing = Topic.create(self.org, self.admin, "Marketing")
team = Team.create(self.org, self.admin, "Sales", topics=[sales])

update_url = reverse("tickets.team_update", args=[team.id])

self.assertRequestDisallowed(update_url, [None, self.user, self.agent, self.editor, self.admin2])

self.assertUpdateFetch(update_url, [self.admin], form_fields=["name", "topics"])

# names must be unique (case-insensitive)
self.assertUpdateSubmit(
update_url,
self.admin,
{"name": "all topics"},
form_errors={"name": "Team with this name already exists."},
object_unchanged=team,
)

self.assertUpdateSubmit(
update_url, self.admin, {"name": "Marketing", "topics": [marketing.id]}, success_status=302
)

team.refresh_from_db()
self.assertEqual(team.name, "Marketing")
self.assertEqual({marketing}, set(team.topics.all()))

# can't edit a system team
self.assertRequestDisallowed(
reverse("tickets.team_update", args=[self.org.default_ticket_team.id]), [self.admin]
)

def test_delete(self):
sales = Topic.create(self.org, self.admin, "Sales")
team1 = Team.create(self.org, self.admin, "Sales", topics=[sales])
team2 = Team.create(self.org, self.admin, "Other", topics=[sales])

delete_url = reverse("tickets.team_delete", args=[team1.id])

self.assertRequestDisallowed(delete_url, [None, self.user, self.agent, self.editor, self.admin2])

response = self.assertDeleteFetch(delete_url, [self.admin])
self.assertContains(response, "You are about to delete")

# submit to delete it
response = self.assertDeleteSubmit(delete_url, self.admin, object_deactivated=team1, success_status=302)

# other team unafected
team2.refresh_from_db()
self.assertTrue(team2.is_active)

# we should have been redirected to the team list
self.assertEqual("/team/", response.url)

def test_list(self):
sales = Topic.create(self.org, self.admin, "Sales")
team1 = Team.create(self.org, self.admin, "Sales", topics=[sales])
team2 = Team.create(self.org, self.admin, "Other", topics=[sales])
Team.create(self.org2, self.admin2, "Cars", topics=[])

list_url = reverse("tickets.team_list")

self.assertRequestDisallowed(list_url, [None, self.agent, self.editor])

self.assertListFetch(list_url, [self.admin], context_objects=[self.org.default_ticket_team, team2, team1])


class TicketCRUDLTest(TembaTest, CRUDLTestMixin):
def setUp(self):
Expand Down

0 comments on commit 72cef68

Please sign in to comment.