Commit a9778683 authored by Ola Hermann Opheim's avatar Ola Hermann Opheim
Browse files

add tests: sort and edit project

parent 943431d3
......@@ -148,14 +148,119 @@ class SortingTest(unittest.TestCase):
def setUp(self):
self.client = Client()
self.sorting_category = ProjectCategory.objects.create(name='sorting_category')
self.user_a = User.objects.create_user(
username='aUser',
email='test@test.com',
password='top_secret'
)
self.user_b = User.objects.create_user(
username='bUser',
email='test@test.com',
password='top_secret'
)
self.user_c = User.objects.create_user(
username='cUser',
email='test@test.com',
password='top_secret'
)
Project.objects.all().delete()
self.project_a = Project.objects.create(
user=self.user_c.profile,
title='A Project',
description='',
category=self.sorting_category,
status='o'
)
self.project_c = Project.objects.create(
user=self.user_b.profile,
title='C Project',
description='',
category=self.sorting_category,
status='o'
)
self.project_b = Project.objects.create(
user=self.user_a.profile,
title='B Project',
description='',
category=self.sorting_category,
status='o'
)
self.project_a_task = Task.objects.create(
project=self.project_a,
title='Test task 1',
description='',
budget=20,
status='ad',
feedback=''
)
self.project_b_task = Task.objects.create(
project=self.project_b,
title='Test task 1',
description='',
budget=20,
status='ad',
feedback=''
)
self.project_c_task = Task.objects.create(
project=self.project_c,
title='Test task 1',
description='',
budget=20,
status='ad',
feedback=''
)
def test_error_free_sorting(self):
# Test sorting by title ASC
response = self.client.post('/projects/', {
'sort_form': '',
'sort_by': 't',
})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['projects'][0], self.project_a)
self.assertEqual(response.context['projects'][1], self.project_b)
self.assertEqual(response.context['projects'][2], self.project_c)
# Test sorting by title DESC
response = self.client.post('/projects/', {
'sort_form': '',
'sort_by': '!t',
})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['projects'][0], self.project_c)
self.assertEqual(response.context['projects'][1], self.project_b)
self.assertEqual(response.context['projects'][2], self.project_a)
# Test sorting by owner username ASC
response = self.client.post('/projects/', {
'sort_form': '',
'sort_by': 'o',
})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['projects'][0], self.project_b)
self.assertEqual(response.context['projects'][1], self.project_c)
self.assertEqual(response.context['projects'][2], self.project_a)
#TODO: possibly add more: context test of projects
# Test sorting by owner username DESC
response = self.client.post('/projects/', {
'sort_form': '',
'sort_by': '!o',
})
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['projects'][0], self.project_a)
self.assertEqual(response.context['projects'][1], self.project_c)
self.assertEqual(response.context['projects'][2], self.project_b)
class ProjectOfferTest(unittest.TestCase):
def setUp(self):
......@@ -173,12 +278,10 @@ class ProjectOfferTest(unittest.TestCase):
#TODO
self.assertTrue(True)
class EditProjectTest(unittest.TestCase):
def setUp(self):
self.client = Client()
def test_edit_project_and_tasks(self):
self.edit_project_category = ProjectCategory.objects.create(name='edit_project_category')
self.project_owner = User.objects.create_user(
......@@ -213,14 +316,16 @@ class EditProjectTest(unittest.TestCase):
feedback=''
)
# Test project exists
def test_edit_project_and_tasks(self):
# Test project pre edit
self.client.login(username= 'ProjectOwner', password= 'top_secret')
response = self.client.get('/projects/' + str(Project.objects.last().pk) + '/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['project'], self.edit_project_test_project)
# Test edit project description
# Test project post edit
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_project': True,
})
......@@ -228,17 +333,17 @@ class EditProjectTest(unittest.TestCase):
'edit_project': True,
'project_description': 'edited',
f'task{self.edit_project_test_task1.id}_budget': '40',
f'task{self.edit_project_test_task1.id}_description': 'edited task',
f'task{self.edit_project_test_task2.id}_budget': '40',
f'task{self.edit_project_test_task2.id}_description': 'edited task',
f'task{self.edit_project_test_task1.id}_description': 'edited task1',
f'task{self.edit_project_test_task2.id}_budget': '50',
f'task{self.edit_project_test_task2.id}_description': 'edited task2',
})
#self.assertEqual(response.context['project'].description, 'edited')
def test_edit_project_tasks_description(self):
#TODO
self.assertTrue(True)
response = self.client.get('/projects/' + str(Project.objects.last().pk) + '/')
def test_edit_project_tasks_budget(self):
#TODO
self.assertTrue(True)
\ No newline at end of file
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['project'].description, 'edited')
self.assertEqual(response.context['total_budget'], 90)
self.assertEqual(response.context['tasks'][0].description, 'edited task1')
self.assertEqual(response.context['tasks'][0].budget, 40)
self.assertEqual(response.context['tasks'][1].description, 'edited task2')
self.assertEqual(response.context['tasks'][1].budget, 50)
\ No newline at end of file
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