def test_create_with_data(self): media_code = make_recipe('legalaid.media_code') matter_type1 = make_recipe('legalaid.matter_type1') matter_type2 = make_recipe('legalaid.matter_type2') data = { 'notes': 'my notes', 'matter_type1': matter_type1.code, 'matter_type2': matter_type2.code, 'media_code': media_code.code, 'source': CASE_SOURCE.VOICEMAIL, 'provider_notes': "bla", } response = self.client.post(self.list_url, data=data, format='json', HTTP_AUTHORIZATION='Bearer %s' % self.token) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertResponseKeys(response) self.assertCaseEqual( response.data, Case( reference=response.data['reference'], notes=data['notes'], matter_type1=matter_type1, matter_type2=matter_type2, media_code=media_code, source=CASE_SOURCE.VOICEMAIL, provider_notes="", laa_reference=response.data['laa_reference'], )) self.assertLogInDB()
def test_create_with_data(self): check = make_recipe("legalaid.eligibility_check") data = { "eligibility_check": unicode(check.reference), "personal_details": self.get_personal_details_default_post_data(), } response = self.client.post(self.list_url, data=data, format="json") self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertCaseResponseKeys(response) self.assertCaseEqual( response.data, Case( reference=response.data["reference"], eligibility_check=check, personal_details=PersonalDetails(**data["personal_details"]), ), ) # test that the Case is in the db and created by 'web' user self.assertEqual(Case.objects.count(), 1) case = Case.objects.first() self.assertEqual(case.created_by.username, "web") # test that the log is in the db and created by 'web' user self.assertEqual(Log.objects.count(), 1) log = Log.objects.first() self.assertEqual(log.created_by.username, "web") # no email sent self.assertEquals(len(mail.outbox), 0)
def test_create_with_data(self): media_code = make_recipe("legalaid.media_code") matter_type1 = make_recipe("legalaid.matter_type1") matter_type2 = make_recipe("legalaid.matter_type2") data = { "notes": "my notes", "matter_type1": matter_type1.code, "matter_type2": matter_type2.code, "media_code": media_code.code, "source": CASE_SOURCE.VOICEMAIL, "provider_notes": "bla", } response = self.client.post(self.list_url, data=data, format="json", HTTP_AUTHORIZATION="Bearer %s" % self.token) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertResponseKeys(response) self.assertCaseEqual( response.data, Case( reference=response.data["reference"], notes=data["notes"], matter_type1=matter_type1, matter_type2=matter_type2, media_code=media_code, source=CASE_SOURCE.VOICEMAIL, provider_notes="", laa_reference=response.data["laa_reference"], ), ) self.assertLogInDB()
def test_update_doesnt_set_readonly_values(self): _old_settings = settings.DEBUG try: settings.DEBUG = True pd = make_recipe("legalaid.personal_details") eligibility_check = make_recipe("legalaid.eligibility_check") thirdparty_details = make_recipe("legalaid.thirdparty_details") adaptation_details = make_recipe("legalaid.adaptation_details") diagnosis = make_recipe("diagnosis.diagnosis") provider = make_recipe("cla_provider.provider") case = make_recipe("legalaid.case", eligibility_check=eligibility_check, personal_details=pd, thirdparty_details=thirdparty_details, adaptation_details=adaptation_details, diagnosis=diagnosis, media_code=None, matter_type1=None, matter_type2=None, source=CASE_SOURCE.PHONE, **self.get_extra_search_make_recipe_kwargs()) media_code = make_recipe("legalaid.media_code") matter_type1 = make_recipe("legalaid.matter_type1") matter_type2 = make_recipe("legalaid.matter_type2") data = { "personal_details": None, "eligibility_check": None, "thirdparty_details": None, "adaptation_details": None, "diagnosis": None, "provider": None, "billable_time": 234, "created": "2014-08-05T10:41:55.979Z", "modified": "2014-08-05T10:41:55.985Z", "created_by": "test_user", "matter_type1": matter_type1.code, "matter_type2": matter_type2.code, "media_code": media_code.code, "laa_reference": 232323, "source": CASE_SOURCE.VOICEMAIL, "requires_action_by": REQUIRES_ACTION_BY.PROVIDER_REVIEW, } response = self.client.patch( self.get_detail_url(case.reference), data=data, format="json", HTTP_AUTHORIZATION=self.get_http_authorization(), ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertResponseKeys(response) self.assertCaseEqual( response.data, Case( reference=response.data["reference"], personal_details=pd, eligibility_check=eligibility_check, thirdparty_details=thirdparty_details, adaptation_details=adaptation_details, diagnosis=diagnosis, provider=provider, billable_time=0, laa_reference=response.data["laa_reference"], matter_type1=matter_type1, matter_type2=matter_type2, media_code=media_code, source=CASE_SOURCE.VOICEMAIL, requires_action_by=case.requires_action_by, ), ) self.assertNotEqual(response.data["requires_action_by"], data["requires_action_by"]) self.assertNotEqual(response.data["created"], data["created"]) self.assertNotEqual(response.data["created_by"], data["created_by"]) self.assertNotEqual(response.data["modified"], data["modified"]) self.assertNotEqual(response.data["laa_reference"], data["laa_reference"]) self.assertNoLogInDB() # looking for the update case query update_query = [ query for query in connection.queries if query["sql"].startswith("UPDATE") ] self.assertEqual(len(update_query), 1) update_sql = update_query[0]["sql"] for readonly_field in [ "personal_details", "eligibility_check", "thirdparty_details", "adaptation_details", "provider", "billable_time", "laa_reference", "requires_action_by", ]: self.assertFalse( readonly_field in update_sql, "%s is in the UPDATE query when it shouldn't be!" % readonly_field) finally: settings.DEBUG = _old_settings connection.queries = []
def test_create_doesnt_set_readonly_values_but_only_personal_details(self): """ Only POST personal details allowed """ pd = make_recipe('legalaid.personal_details') eligibility_check = make_recipe('legalaid.eligibility_check') thirdparty_details = make_recipe('legalaid.thirdparty_details') adaptation_details = make_recipe('legalaid.adaptation_details') diagnosis = make_recipe('diagnosis.diagnosis') provider = make_recipe('cla_provider.provider') media_code = make_recipe('legalaid.media_code') matter_type1 = make_recipe('legalaid.matter_type1') matter_type2 = make_recipe('legalaid.matter_type2') data = { 'personal_details': unicode(pd.reference), 'eligibility_check': unicode(eligibility_check.reference), 'thirdparty_details': unicode(thirdparty_details.reference), 'adaptation_details': unicode(adaptation_details.reference), 'diagnosis': unicode(diagnosis.reference), 'provider': unicode(provider.id), 'notes': 'my notes', 'billable_time': 234, 'created': "2014-08-05T10:41:55.979Z", 'modified': "2014-08-05T10:41:55.985Z", 'created_by': "test_user", 'matter_type1': matter_type1.code, 'matter_type2': matter_type2.code, 'media_code': media_code.code, 'provider_notes': "bla", 'source': CASE_SOURCE.VOICEMAIL, 'laa_reference': 232323, 'requires_action_by': REQUIRES_ACTION_BY.PROVIDER_REVIEW } response = self.client.post(self.list_url, data=data, format='json', HTTP_AUTHORIZATION='Bearer %s' % self.token) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertResponseKeys(response) self.assertCaseEqual( response.data, Case(reference=response.data['reference'], personal_details=pd, eligibility_check=None, thirdparty_details=None, adaptation_details=None, diagnosis=None, provider=None, notes=data['notes'], billable_time=0, laa_reference=response.data['laa_reference'], matter_type1=matter_type1, matter_type2=matter_type2, media_code=media_code, source=CASE_SOURCE.VOICEMAIL, provider_notes="")) self.assertNotEqual(response.data['requires_action_by'], data['requires_action_by']) self.assertNotEqual(response.data['created'], data['created']) self.assertNotEqual(response.data['created_by'], data['created_by']) self.assertNotEqual(response.data['modified'], data['modified']) self.assertNotEqual(response.data['laa_reference'], data['laa_reference']) self.assertLogInDB()
def test_update_doesnt_set_readonly_values(self): _old_settings = settings.DEBUG try: settings.DEBUG = True pd = make_recipe('legalaid.personal_details') eligibility_check = make_recipe('legalaid.eligibility_check') thirdparty_details = make_recipe('legalaid.thirdparty_details') adaptation_details = make_recipe('legalaid.adaptation_details') diagnosis = make_recipe('diagnosis.diagnosis') provider = make_recipe('cla_provider.provider') case = make_recipe( 'legalaid.case', eligibility_check=eligibility_check, personal_details=pd, thirdparty_details=thirdparty_details, adaptation_details=adaptation_details, diagnosis=diagnosis, media_code=None, matter_type1=None, matter_type2=None, source=CASE_SOURCE.PHONE, **self.get_extra_search_make_recipe_kwargs() ) media_code = make_recipe('legalaid.media_code') matter_type1 = make_recipe('legalaid.matter_type1') matter_type2 = make_recipe('legalaid.matter_type2') data = { 'personal_details': None, 'eligibility_check': None, 'thirdparty_details': None, 'adaptation_details': None, 'diagnosis': None, 'provider': None, 'billable_time': 234, 'created': "2014-08-05T10:41:55.979Z", 'modified': "2014-08-05T10:41:55.985Z", 'created_by': "test_user", 'matter_type1': matter_type1.code, 'matter_type2': matter_type2.code, 'media_code': media_code.code, 'laa_reference': 232323, 'source': CASE_SOURCE.VOICEMAIL, 'requires_action_by': REQUIRES_ACTION_BY.PROVIDER_REVIEW } response = self.client.patch( self.get_detail_url(case.reference), data=data, format='json', HTTP_AUTHORIZATION=self.get_http_authorization() ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertResponseKeys(response) self.assertCaseEqual(response.data, Case( reference=response.data['reference'], personal_details=pd, eligibility_check=eligibility_check, thirdparty_details=thirdparty_details, adaptation_details=adaptation_details, diagnosis=diagnosis, provider=provider, billable_time=0, laa_reference=response.data['laa_reference'], matter_type1=matter_type1, matter_type2=matter_type2, media_code=media_code, source=CASE_SOURCE.VOICEMAIL, requires_action_by=case.requires_action_by ) ) self.assertNotEqual(response.data['requires_action_by'], data['requires_action_by']) self.assertNotEqual(response.data['created'], data['created']) self.assertNotEqual(response.data['created_by'], data['created_by']) self.assertNotEqual(response.data['modified'], data['modified']) self.assertNotEqual(response.data['laa_reference'], data['laa_reference']) self.assertNoLogInDB() # looking for the update case query update_query = [query for query in connection.queries if query['sql'].startswith('UPDATE')] self.assertEqual(len(update_query), 1) update_sql = update_query[0]['sql'] for readonly_field in [ 'personal_details', 'eligibility_check', 'thirdparty_details', 'adaptation_details', 'provider', 'billable_time', 'laa_reference', 'requires_action_by' ]: self.assertFalse(readonly_field in update_sql, '%s is in the UPDATE query when it shouldn\'t be!' % readonly_field) finally: settings.DEBUG = _old_settings connection.queries = []
def test_create_doesnt_set_readonly_values_but_only_personal_details(self): """ Only POST personal details allowed """ pd = make_recipe("legalaid.personal_details") eligibility_check = make_recipe("legalaid.eligibility_check") thirdparty_details = make_recipe("legalaid.thirdparty_details") adaptation_details = make_recipe("legalaid.adaptation_details") diagnosis = make_recipe("diagnosis.diagnosis") provider = make_recipe("cla_provider.provider") organisation = make_recipe("call_centre.organisation") media_code = make_recipe("legalaid.media_code") matter_type1 = make_recipe("legalaid.matter_type1") matter_type2 = make_recipe("legalaid.matter_type2") data = { "personal_details": unicode(pd.reference), "eligibility_check": unicode(eligibility_check.reference), "thirdparty_details": unicode(thirdparty_details.reference), "adaptation_details": unicode(adaptation_details.reference), "diagnosis": unicode(diagnosis.reference), "provider": unicode(provider.id), "notes": "my notes", "billable_time": 234, "created": "2014-08-05T10:41:55.979Z", "modified": "2014-08-05T10:41:55.985Z", "created_by": "test_user", "matter_type1": matter_type1.code, "matter_type2": matter_type2.code, "media_code": media_code.code, "provider_notes": "bla", "source": CASE_SOURCE.VOICEMAIL, "laa_reference": 232323, "requires_action_by": REQUIRES_ACTION_BY.PROVIDER_REVIEW, "organisation": organisation.pk, } response = self.client.post(self.list_url, data=data, format="json", HTTP_AUTHORIZATION="Bearer %s" % self.token) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertResponseKeys(response) self.assertCaseEqual( response.data, Case( reference=response.data["reference"], personal_details=pd, eligibility_check=None, thirdparty_details=None, adaptation_details=None, diagnosis=None, provider=None, notes=data["notes"], billable_time=0, laa_reference=response.data["laa_reference"], matter_type1=matter_type1, matter_type2=matter_type2, media_code=media_code, source=CASE_SOURCE.VOICEMAIL, provider_notes="", organisation=None, ), ) self.assertNotEqual(response.data["requires_action_by"], data["requires_action_by"]) self.assertNotEqual(response.data["created"], data["created"]) self.assertNotEqual(response.data["created_by"], data["created_by"]) self.assertNotEqual(response.data["modified"], data["modified"]) self.assertNotEqual(response.data["laa_reference"], data["laa_reference"]) self.assertLogInDB()