tests.py 23.9 KB
Newer Older
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
1
2
3
import unittest
from django.test import Client
from django.contrib.auth.models import User
Andreas Berger's avatar
Andreas Berger committed
4

Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
5
from projects.templatetags.project_extras import get_all_taskoffers
6
from projects.models import Project, ProjectCategory, Task, TaskOffer
7
from projects.forms import ProjectStatusForm, TaskOfferResponseForm
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
8
9
10

from projects.views import get_user_task_permissions

11
12
# Task 2 - I
class ProjectStatementTest(unittest.TestCase):
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
13
14
    def setUp(self):
        self.client = Client()
15
16
17

    def test_project_view(self):

Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
18
19
20
21
22
        self.userOwner = User.objects.create_user(
            username='Owner',
            email='test@test.com',
            password='top_secret'
        )
23
         
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
24
25
26
27
28
        self.userNormal = User.objects.create_user(
            username='Normal',
            email='test2@test.com',
            password='top_secret'
        )
29
        
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
        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=''
        )

Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
49
50
51
52
53
54
55
56
57
        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
        )

Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
58
59
60
61
62
        # 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')
63
        self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
64
            'offer_submit': True, 
65
66
67
68
            'title': 'offer title',
            'description': 'test offer',
            'price': 567,
            'taskvalue': self.testTask.id,
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
69
70
        })

71
72
73
        # Test project_view POST route edit offer
        self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
            'edit_offer': '', 
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
74
            'offer_id': self.edit_offer_test_offer.id,
75
            'offer_description': 'edited',
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
76
            'offer_price': '30',
77
78
        })
        
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
79
80
81
82
        # 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, 
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
83
            'taskofferid': self.edit_offer_test_offer.id,
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
84
85
86
            'status': 'a',
            'feedback': 'ja',
        })
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
87
        
88
89
90
91
92
93
94
95
96
97
        # 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',
        })
98

Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
99
100
101
102
        # Test project_view POST route status change
        self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
            'status_change': True,
            'status': 'o',
103
104
        })   

105
106
107

# Task 2 - II
class UserTaskPermissionStatementTest(unittest.TestCase):
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    def setUp(self):
        self.client = Client()

        self.userOwner2 = User.objects.create_user(
            username='Owner2',
            email='test@test.com',
            password='top_secret'
        )

        self.userHired = User.objects.create_user(
            username='Hired',
            email='test2@test.com',
            password='top_secret'
        )

        self.testCategory = ProjectCategory.objects.create(name='test2')
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
124

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
        self.testProject2 = Project.objects.create(
            user=self.userOwner2.profile,
            title="Test prosjekt",
            description='',
            category=self.testCategory,
            status='o'
        )

        self.testTask2 = Task.objects.create(
            project=self.testProject2,
            title='Test task',
            description='',
            budget=20,
            status='ad',
            feedback=''
        )

142
143
144
145
146
147
148
149
        self.test_permission_offer = TaskOffer.objects.create(
            task=self.testTask2,
            title='Test offer 2',
            description='original',
            price=20,
            offerer=self.userHired.profile,
        )

150
    def test_get_user_task_permissions(self):
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
151
        # Test route of project owner
152
        get_user_task_permissions(self.userOwner2, self.testTask2)
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
153
154

        # Test route of user unrelated to task
155
        get_user_task_permissions(self.userHired, self.testTask2)
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
156
157

        # Test route of user hired to do the task
158
        self.client.login(username= 'Owner2', password= 'top_secret')
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
159
160
        response = self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
            'offer_response': True, 
161
            'taskofferid': self.test_permission_offer.id,
Ola Hermann Opheim's avatar
task 2    
Ola Hermann Opheim committed
162
163
164
            'status': 'a',
            'feedback': 'ja',
        })
165
        get_user_task_permissions(self.userHired, response.context['tasks'][0])   
166
             
167

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Task 3 - I
class GiveTaskOfferBoundaryTest(unittest.TestCase):
    def setUp(self):
        self.client = Client()

        self.testCategory = ProjectCategory.objects.create(name='test1')

    def test_boundary_give_offer(self):

        self.userBoundaryOwner = User.objects.create_user(
            username='BoundOw',
            email='test@test.com',
            password='top_secret'
        )
         
        self.userBoundaryOfferer = User.objects.create_user(
            username='BoundOff',
            email='test@test.com',
            password='top_secret'
        )
        
        self.testBoundaryProject = Project.objects.create(
            user=self.userBoundaryOwner.profile,
            title="Test project",
            description='',
            category=self.testCategory,
            status='o'
        )

        self.testBoundaryTask = Task.objects.create(
            project=self.testBoundaryProject,
            title='Test task',
            description='',
            budget=20,
            status='ad',
            feedback=''
        )
    
        title_200char = "NNEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue"
        des_500char = "NNEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPGWwOaXChNueq2bq12qrlS6S0YPHkku3JsfYo2BPWOhkNNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueNNEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNueq2bq12qrlS6S0YPkku3JsfYo2BPWOhkNFRLRGi2KoOtEcOLJyGWwOaXChNue"

        self.client.login(username= 'BoundOff', password= 'top_secret') 

        # Test title boundary values by check if list of offers extends
        # title 0 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': "",
            'description': 'max 500',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers)

        # title 1 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': "A",
            'description': 'max 500',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # title 199 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
