Commit 45763c91 authored by Ola Hermann Opheim's avatar Ola Hermann Opheim
Browse files

added output test on accepting offer

parent 47e7c475
......@@ -4,10 +4,12 @@ from django.contrib.auth.models import User
from projects.templatetags.project_extras import get_all_taskoffers
from projects.models import Project, ProjectCategory, Task, TaskOffer
from projects.forms import ProjectStatusForm, TaskOfferResponseForm
from projects.views import get_user_task_permissions
class ProjectTest(unittest.TestCase):
# Task 2 - I
class ProjectStatementTest(unittest.TestCase):
def setUp(self):
self.client = Client()
......@@ -100,7 +102,9 @@ class ProjectTest(unittest.TestCase):
'status': 'o',
})
class UserTaskPermissionTest(unittest.TestCase):
# Task 2 - II
class UserTaskPermissionStatementTest(unittest.TestCase):
def setUp(self):
self.client = Client()
......@@ -135,6 +139,14 @@ class UserTaskPermissionTest(unittest.TestCase):
feedback=''
)
self.test_permission_offer = TaskOffer.objects.create(
task=self.testTask2,
title='Test offer 2',
description='original',
price=20,
offerer=self.userHired.profile,
)
def test_get_user_task_permissions(self):
# Test route of project owner
get_user_task_permissions(self.userOwner2, self.testTask2)
......@@ -143,23 +155,104 @@ class UserTaskPermissionTest(unittest.TestCase):
get_user_task_permissions(self.userHired, self.testTask2)
# Test route of user hired to do the task
self.client.login(username= 'Hired', password= 'top_secret')
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_submit': True,
'title': 'heititle',
'description': 'ja',
'price': 123,
'taskvalue': Project.objects.last().pk,
})
self.client.login(username= 'Owner2', password= 'top_secret')
response = self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_response': True,
'taskofferid': 0,
'taskofferid': self.test_permission_offer.id,
'status': 'a',
'feedback': 'ja',
})
get_user_task_permissions(self.userHired, self.testTask2)
get_user_task_permissions(self.userHired, response.context['tasks'][0])
# Task 3 - II
class AcceptingOfferOutputTest(unittest.TestCase):
def setUp(self):
self.client = Client()
def test_project_view(self):
self.userAccepter = User.objects.create_user(
username='Accepter',
email='test@test.com',
password='top_secret'
)
self.userOfferer = User.objects.create_user(
username='Offerer3',
email='test@test.com',
password='top_secret'
)
self.testCategory = ProjectCategory.objects.create(name='accept_category')
self.testAcceptProject = Project.objects.create(
user=self.userAccepter.profile,
title="Test prosjekt",
description='',
category=self.testCategory,
status='o'
)
self.testAcceptTask = Task.objects.create(
project=self.testAcceptProject,
title='Test task',
description='',
budget=20,
status='ad',
feedback=''
)
self.accepting_offer_test_offer = TaskOffer.objects.create(
task=self.testAcceptTask,
title='Test offer 1',
description='original',
price=20,
offerer=self.userOfferer.profile,
)
# Test output on POST route offer_response with accepting
self.client.login(username= 'Accepter', password= 'top_secret')
response = self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_response': True,
'taskofferid': self.accepting_offer_test_offer.id,
'status': 'a',
'feedback': 'ja',
})
# Checks output project relevant data
project = response.context['project']
self.assertEqual(project, self.testAcceptProject)
self.assertTrue(self.userOfferer.profile in project.participants.all())
# TODO: fix in code if this is the error
# self.assertEqual(project.status, 'i')
# Checks output task relevant data
task = Task.objects.get(id=self.testAcceptTask.id)
self.assertEqual(response.context['tasks'][0], self.testAcceptTask)
self.assertEqual(task.accepted_task_offer(), self.accepting_offer_test_offer)
self.assertTrue(self.userOfferer.profile in task.read.all())
self.assertTrue(self.userOfferer.profile in task.write.all())
self.assertFalse(self.userOfferer.profile in task.modify.all())
# Checks output offer relevant data
offer = TaskOffer.objects.get(id=self.accepting_offer_test_offer.id)
self.assertEqual(offer, self.accepting_offer_test_offer)
self.assertEqual(offer.status, 'a')
self.assertEqual(offer.feedback, 'ja')
# Checks other output data
self.assertEqual(response.context['total_budget'], 20)
self.assertIsNotNone(response.context['status_form'])
self.assertIsNotNone(response.context['offer_response_form'])
# Task 3 - IV
class SortingTest(unittest.TestCase):
def setUp(self):
self.client = Client()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment