Skip to content

Commit

Permalink
Merge branch 'main' into task-change-assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
orzionpour committed Nov 27, 2021
2 parents 4bca4f8 + abfa428 commit 4cce8ad
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tasks/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('title', models.CharField(max_length=200, blank=False, default=None)),
('created_date', models.DateTimeField(auto_now_add=True)),
('description', models.TextField(blank=True, null=True)),
],
Expand All @@ -27,7 +27,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('title', models.CharField(max_length=200, blank=False, default=None)),
('created_date', models.DateTimeField(auto_now_add=True)),
('priority', enumchoicefield.fields.EnumChoiceField(default=tasks.models.Priority.LOW,
enum_class=tasks.models.Priority,
Expand Down
4 changes: 2 additions & 2 deletions tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Priority(ChoiceEnum):


class Task(models.Model):
title = models.CharField(max_length=200)
title = models.CharField(max_length=200, blank=False, default=None)
created_date = models.DateTimeField(auto_now_add=True)
assignee = models.ForeignKey(
User, on_delete=models.RESTRICT, related_name='assigneeTasks')
Expand Down Expand Up @@ -67,7 +67,7 @@ class Comment(models.Model):
User, on_delete=models.RESTRICT, related_name='appUser')
task = models.ForeignKey(
Task, on_delete=models.CASCADE, related_name='task')
title = models.CharField(max_length=200)
title = models.CharField(max_length=200, blank=False, default=None)
created_date = models.DateTimeField(auto_now_add=True)
description = models.TextField(null=True, blank=True)

Expand Down
71 changes: 69 additions & 2 deletions tasks/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
# from django.test import TestCase
from tasks.models import Comment, Status, Priority, Task
import pytest
from users.models import Role, User, Team

# Create your tests here.

@pytest.mark.django_db
class TestComments:

@pytest.fixture
def team_1(self):
return Team.objects.create(name="Team1", description="Best team ever")

@pytest.fixture
def employee_1(self, team_1):
user = User.create_user(
username="employee1",
email="user1@redhat.com",
password="password",
first_name="first_name",
last_name="last_name",
role=Role.EMPLOYEE,
team=team_1)
return user

@pytest.fixture
def manager_1(self, team_1):
user = User.create_user(
username="manager1",
email="user1@redhat.com",
password="password",
first_name="first_name",
last_name="last_name",
role=Role.MANAGER,
team=team_1)
return user

@pytest.fixture
def task_1(self, employee_1, manager_1):
task = Task.objects.create(title="new house",
assignee=employee_1,
created_by=manager_1,
priority=Priority.HIGH,
status=Status.IN_PROGRESS,
description="build me a house")
return task

@pytest.fixture
def comment_1(self, task_1, employee_1):
comment = Comment.objects.create(appUser=employee_1,
task=task_1,
title="A problem",
description="I dont know how")
return comment

def test_create_comment(self, comment_1):
assert isinstance(comment_1, Comment)
assert Comment.objects.filter(id=comment_1.id).exists()

def test_user_make_two_comments(self, task_1, employee_1, comment_1):
com = Comment.objects.create(appUser=employee_1,
title="A problem2",
task=task_1,
description="Need more info")
assert com.id != comment_1.id

def test_comment_without_title(self, task_1, employee_1):
with pytest.raises(Exception):
Comment.objects.create(appUser=employee_1,
task=task_1,
description="Need more info")
3 changes: 2 additions & 1 deletion users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('name', models.CharField(max_length=255,
blank=False, default=None)),
('description', models.CharField(max_length=500)),
],
),
Expand Down
10 changes: 8 additions & 2 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Role(ChoiceEnum):

# Create your models here.
class Team(models.Model):
name = models.CharField(max_length=255)
name = models.CharField(max_length=255, blank=False, default=None)
description = models.CharField(max_length=500)

def __str__(self) -> str:
Expand All @@ -32,7 +32,7 @@ def create_user(username, email, password, first_name, last_name, role, team):
password=password,
first_name=first_name,
last_name=last_name)
if(isinstance(django_user, DjangoUser)):
if isinstance(django_user, DjangoUser):
user = User.objects.create(user=django_user,
role=role,
team=team)
Expand All @@ -45,3 +45,9 @@ def delete(self, *args, **kwargs):

def __str__(self) -> str:
return self.user.username

def is_employee(self):
return self.role == Role.EMPLOYEE

def is_manager(self):
return self.role == Role.MANAGER
28 changes: 27 additions & 1 deletion users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_create_teams(self, valid_teams):

def test_create_team_without_title(self):
with pytest.raises(Exception):
Team.objects.create('', "Best team ever")
Team.objects.create(description="Best team ever")


@pytest.mark.django_db
Expand Down Expand Up @@ -78,3 +78,29 @@ def test_create_user_with_long_name(self):
last_name="last_name",
role=Role.EMPLOYEE,
team=TestTeams.valid_team)

@pytest.fixture
def example_team(self):
team = Team.objects.create(name='a', description='b')
return team

@pytest.fixture
def example_user_employee(self, example_team):
user = User.create_user('a', 'a@a.com', 'aaa', 'a', 'z', Role.EMPLOYEE, example_team)
return user

@pytest.fixture
def example_user_manager(self, example_team):
user = User.create_user('m', 'm@m.com', 'mmm', 'm', 'z', Role.MANAGER, example_team)
user.save()
return user

@pytest.mark.django_db
def test_check_is_employee(self, example_user_employee, example_user_manager):
assert User.is_employee(example_user_employee) is True
assert User.is_employee(example_user_manager) is False

@pytest.mark.django_db
def test_check_is_manager(self, example_user_employee, example_user_manager):
assert User.is_manager(example_user_employee) is False
assert User.is_manager(example_user_manager) is True

0 comments on commit 4cce8ad

Please sign in to comment.