237
            'title': title_200char[:-1],
238
239
240
241
242
243
244
245
246
247
            'description': 'max 500',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # title 200 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
248
            'title': title_200char,
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
            'description': 'max 500',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # title 201 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': (title_200char + "A"),
            'description': 'max 500',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers)


        # Test description boundary values by check if list of offers extends
        # description 0 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': '',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers)

        # description 1 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': 'A',
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # description 499 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': des_500char[:-1],
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # description 500 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': des_500char,
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # description 501 chars
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': des_500char + "A",
            'price': 123, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers)


        # Test price boundary values by check if list of offers extends
        # price -1
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': 'description',
            'price': -1, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
335
        # self.assertEqual(TaskOffer.objects.count(), nr_of_offers)
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359

        # price 0
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': 'description',
            'price': 0, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)

        # price 1
        nr_of_offers = TaskOffer.objects.count()
        self.client.post(f'/projects/{self.testBoundaryProject.pk}/', {
            'title': 'title',
            'description': 'description',
            'price': 1, 
            'taskvalue': self.testBoundaryTask.id, 
            'offer_submit': True
        })
        self.assertEqual(TaskOffer.objects.count(), nr_of_offers+1)


360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# 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())
        # 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
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
442
443
444
445
class SortingTest(unittest.TestCase):
    def setUp(self):
        self.client = Client()

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
        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=''
        )

518
    def test_error_free_sorting(self):
519
520
521
522
523
524
525
526
527
528
529
530

        # 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
531
532
533
534
535
        response = self.client.post('/projects/', {
            'sort_form': '',
            'sort_by': '!t',
        })
        self.assertEqual(response.status_code, 200)
536
537
538
539
540
541
542
543
544
545
546
547
548
        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)
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
549

550
551
552
553
554
555
556
557
558
        # 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)
559

560
class EditTaskOfferTest(unittest.TestCase):
561
562
563
    def setUp(self):
        self.client = Client()

564
        self.edit_offer_category = ProjectCategory.objects.create(name='edit_offer_category')
565

566
567
568
569
570
        self.project_owner = User.objects.create_user(
            username='POwner',
            email='test@test.com',
            password='top_secret'
        )
571

572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
        self.offerer = User.objects.create_user(
            username='Offerer',
            email='test@test.com',
            password='top_secret'
        )

        self.edit_offer_test_project = Project.objects.create(
            user=self.project_owner.profile,
            title='Edit offer test project',
            description='',
            category=self.edit_offer_category,
            status='o'
        )

        self.edit_offer_test_task = Task.objects.create(
            project=self.edit_offer_test_project,
            title='Test task 1',
            description='',
            budget=20,
            status='o',
            feedback=''
        )

        self.edit_offer_test_offer = TaskOffer.objects.create(
            task=self.edit_offer_test_task,
            title='Test offer 1',
            description='original',
            price=20,
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
600
601
            offerer=self.offerer.profile,
            edit=True
602
603
604
        )

    def test_edit_offer(self):
605

606
607
608
609
610
611
612
        # Test init
        self.assertEqual(self.edit_offer_test_offer.description, 'original')
        self.assertEqual(self.edit_offer_test_offer.price, 20)

        # Test edit
        self.client.login(username= 'Offerer', password= 'top_secret')        
        self.client.post('/projects/' + str(Project.objects.last().pk) + '/', {
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
613
614
            'edit_offer': '', 
            'offer_id': self.edit_offer_test_offer.id,
615
616
617
            'offer_description': 'edited',
            'offer_price': 30,
        })
Ola Hermann Opheim's avatar
Ola Hermann Opheim committed
618
619
620
621
        offer = TaskOffer.objects.get(id=self.edit_offer_test_offer.id)
        self.assertEqual(offer.description, 'edited')
        self.assertEqual(offer.price, 30)

622
623
624
625
class EditProjectTest(unittest.TestCase):
    def setUp(self):
        self.client = Client()

626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
        self.edit_project_category = ProjectCategory.objects.create(name='edit_project_category')

        self.project_owner = User.objects.create_user(
            username='ProjectOwner',
            email='test@test.com',
            password='top_secret'
        )

        self.edit_project_test_project = Project.objects.create(
            user=self.project_owner.profile,
            title='Edit project test project',
            description='',
            category=self.edit_project_category,
            status='o'
        )

        self.edit_project_test_task1 = Task.objects.create(
            project=self.edit_project_test_project,
            title='Test task 1',
            description='',
            budget=20,
            status='ad',
            feedback=''
        )

        self.edit_project_test_task2 = Task.objects.create(
            project=self.edit_project_test_project,
            title='Test task 2',
            description='',
            budget=30,
            status='ad',
            feedback=''
        )

660
661
662
    def test_edit_project_and_tasks(self):

        # Test project pre edit
663
664
665
666
667
668
        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)

669
        # Test project post edit
670
671
672
673
674
675
676
        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.edit_project_test_task1.id}_budget': '40',
677
678
679
            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',
680
        })
681
        response = self.client.get('/projects/' + str(Project.objects.last().pk) + '/')
682

683
684
685
686
687
688
689
        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)