Skip to content

Commit

Permalink
Update change_assignee
Browse files Browse the repository at this point in the history
- Add new user case handling: new_assignee is a user but not part of the system (not in DB)
- Add corresponding test
  • Loading branch information
orzionpour committed Nov 27, 2021
1 parent f5e2986 commit e49462b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 19 additions & 1 deletion tasks/tests/test_change_assignee.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit e49462b

Please sign in to comment.