Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
Unbreak unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ropable committed Jul 14, 2017
1 parent 2baeac8 commit 6c4e5bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
22 changes: 17 additions & 5 deletions oim_cms/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ApiTestCase(TestCase):

def setUp(self):
# Generate some other DepartmentUser objects.
mixer.cycle(6).blend(
mixer.cycle(8).blend(
DepartmentUser, photo=None, active=True,
email=random_dpaw_email, org_unit=None,
cost_centre=None, ad_guid=uuid1, o365_licence=False, in_sync=False)
Expand All @@ -31,16 +31,20 @@ def setUp(self):
self.loc2 = mixer.blend(Location, manager=None)
# Generate a basic org structure.
# NOTE: don't use mixer to create OrgUnit objects (it breaks MPTT).
self.dept = OrgUnit.objects.create(name='Department 1', unit_type=0, acronym='DEPT')
self.dept = OrgUnit.objects.create(name='Department 1', unit_type=0, acronym='DEPT', active=True)
self.div1 = OrgUnit.objects.create(
name='Divison 1', unit_type=1, parent=self.dept, location=self.loc1, acronym='D1')
name='Divison 1', unit_type=1, parent=self.dept, location=self.loc1, acronym='DIV1', active=True)
self.branch1 = OrgUnit.objects.create(
name='Branch 1', unit_type=2, parent=self.div1, location=self.loc1, acronym='BRANCH1', active=True)
self.cc1 = CostCentre.objects.create(
name='Cost centre 1', code='001', division=self.div1, org_position=self.div1)
self.div2 = OrgUnit.objects.create(
name='Divison 2', unit_type=1, parent=self.dept, location=self.loc2, acronym='D2')
name='Divison 2', unit_type=1, parent=self.dept, location=self.loc2, acronym='DIV2', active=True)
self.branch2 = OrgUnit.objects.create(
name='Branch 2', unit_type=2, parent=self.div2, location=self.loc2, acronym='BRANCH2', active=True)
self.cc2 = CostCentre.objects.create(
name='Cost centre 2', code='002', division=self.div2, org_position=self.div2)
# Give each of the divisions some members.
# Give each of the org units some members.
users = DepartmentUser.objects.all()
self.user1 = users[0]
self.user1.org_unit = self.div1
Expand All @@ -54,6 +58,14 @@ def setUp(self):
self.user2.save()
self.div2.manager = self.user2
self.div2.save()
self.user3 = users[2]
self.user3.org_unit = self.branch1
self.user3.cost_centre = self.cc1
self.user3.save()
self.user4 = users[3]
self.user4.org_unit = self.branch2
self.user4.cost_centre = self.cc2
self.user4.save()
# Mark a user as inactive and deleted in AD.
self.del_user = users[2]
self.del_user.active = False
Expand Down
9 changes: 4 additions & 5 deletions organisation/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ def test_data_org_structure(self):
# Deserialised response contains a list.
self.assertTrue(isinstance(r['objects'], list))
# Make OrgUnit inactive to test exclusion.
self.div1.active = False
self.div1.save()
self.branch1.active = False
self.branch1.save()
response = self.client.get(url)
# FIXME: this is busted.
#self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, 200)
# Division 1 won't be present in the response.
#self.assertNotContains(response, self.div1.name)
self.assertNotContains(response, self.branch1.name)

def test_data_cost_centre(self):
"""Test the data_cost_centre API endpoint
Expand Down

0 comments on commit 6c4e5bf

Please sign in to comment.