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

project view statement test refac

parent 90982abe
......@@ -26,4 +26,4 @@ class PaymentRegressionTest(unittest.TestCase):
self.assertEquals(task_payment.payer, User.objects.get(username="User1").profile)
self.assertEquals(task_payment.receiver, User.objects.get(username="User2").profile)
self.assertEquals(Task.objects.get(title="Task2").status, 'ps')
self.assertTrue(('/payment/1/2/receipt/', 302) in response.redirect_chain)
self.assertTrue((f'/payment/{project.pk}/{task.id}/receipt/', 302) in response.redirect_chain)
......@@ -23,9 +23,9 @@ class NewProjectRegressionTest(unittest.TestCase):
def test_views_new_project(self):
self.client.login(username= 'User', password= 'top_secret')
response = self.client.post('/projects/new/', self.request_data)
response = self.client.post('/projects/new/', self.request_data, follow=True)
new_project_id = int(response.url.split("/")[2])
new_project_id = int(response.redirect_chain[0][0].split("/")[2])
new_project = Project.objects.get(pk=new_project_id)
self.assertEquals(new_project.user.user, self.user)
self.assertEquals(new_project.category.name, "Category")
......
import unittest
from django.test import Client
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 test_helpers import create_test_user, delete_test_data, create_multiple_test_data
class ProjectViewStatementTest(unittest.TestCase):
def setUp(self):
self.client = Client()
create_multiple_test_data()
self.project_id = Project.objects.get(title="Project2").pk
def tearDown(self):
delete_test_data()
def test_get(self):
self.client.get(f'/projects/{self.project_id}/')
def test_post_offer_response(self):
task_offer = TaskOffer.objects.get(title="TaskOffer4")
self.client.login(username= 'User2', password= 'top_secret')
self.client.post(f'/projects/{self.project_id}/', {
'offer_response': True,
'taskofferid': task_offer.id,
'status': 'a',
'feedback': 'Feedback',
})
def test_post_edit_project(self):
test_task1 = Task.objects.get(title="Task3")
test_task2 = Task.objects.get(title="Task4")
self.client.login(username= 'User2', password= 'top_secret')
self.client.post(f'/projects/{self.project_id}/', {
'edit_project': True,
'project_description': 'Edited',
f'task{test_task1.id}_budget': '100',
f'task{test_task1.id}_description': 'Edited',
f'task{test_task2.id}_budget': '20',
f'task{test_task2.id}_description': 'Edited',
})
def test_post_status_change(self):
self.client.login(username= 'User2', password= 'top_secret')
self.client.post(f'/projects/{self.project_id}/', {
'status_change': True,
'status': 'o',
})
def test_post_offer_submit(self):
test_task = Task.objects.get(title="Task4")
self.client.login(username= 'User1', password= 'top_secret')
self.client.post(f'/projects/{self.project_id}/', {
'offer_submit': True,
'title': 'TaskOffer5',
'description': 'Offer description',
'price': 567,
'taskvalue': test_task.id
})
def test_post_edit_offer(self):
task_offer = TaskOffer.objects.get(title="TaskOffer3")
self.client.login(username= 'User1', password= 'top_secret')
self.client.post(f'/projects/{self.project_id}/', {
'edit_offer': True,
'offer_id': task_offer.id,
'offer_description': 'Edited',
'offer_price': '30',
})
......@@ -9,100 +9,6 @@ from projects.forms import ProjectStatusForm, TaskOfferResponseForm
from projects.views import get_user_task_permissions
# Task 2 - I
class ProjectStatementTest(unittest.TestCase):
def setUp(self):
self.client = Client()
def test_project_view(self):
self.userOwner = User.objects.create_user(
username='Owner',
email='test@test.com',
password='top_secret'
)
self.userNormal = User.objects.create_user(
username='Normal',
email='test2@test.com',
password='top_secret'
)
self.testCategory = ProjectCategory.objects.create(name='test')
self.testProject = Project.objects.create(
user=self.userOwner.profile,
title="Test prosjekt",
description='',
category=self.testCategory,
status='o'
)
self.testTask = Task.objects.create(
project=self.testProject,
title='Test task',
description='',
budget=20,
status='ad',
feedback=''
)
self.edit_offer_test_offer = TaskOffer.objects.create(
task=self.testTask,
title='Test offer 1',
description='original',
price=20,
offerer=self.userNormal.profile,
edit=True
)
# Test project_view GET route
self.client.get('/projects/' + str(Project.objects.last().pk) + '/')
# Test project_view POST route submit project
self.client.login(username= 'Normal', password= 'top_secret')
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_submit': True,
'title': 'offer title',
'description': 'test offer',
'price': 567,
'taskvalue': self.testTask.id,
})
# Test project_view POST route edit offer
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_offer': '',
'offer_id': self.edit_offer_test_offer.id,
'offer_description': 'edited',
'offer_price': '30',
})
# Test project_view POST route offer response
self.client.login(username= 'Owner', password= 'top_secret')
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'offer_response': True,
'taskofferid': self.edit_offer_test_offer.id,
'status': 'a',
'feedback': 'ja',
})
# Test project_view POST route edit project
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_project': True,
})
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'edit_project': True,
'project_description': 'edited',
f'task{self.testTask.id}_budget': '100',
f'task{self.testTask.id}_description': 'edited',
})
# Test project_view POST route status change
self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
'status_change': True,
'status': 'o',
})
# Task 2 - II
class UserTaskPermissionStatementTest(unittest.TestCase):
......
......@@ -67,7 +67,6 @@ def project_view(request, project_id):
offer_response.save()
offer_response_form = TaskOfferResponseForm()
if request.method == 'POST' and 'edit_project' in request.POST:
edit_project_form = EditProjectForm(request.POST)
if edit_project_form.is_valid() and project.status == 'o':
......
......@@ -100,7 +100,8 @@ def create_multiple_test_data():
title="Project2",
description='',
category=test_category_2,
status='o'
status='o',
edit=True
)
test_task_1 = Task.objects.create(
......@@ -157,6 +158,7 @@ def create_multiple_test_data():
description='',
price=20,
offerer=test_user_1.profile,
edit=True
)
test_taskoffer_4 = TaskOffer.objects.create(
task=test_task_4,
......@@ -164,7 +166,6 @@ def create_multiple_test_data():
description='',
price=20,
offerer=test_user_1.profile,
status='a'
)
def delete_test_data():
......
"""
import unittest
from django.test import Client
from django.contrib.auth.models import User
from projects.templatetags.project_extras import get_all_taskoffers
#TODO: from projects.templatetags.project_extras import get_all_taskoffers
from projects.models import Project, ProjectCategory, Task
from test_helpers import delete_test_data
......@@ -112,7 +113,7 @@ class SignUpBoundaryTest(unittest.TestCase):
self.test_data['last_name'] = chars_30 + "A"
self.client.post('/user/signup/', self.test_data)
self.assertEqual(User.objects.count(), 2)
"""
def test_categories_boundaries(self):
# no categories
self.test_data['username'] = "A"
......
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