Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Bug Fix 3 Merge (#28)
Browse files Browse the repository at this point in the history
* Added lines to prevent 'create patient' form submitting without a name

* Fixing linting error

* Fixing tests that used non-compliant patient names

* Linting Fixes

* Getting tests passing again

* Fixing issue where middle name would say False on form submission, this is due to the key middle_names being in the dictionary so the format is finding that and returning it

* Adding check to create to ensure that other or patient identifier are included

* Making sure reallocation filters for users only in the location id

* Adding unit tests for submit ward function

* Adding more tests (broken)

* Got deallocate test going

* Finishing Deallocate testing

* Cleaning up and adding submit_users tests

* Refactoring complete a little bit

* Making sure person completing form can't deallocate themselves from ward when assigning themselves to a bed

* Linting Fix

* Completing unit tests

* Linting Fixes

* Removing create and edit from nurse selection when picking nurses in allocation view

* Removing the create button from the select more popup for users

* Moving Staff Allocation Integration Testing up into nh_eobs due to weird issue with nh.clinical.patient.unfollow and EWS obs

* Adding logic to ensure that existing allocations on other wards are not removed when doing a nursing shift change

* Fixing tests to work with the new way of deallocating users

* Making sure the 'create meh' option doesn't popup when typing in a name that isn't in system

* Making sure the 'create meh' option doesn't popup when typing in a name that isn't in system

* F94 responsibility reallocation (#25)

* Starting to separate the functionality into superclass

* Initial unit testing around the _get_default_methods, the allocating one is currently broken

* Finally got get_default_allocatings unit tests working

* Starting to add unit tests around reallocate method

* Finishing unit testing around reallocate method

* Linting fixes

* Adding test for complete method

* Restoring reallocation tables as messed them up a bit

* Making sure that re-allocation is only affecting the ward in question

* Staff Reallocation Integration Tests - Linting

* F94 responsibility reallocation (#27)

* Starting to separate the functionality into superclass

* Initial unit testing around the _get_default_methods, the allocating one is currently broken

* Finally got get_default_allocatings unit tests working

* Starting to add unit tests around reallocate method

* Finishing unit testing around reallocate method

* Linting fixes

* Adding test for complete method

* Restoring reallocation tables as messed them up a bit

* Making sure that re-allocation is only affecting the ward in question

* Staff Reallocation Integration Tests - Linting

* Adding fix to bug found during testing

* Adding fix to bug found during testing

* Fixing test that now fails due to side effect of changes made
  • Loading branch information
colinfwren committed Jun 7, 2016
1 parent fedb62c commit 8f6ad45
Show file tree
Hide file tree
Showing 10 changed files with 927 additions and 168 deletions.
10 changes: 8 additions & 2 deletions nh_clinical/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
from . import test_staff_allocation_deallocate
from . import test_staff_allocation_submit_users
from . import test_staff_allocation_complete
from . import test_staff_allocation_unfollow
from . import test_staff_allocation_responsibility_allocation
from . import test_allocation_unfollow
from . import test_allocation_responsibility_allocation
from . import test_staff_reallocation_default_ward
from . import test_staff_reallocation_default_locations
from . import test_staff_reallocation_default_users
from . import test_staff_reallocation_default_allocatings
from . import test_staff_reallocation_reallocate
from . import test_staff_reallocation_complete
# from . import test_doctor
# from . import test_spell
# from . import test_auditing
Expand Down
67 changes: 67 additions & 0 deletions nh_clinical/tests/test_allocation_responsibility_allocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Part of NHClinical. See LICENSE file for full copyright and licensing details
# -*- coding: utf-8 -*-
from openerp.tests.common import SingleTransactionCase


class TestStaffAllocationResponsibilityAllocation(SingleTransactionCase):

EXPECTED_LOCATIONS = [128, 256, 512, 1024]

@classmethod
def setUpClass(cls):
super(TestStaffAllocationResponsibilityAllocation, cls).setUpClass()
cls.allocation_pool = cls.registry('nh.clinical.staff.allocation')
cls.activity_pool = cls.registry('nh.activity')
cls.resp_allocation_pool = \
cls.registry('nh.clinical.user.responsibility.allocation')

def setUp(self):
super(TestStaffAllocationResponsibilityAllocation, self).setUp()

def mock_resp_allo_create(*args, **kwargs):
context = kwargs.get('context')
if context and context == 'resp_allo_test_create':
global activity_data
activity_data = args[4]
return 1

def mock_activity_complete(*args, **kwargs):
context = kwargs.get('context')
if context and context == 'resp_allo_test_complete':
global completed_activities
completed_activities = args[3]
return True

self.resp_allocation_pool._patch_method('create_activity',
mock_resp_allo_create)
self.activity_pool._patch_method('complete', mock_activity_complete)

def tearDown(self):
super(TestStaffAllocationResponsibilityAllocation, self).tearDown()
self.resp_allocation_pool._revert_method('create_activity')
self.activity_pool._revert_method('complete')

def test_creates_activity_with_data(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS
"""
self.resp_calls = []
self.allocation_pool.responsibility_allocation_activity(
self.cr, self.uid, 64, self.EXPECTED_LOCATIONS,
context='resp_allo_test_create')
self.assertEqual(activity_data, {
'responsible_user_id': 64,
'location_ids': [[6, 0, self.EXPECTED_LOCATIONS]]
})

def test_completes_activity(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS
"""
self.resp_calls = []
self.allocation_pool.responsibility_allocation_activity(
self.cr, self.uid, 64, self.EXPECTED_LOCATIONS,
context='resp_allo_test_complete')
self.assertEqual(completed_activities, 1)
84 changes: 84 additions & 0 deletions nh_clinical/tests/test_allocation_unfollow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Part of NHClinical. See LICENSE file for full copyright and licensing details
# -*- coding: utf-8 -*-
from openerp.tests.common import SingleTransactionCase


class TestStaffAllocationUnfollow(SingleTransactionCase):

EXPECTED_PATIENTS = [128, 256, 512, 1024]

@classmethod
def setUpClass(cls):
super(TestStaffAllocationUnfollow, cls).setUpClass()
cls.allocation_pool = cls.registry('nh.clinical.staff.allocation')
cls.activity_pool = cls.registry('nh.activity')
cls.patient_pool = cls.registry('nh.clinical.patient')
cls.unfollow_pool = cls.registry('nh.clinical.patient.unfollow')

def setUp(self):
super(TestStaffAllocationUnfollow, self).setUp()

def mock_patient_search(*args, **kwargs):
context = kwargs.get('context')
if context and context == 'unfollow_test_search':
global search_location_ids
search_location_ids = args[3]
return self.EXPECTED_PATIENTS

def mock_unfollow_create(*args, **kwargs):
context = kwargs.get('context')
if context and context == 'unfollow_test_create':
global unfollow_patients
unfollow_patients = args[4]
return 1

def mock_activity_complete(*args, **kwargs):
context = kwargs.get('context')
if context and context == 'unfollow_test_complete':
global completed_activities
completed_activities = args[3]
return True

self.patient_pool._patch_method('search', mock_patient_search)
self.unfollow_pool._patch_method('create_activity',
mock_unfollow_create)
self.activity_pool._patch_method('complete', mock_activity_complete)

def tearDown(self):
super(TestStaffAllocationUnfollow, self).tearDown()
self.patient_pool._revert_method('search')
self.unfollow_pool._revert_method('create_activity')
self.activity_pool._revert_method('complete')

def test_passes_location_ids(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS
"""
self.resp_calls = []
self.allocation_pool.unfollow_patients_in_locations(
self.cr, self.uid, [64], context='unfollow_test_search')
self.assertEqual(search_location_ids, [
['current_location_id', 'in', [64]]])

def test_passes_patient_ids(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS
"""
self.resp_calls = []
self.allocation_pool.unfollow_patients_in_locations(
self.cr, self.uid, [64], context='unfollow_test_create')
self.assertEqual(unfollow_patients, {
'patient_ids': [[6, 0, self.EXPECTED_PATIENTS]]
})

def test_completes_activity(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS
"""
self.resp_calls = []
self.allocation_pool.unfollow_patients_in_locations(
self.cr, self.uid, [64], context='unfollow_test_complete')
self.assertEqual(completed_activities, 1)
144 changes: 144 additions & 0 deletions nh_clinical/tests/test_staff_reallocation_complete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Part of NHClinical. See LICENSE file for full copyright and licensing details
# -*- coding: utf-8 -*-
from openerp.tests.common import SingleTransactionCase


class TestStaffReallocationComplete(SingleTransactionCase):

EXPECTED_WARDS = [128, 256, 512, 1024]
resp_calls = []

@classmethod
def setUpClass(cls):
super(TestStaffReallocationComplete, cls).setUpClass()
cr, uid = cls.cr, cls.uid
cls.activity_pool = cls.registry('nh.activity')
cls.allocation_pool = cls.registry('nh.clinical.staff.reallocation')
cls.allocating_pool = cls.registry('nh.clinical.allocating')
cls.users_pool = cls.registry('res.users')
cls.location_pool = cls.registry('nh.clinical.location')
cls.nurse = cls.users_pool.create(cr, uid, {
'name': 'Nurse 1',
'login': 'complete_test_nurse1'
})
cls.hca = cls.users_pool.create(cr, uid, {
'name': 'HCA 1',
'login': 'complete_test_hca1'
})
cls.location = cls.location_pool.create(cr, uid, {
'usage': 'bed', 'name': 'Loc3',
'type': 'poc', 'parent_id': 1})
cls.ward_location = cls.location_pool.create(cr, uid, {
'usage': 'ward', 'name': 'Loc4',
'type': 'poc', 'parent_id': 1})
cls.allocation = cls.allocating_pool.create(cr, uid, {
'nurse_id': cls.nurse,
'hca_ids': [cls.hca],
'location_id': cls.location
})

def setUp(self):
cr, uid = self.cr, self.uid
super(TestStaffReallocationComplete, self).setUp()

def mock_allocation_wizard_browse(*args, **kwargs):
context = kwargs.get('context')
if context and 'complete_test' in context:
if context == 'complete_test_dual_role':
return self.allocation_pool.new(cr, uid, {
'allocating_ids': self.allocating_pool.new(cr, uid,
{}),
'user_ids': [uid, self.hca],
'ward_id': self.ward_location
})
return self.allocation_pool.new(cr, uid, {
'allocating_ids': self.allocating_pool.new(cr, uid, {}),
'user_ids': [self.nurse, self.hca],
'ward_id': self.ward_location
})
else:
return mock_allocation_wizard_browse.origin(*args, **kwargs)

def mock_allocating_browse(*args, **kwargs):
context = kwargs.get('context')
if context and 'complete_test' in context:
if context == 'complete_test_dual_role':
return self.allocating_pool.new(cr, uid, {
'nurse_id': uid,
'hca_ids': [self.hca],
'location_id': self.location
})
return self.allocating_pool.new(cr, uid, {
'nurse_id': self.nurse,
'hca_ids': [self.hca],
'location_id': self.location
})
else:
return mock_allocating_browse.origin(*args, **kwargs)

def mock_responsibility_allocation(*args, **kwargs):
context = kwargs.get('context')
if context and context in ['complete_test_resp',
'complete_test_dual_role']:
self.resp_calls.append((args[3], args[4]))
return True

self.allocation_pool._patch_method('browse',
mock_allocation_wizard_browse)
self.allocating_pool._patch_method('browse', mock_allocating_browse)
self.allocation_pool._patch_method(
'responsibility_allocation_activity',
mock_responsibility_allocation)

def tearDown(self):
super(TestStaffReallocationComplete, self).tearDown()
self.allocation_pool._revert_method('browse')
self.allocating_pool._revert_method('browse')
self.allocation_pool._revert_method(
'responsibility_allocation_activity')

def test_calls_reallocation(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS
"""
self.resp_calls = []
self.allocation_pool.complete(self.cr, self.uid, [64],
context='complete_test_resp')
self.assertEqual(len(self.resp_calls), 3)
self.assertIn((self.nurse, [self.location]), self.resp_calls)
self.assertIn((self.hca, [self.location]), self.resp_calls)

def test_calls_reallocation_dual_role(self):
"""
Test that the calls the responsibility allocation method with the user
ID and location IDS but when user is both ward manager and nurse make
sure it keeps them on the ward and the bed
"""
self.resp_calls = []
self.allocation_pool.complete(self.cr, self.uid, [64],
context='complete_test_dual_role')
self.assertEqual(len(self.resp_calls), 2)
self.assertIn((self.uid, [self.location, self.ward_location]),
self.resp_calls)
self.assertIn((self.hca, [self.location]), self.resp_calls)

def test_returns_wizard_id(self):
"""
Test that the submit_wards method returns the wizard ID to the frontend
so it can be passed to the next part of the wizard
"""
wizard_test = self.allocation_pool.complete(
self.cr, self.uid, [64], context='complete_test')
self.assertEqual(wizard_test, {'type': 'ir.actions.act_window_close'})

def test_errors_on_bad_id(self):
"""
Method should error when passed an ID that isn't an int
"""
with self.assertRaises(ValueError) as id_error:
self.allocation_pool.complete(
self.cr, self.uid, 'this is a test',
context='complete_test')
self.assertEqual(id_error.exception.message,
'Invalid ID passed to complete')
Loading

0 comments on commit 8f6ad45

Please sign in to comment.