def test_extend_loan(self, mock_xsrf_token, mock_loanextend): tomorrow = datetime.datetime.utcnow() + datetime.timedelta(days=1) self.login_endpoints_user() self.service.extend_loan( device_messages.ExtendLoanRequest( device=device_messages.DeviceRequest( urlkey=self.device.key.urlsafe()), extend_date=tomorrow)) mock_loanextend.assert_called_once_with( user_email=loanertest.USER_EMAIL, extend_date_time=tomorrow) assert mock_xsrf_token.call_count == 1 mock_xsrf_token.reset_mock() mock_loanextend.reset_mock() self.service.extend_loan( device_messages.ExtendLoanRequest( device=device_messages.DeviceRequest( chrome_device_id=self.device.chrome_device_id), extend_date=tomorrow)) mock_loanextend.assert_called_once_with( user_email=loanertest.USER_EMAIL, extend_date_time=tomorrow) assert mock_xsrf_token.call_count == 1 mock_loanextend.side_effect = device_model.ExtendError self.assertRaises( device_api.endpoints.BadRequestException, self.service.extend_loan, device_messages.ExtendLoanRequest( device=device_messages.DeviceRequest( chrome_device_id=self.device.chrome_device_id), extend_date=tomorrow))
def testExtendLoanRequest(self): now = datetime.datetime.now() device = device_messages.DeviceRequest(asset_tag='FAKE-TAG') extend_loan_req = device_messages.ExtendLoanRequest( device=device, extend_date=now) self.assertEqual(extend_loan_req.extend_date, now) self.assertEqual(extend_loan_req.device.asset_tag, 'FAKE-TAG')
def test_extend_loan_unassigned(self): self.device.assigned_user = None self.device.put() with self.assertRaisesRegexp(endpoints.UnauthorizedException, device_model._UNASSIGNED_DEVICE): self.service.extend_loan( device_messages.ExtendLoanRequest( device=device_messages.DeviceRequest( chrome_device_id=self.device.chrome_device_id)))