forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Team.all_topics to more easily model a team that can access all t…
…opics
- Loading branch information
1 parent
ad87740
commit 78081da
Showing
3 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Generated by Django 5.1.2 on 2024-10-23 19:51 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("tickets", "0064_shortcut")] | ||
|
||
operations = [ | ||
migrations.AddField(model_name="team", name="all_topics", field=models.BooleanField(default=False)), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1286,14 +1286,20 @@ def _import(definition, preview=False): | |
|
||
def test_release(self): | ||
topic1 = Topic.create(self.org, self.admin, "Sales") | ||
topic2 = Topic.create(self.org, self.admin, "Support") | ||
flow = self.create_flow("Test") | ||
flow.topic_dependencies.add(topic1) | ||
team = Team.create(self.org, self.admin, "Sales & Support", topics=[topic1, topic2]) | ||
|
||
topic1.release(self.admin) | ||
|
||
self.assertFalse(topic1.is_active) | ||
self.assertTrue(topic1.name.startswith("deleted-")) | ||
|
||
# topic should be removed from team | ||
self.assertEqual({topic2}, set(team.topics.all())) | ||
|
||
# flow should be flagged as having issues | ||
flow.refresh_from_db() | ||
self.assertTrue(flow.has_issues) | ||
|
||
|
@@ -1313,24 +1319,32 @@ def test_release(self): | |
|
||
class TeamTest(TembaTest): | ||
def test_create(self): | ||
team1 = Team.create(self.org, self.admin, "Sales") | ||
sales = Topic.create(self.org, self.admin, "Sales") | ||
support = Topic.create(self.org, self.admin, "Support") | ||
team1 = Team.create(self.org, self.admin, "Sales & Support", topics=[sales, support]) | ||
agent2 = self.create_user("[email protected]") | ||
self.org.add_user(self.agent, OrgRole.AGENT, team=team1) | ||
self.org.add_user(agent2, OrgRole.AGENT, team=team1) | ||
|
||
self.assertEqual("Sales", team1.name) | ||
self.assertEqual("Sales", str(team1)) | ||
self.assertEqual(f'<Team: id={team1.id} name="Sales">', repr(team1)) | ||
|
||
self.assertEqual("Sales & Support", team1.name) | ||
self.assertEqual("Sales & Support", str(team1)) | ||
self.assertEqual(f'<Team: id={team1.id} name="Sales & Support">', repr(team1)) | ||
self.assertEqual({self.agent, agent2}, set(team1.get_users())) | ||
self.assertEqual({sales, support}, set(team1.topics.all())) | ||
self.assertFalse(team1.all_topics) | ||
|
||
# create an unrestricted team | ||
team2 = Team.create(self.org, self.admin, "Any Topic", all_topics=True) | ||
self.assertEqual(set(), set(team2.topics.all())) | ||
self.assertTrue(team2.all_topics) | ||
|
||
# try to create with invalid name | ||
with self.assertRaises(AssertionError): | ||
Team.create(self.org, self.admin, '"Support"') | ||
|
||
# try to create with name that already exists | ||
with self.assertRaises(AssertionError): | ||
Team.create(self.org, self.admin, "Sales") | ||
Team.create(self.org, self.admin, "Sales & Support") | ||
|
||
def test_release(self): | ||
team1 = Team.create(self.org, self.admin, "Sales") | ||
|