diff --git a/tasks/models.py b/tasks/models.py index 65d841d..7c1ea6d 100644 --- a/tasks/models.py +++ b/tasks/models.py @@ -54,6 +54,8 @@ def filter_by_symbol(cls, priority_filter): return cls.objects.filter(priority=priority_filter) def change_assignee(self, new_assignee): + if new_assignee not in User.objects.all(): + raise Exception prev_assignee = self.assignee if new_assignee is None: raise TypeError("Valid user must be provided") diff --git a/tasks/tests/test_change_assignee.py b/tasks/tests/test_change_assignee.py index 8c0c2b5..916f436 100644 --- a/tasks/tests/test_change_assignee.py +++ b/tasks/tests/test_change_assignee.py @@ -1,6 +1,7 @@ import pytest from tasks.models import Task -from users.models import Team, User +from users.models import Team, User, Role +from django.contrib.auth.models import User as DjangoUser @pytest.mark.django_db @@ -34,3 +35,20 @@ def test_change_assignee_other_team(self, test_db): with pytest.raises(Exception): task.change_assignee(employee_2) assert task.assignee == employee_1 + + @pytest.fixture + def out_db_user(self, test_db): + team = test_db[0][0] + django_user = DjangoUser.objects.create(username="testtest", + password="ssdalhSFDAJ23!", + email="example@redhat.com", + first_name="test", + last_name="test") + user = User(user=django_user, role=Role.EMPLOYEE, team=team) + return user + + def test_change_assignee_not_db_user(self, test_db, out_db_user): + tasks = test_db[3] + task = tasks[0] + with pytest.raises(Exception): + task.change_assignee(out_db_user)