Skip to content

Commit

Permalink
add tests for Project.AP(); fix #152
Browse files Browse the repository at this point in the history
  • Loading branch information
edbennett committed Aug 13, 2019
1 parent 4058a7a commit 4d0b2f2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
4 changes: 2 additions & 2 deletions funding/fixtures/tests/attributions.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"attribution_ptr": 1,
"identifier": "scw0001",
"pi_email": "[email protected]",
"amount": 10000
"amount": 12000
}
},
{
Expand Down Expand Up @@ -65,4 +65,4 @@
"url": "https://cronfa.swansea.ac.uk/publication2"
}
}
]
]
6 changes: 5 additions & 1 deletion institution/fixtures/tests/institutions.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"needs_user_approval": true,
"needs_funding_workflow": false,
"needs_funding_approval": false,
"logo_path": "/static/img/example-logo.png"
"logo_path": "/static/img/example-logo.png",
"AP_base": 50000,
"AP_per_publication": 10000,
"AP_per_CPU_hour": 1,
"AP_per_GPU_hour": 40
}
},
{
Expand Down
3 changes: 0 additions & 3 deletions priority/tests.py

This file was deleted.

Empty file added priority/tests/__init__.py
Empty file.
51 changes: 51 additions & 0 deletions priority/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from django.test import TestCase
from django.urls import reverse

from project.models import Project
from funding.models import Attribution, FundingBody, FundingSource, Publication
from institution.models import Institution
from users.models import CustomUser


class PriorityTests(TestCase):
fixtures = [
'institution/fixtures/tests/institutions.json',
'users/fixtures/tests/users.json',
'funding/fixtures/tests/funding_bodies.json',
'funding/fixtures/tests/attributions.json',
'project/fixtures/tests/categories.json',
'project/fixtures/tests/projects.json',
'project/fixtures/tests/memberships.json',
]


class Priority_ProjectModelTests(PriorityTests):
def setUp(self):
self.project = Project.objects.get(code='scw0000')
self.publication = Attribution.objects.get(title='Test publication')
self.fundingsource = self.project.attributions.get().child
self.tech_lead = self.project.tech_lead
self.institution = self.tech_lead.profile.institution

def test_AP_with_no_funding_approval(self):
self.assertEqual(self.project.AP(), 62000)

def test_AP_with_unapproved_funding(self):
self.institution.needs_funding_approval = True
self.assertEqual(self.project.AP(), 50000)

def test_AP_with_approved_funding(self):
self.institution.needs_funding_approval = True
self.fundingsource.approved = True
self.fundingsource.amount = 15000
self.fundingsource.save()
self.assertEqual(self.project.AP(), 65000)

def test_AP_with_publication(self):
self.fundingsource.delete()
self.project.attributions.add(self.publication)
self.assertEqual(self.project.AP(), 60000)

def test_AP_with_publication_and_fundingsource(self):
self.project.attributions.add(self.publication)
self.assertEqual(self.project.AP(), 72000)

0 comments on commit 4d0b2f2

Please sign in to comment.