def test_process_shift_creation_works_without_errors(self): ResidentFactory.create( state=ResidentStateEnum.APPROVED, specialities=[self.shift.speciality], residency_years=self.shift.residency_years_required) process_shift_creation(self.shift)
def test_get_waiting_for_approve_by_account_manager_success(self): self.authenticate_as_account_manager() ResidentFactory.create(state=ResidentStateEnum.PROFILE_FILLED) resp = self.client.get('/api/accounts/resident/waiting_for_approval/') self.assertSuccessResponse(resp) # There is only one resident in profile filled state self.assertEqual(len(resp.data), 1)
def test_update_using_existing_another_email_failed(self): ResidentFactory.create(email='*****@*****.**') self.authenticate_as_resident() data = { 'email' '*****@*****.**', } resp = self.client.patch('/api/accounts/resident/{0}/'.format( self.resident.pk), data, format='json') self.assertBadRequest(resp)
def test_process_shift_updating_with_active_applicants_works_correctly( self, mock_async_send_mail): # Create suitable resident without application ResidentFactory.create( state=ResidentStateEnum.APPROVED, specialities=[self.shift.speciality], residency_years=self.shift.residency_years_required) process_shift_updating(self.shift) mock_async_send_mail.assert_called_once() _, first_call_args, _ = mock_async_send_mail.mock_calls[0] self.assertEqual(first_call_args[1], self.resident.email)
def test_fill_profile(self, mock_process_resident_profile_filling): new_resident = ResidentFactory.create() new_resident.fill_profile({}) new_resident.save() new_resident.refresh_from_db() self.assertEqual(new_resident.state, ResidentStateEnum.PROFILE_FILLED) mock_process_resident_profile_filling.assert_called_with(new_resident)
def test_reject(self, mock_process_resident_rejecting): resident = ResidentFactory.create( state=ResidentStateEnum.PROFILE_FILLED) resident.reject() resident.save() resident.refresh_from_db() self.assertEqual(resident.state, ResidentStateEnum.REJECTED) mock_process_resident_rejecting.assert_called_with(resident)
def test_process_shift_creation_works_correctly(self, mock_async_send_mail): # Not suitable resident ResidentFactory.create(state=ResidentStateEnum.APPROVED) # Suitable resident with notification disabled settings ResidentFactory.create( state=ResidentStateEnum.APPROVED, specialities=[self.shift.speciality], residency_years=self.shift.residency_years_required, notification_new_shifts=False) suitable_resident = ResidentFactory.create( state=ResidentStateEnum.APPROVED, specialities=[self.shift.speciality], residency_years=self.shift.residency_years_required) process_shift_creation(self.shift) mock_async_send_mail.assert_called_once() _, first_call_args, _ = mock_async_send_mail.mock_calls[0] self.assertEqual(first_call_args[1], suitable_resident.email)
def test_authentication_with_token_success(self): client = WSClient() resident = ResidentFactory.create() token = TokenFactory.create(user=resident) client.send_and_consume('websocket.connect', path='/accounts/user/{0}/'.format(token.key), check_accept=False) received = client.receive(json=False) self.assertEqual(received, {"accept": True})
def test_reject_permission(self): resident = ResidentFactory.create( state=ResidentStateEnum.PROFILE_FILLED) # Scheduler (not account manager) can't approve resident scheduler = SchedulerFactory.create() self.assertFalse(has_transition_perm( resident.reject, scheduler)) # Account manager can approve resident self.assertTrue(has_transition_perm( resident.reject, self.account_manager))
def test_receive_for_authenticated_success(self): client = WSClient() resident = ResidentFactory.create() token = TokenFactory.create(user=resident) client.send_and_consume( 'websocket.connect', path='/accounts/user/{0}/'.format(token.key), ) Group('user-{0}'.format(resident.pk)).send({'text': 'ok'}, immediately=True) self.assertEqual(client.receive(json=False), 'ok')
def setUp(self): self.request = ExtendedRequestFactory() self.scheduler = SchedulerFactory.create() self.resident = ResidentFactory.create() self.shift = ShiftFactory.create(owner=self.scheduler) self.application = ApplicationFactory.create(shift=self.shift) self.message = MessageFactory.create(owner=self.resident, application=self.application, text='test text') self.message2 = MessageFactory.create(owner=self.resident, application=self.application, text='see attachment', attachment=SimpleUploadedFile( 'text.txt', b'Some text in file'))
def setUp(self): super(ShiftsTestCaseMixin, self).setUp() self.first_speciality = SpecialityFactory.create() self.second_speciality = SpecialityFactory.create() self.first_shift = ShiftFactory.create( residency_years_required=0, speciality=self.first_speciality) self.second_shift = ShiftFactory.create( residency_years_required=5, speciality=self.second_speciality) self.approved_resident = ResidentFactory.create( state=ResidentStateEnum.APPROVED, residency_years=5, ) self.approved_resident.specialities.add(self.first_speciality, self.second_speciality)
def setUp(self): self.request = ExtendedRequestFactory() self.scheduler = SchedulerFactory.create() self.resident = ResidentFactory.create() self.shift = ShiftFactory.create(owner=self.scheduler)
def test_create_token_as_not_active_resident(self): resident = ResidentFactory.create(is_active=False) token = self.create_token(resident) self.assertIsNone(token)
def test_update_not_self_by_resident_failed(self): resident = ResidentFactory.create() self.authenticate_as_resident(resident) resp = self.client.patch('/api/accounts/resident/{0}/'.format( self.resident.pk)) self.assertForbidden(resp)
def setUp(self): self.scheduler = SchedulerFactory.create() self.resident = ResidentFactory.create() self.shift = ShiftFactory.create(owner=self.scheduler) self.application = ApplicationFactory.create(shift=self.shift, owner=self.resident)
def setUp(self): super(APITestCase, self).setUp() self.scheduler = SchedulerFactory(password='******') self.resident = ResidentFactory(password='******') self.account_manager = AccountManagerFactory(password='******')
def setUp(self): super(ApplicationTest, self).setUp() self.resident = ResidentFactory.create() self.scheduler = SchedulerFactory.create() self.shift = ShiftFactory.create(owner=self.scheduler)
def setUp(self): self.resident = ResidentFactory.create() self.scheduler = SchedulerFactory.create() self.account_manager = AccountManagerFactory.create() self.superuser = SuperUserFactory.create()