Commit 7204f563 authored by Ola Hermann Opheim's avatar Ola Hermann Opheim
Browse files

payment code review

parent 1618bb1f
import unittest
from django.test import Client
from test_helpers import create_test_user, delete_test_data, create_multiple_test_data
from test_helpers import create_test_user, delete_test_data
class HomeViewRegressionTest(unittest.TestCase):
def setUp(self):
......
from django.test import TestCase
import unittest
from django.test import Client
from django.contrib.auth.models import User
# Create your tests here.
from projects.models import Project, Task
from payment.models import Payment
from test_helpers import delete_test_data, create_multiple_test_data
class PaymentRegressionTest(unittest.TestCase):
def setUp(self):
self.client = Client()
create_multiple_test_data()
def tearDown(self):
delete_test_data()
def test_payment_output(self):
project = Project.objects.get(title="Project1")
task = Task.objects.get(title="Task2")
self.client.login(username= 'User1', password= 'top_secret')
response = self.client.post(f'/payment/{project.pk}/{task.id}', follow=True)
task_payment = Payment.objects.get(task=task)
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)
......@@ -2,7 +2,7 @@
from django.shortcuts import render, redirect
from .models import Payment
from projects.models import Project, Task, TaskOffer
from projects.models import Project, Task
from projects.templatetags.project_extras import get_accepted_task_offer
from .forms import PaymentForm
from django.contrib.auth.decorators import login_required
......@@ -10,11 +10,11 @@ from django.contrib.auth.decorators import login_required
@login_required
def payment(request, project_id, task_id):
task = Task.objects.get(pk=task_id)
sender = Project.objects.get(pk=project_id).user
receiver = get_accepted_task_offer(task).offerer
if request.method == 'POST':
task = Task.objects.get(pk=task_id)
sender = Project.objects.get(pk=project_id).user
receiver = get_accepted_task_offer(task).offerer
payment = Payment(payer=sender, receiver=receiver, task=task)
payment.save()
task.status = Task.PAYMENT_SENT # Set task status to payment sent
......@@ -23,7 +23,6 @@ def payment(request, project_id, task_id):
return redirect('receipt', project_id=project_id, task_id=task_id)
form = PaymentForm()
return render(request,
'payment/payment.html', {
'form': form,
......
......@@ -2,6 +2,7 @@
from django.contrib.auth.models import User
from projects.models import Project, ProjectCategory, Task, TaskOffer
from payment.models import Payment
def create_test_user():
User.objects.create_user(
......@@ -124,7 +125,10 @@ def create_multiple_test_data():
def delete_test_data():
User.objects.all().delete()
ProjectCategory.objects.all().delete()
Project.objects.all().delete()
Task.objects.all().delete()
TaskOffer.objects.all().delete()
Payment.objects.all().delete()
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