Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task change assignee #83

Merged
merged 14 commits into from
Nov 29, 2021
82 changes: 82 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pytest
from users.models import User, Team, Role
from tasks.models import Task, Priority, Status


@pytest.fixture
def teams():
"""
Adds teams to DB
"""
team1 = Team.objects.create(name="Team1",
description="This is a test team")
team2 = Team.objects.create(name="Team2",
description="This is a test team")
team3 = Team.objects.create(name="Team3",
description="This is a test team")
return team1, team2, team3
orzionpour marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture
def users(teams):
"""
Adds users to DB
"""
team1, team2, team3 = teams
employees = []
managers = []
users_counter = 0
for i in range(3):
kobihk marked this conversation as resolved.
Show resolved Hide resolved
for team in (team1, team2):
employee = User.create_user(username=f"User{users_counter}",
email=f"User{users_counter}@redhat.com",
password="ssSSAD231!@",
orzionpour marked this conversation as resolved.
Show resolved Hide resolved
first_name=f"User{users_counter}",
last_name=f"User{users_counter}",
role=Role.EMPLOYEE,
team=team)
employees += [employee]
orzionpour marked this conversation as resolved.
Show resolved Hide resolved
users_counter += 1
for i, team in enumerate((team1, team2, team3)):
manager = User.create_user(username=f"Manager{i}",
email=f"Manager{i}@redhat.com",
password="ssSSAD231!@",
first_name=f"Manager{i}",
last_name=f"Manager{i}",
role=Role.MANAGER,
team=team)
managers += [manager]
orzionpour marked this conversation as resolved.
Show resolved Hide resolved
return teams, tuple(employees), tuple(managers)


@pytest.fixture
def tasks(users):
"""
Adds tasks to DB
"""
teams, employees, managers = users
tasks = []
for k in range(3):
for i in range(3):
for j in range(2):
orzionpour marked this conversation as resolved.
Show resolved Hide resolved
task = Task.objects.create(title=f"Task{j}",
assignee=employees[k + i],
created_by=managers[k],
priority=Priority.LOW,
status=Status.BACKLOG,
description="Test task")
tasks += [task]
return teams, employees, managers, tuple(tasks)


@pytest.fixture
def test_db(tasks):
"""
Returns test DB components as tuples.
The test DB contains: 3 teams, 3 users per team, 2 tasks per user, 1 manager per team.
"""
teams = tasks[0]
employees = tasks[1]
managers = tasks[2]
task = tasks[3]
return teams, employees, managers, task
kobihk marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def filter_by_symbol(cls, priority_filter):
print(priority_filter)
return cls.objects.filter(priority=priority_filter)

def change_assignee(self, new_assignee):
self.assignee = new_assignee
orzionpour marked this conversation as resolved.
Show resolved Hide resolved


class Comment(models.Model):
appUser = models.ForeignKey(
Expand Down
12 changes: 12 additions & 0 deletions tasks/tests/test_change_assignee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from tasks.models import Task


@pytest.mark.django_db
class TestChangeTaskAssignee:
def test_change_task_assignee(self, test_db):
_, employees, _, _ = test_db
task = Task.objects.filter(assignee=employees[0]).first()
assert task is not None
task.change_assignee(employees[1])
assert task.assignee == employees[1]