def test_post_invalid(client, organisation): force_login(organisation, client) csv_data = "code,description\n1067731000000107,Injury whilst swimming (disorder)" # missing signoff-0-user data = { "name": "Test Codelist", "coding_system_id": "snomedct", "description": "This is a test", "methodology": "This is how we did it", "csv_data": csv_builder(csv_data), "reference-TOTAL_FORMS": "1", "reference-INITIAL_FORMS": "0", "reference-MIN_NUM_FORMS": "0", "reference-MAX_NUM_FORMS": "1000", "reference-0-text": "foo", "reference-0-url": "http://example.com", "signoff-TOTAL_FORMS": "1", "signoff-INITIAL_FORMS": "0", "signoff-MIN_NUM_FORMS": "0", "signoff-MAX_NUM_FORMS": "1000", "signoff-0-date": "2020-01-23", } with assert_no_difference(organisation.codelists.count): response = client.post(organisation.get_codelist_create_url(), data=data) # we're returning an HTML response when there are errors so check we don't # receive a redirect code assert response.status_code == 200 # confirm we have errors from the signoff formset assert response.context_data["signoff_formset"].errors
def test_versions_post_no_auth(client, user_codelist): data = {"ecl": "<<128133004"} with assert_no_difference(user_codelist.versions.count): rsp = post(client, user_codelist.get_versions_api_url(), data, None) assert rsp.status_code == 401
def test_post_with_duplicate_name(client, organisation): force_login(organisation, client) csv_data = "code,description\n1067731000000107,Injury whilst swimming (disorder)" data = { "name": "Old-style Codelist", # This name is already taken "coding_system_id": "snomedct", "description": "This is a test", "methodology": "This is how we did it", "csv_data": csv_builder(csv_data), "reference-TOTAL_FORMS": "0", "reference-INITIAL_FORMS": "0", "reference-MIN_NUM_FORMS": "0", "reference-MAX_NUM_FORMS": "1000", "signoff-TOTAL_FORMS": "0", "signoff-INITIAL_FORMS": "0", "signoff-MIN_NUM_FORMS": "0", "signoff-MAX_NUM_FORMS": "1000", } with assert_no_difference(organisation.codelists.count): response = client.post(organisation.get_codelist_create_url(), data=data) # we're returning an HTML response when there are errors so check we don't # receive a redirect code assert response.status_code == 200 # confirm we have errors from the codelist form assert response.context_data["codelist_form"].errors == { "__all__": ["There is already a codelist called Old-style Codelist"] }
def test_versions_post_bad_ecl(client, user, user_codelist): data = {"ecl": "<<128133004 MIN"} with assert_no_difference(user_codelist.versions.count): rsp = post(client, user_codelist.get_versions_api_url(), data, user) assert rsp.status_code == 400 assert json.loads( rsp.content)["error"].startswith("InputMismatchException")
def test_versions_post_missing_data(client, user, user_codelist): data = {} with assert_no_difference(user_codelist.versions.count): rsp = post(client, user_codelist.get_versions_api_url(), data, user) assert rsp.status_code == 400 assert json.loads(rsp.content) == { "error": "Provide exactly one of `codes` or `ecl`" }
def test_versions_post_no_difference(client, user, user_codelist): data = {"ecl": "(<<128133004 OR 156659008) MINUS <<439656005"} with assert_no_difference(user_codelist.versions.count): rsp = post(client, user_codelist.get_versions_api_url(), data, user) assert rsp.status_code == 400 assert json.loads(rsp.content) == { "error": "No difference to previous version" }
def test_post_missing_field(client, old_style_codelist): force_login(old_style_codelist, client) with assert_no_difference(old_style_codelist.versions.count): response = client.post(old_style_codelist.get_version_upload_url(), data={}) assert response.status_code == 200 assert "form" in response.context_data assert len(response.context_data["form"].errors) == 1 assert "csv_data" in response.context_data["form"].errors
def test_codelists_post_no_auth(client, user): data = { "name": "New codelist", "coding_system_id": "snomedct", "codes": ["128133004", "156659008"], } with assert_no_difference(user.codelists.count): rsp = post(client, user.get_codelists_api_url(), data, None) assert rsp.status_code == 401
def test_versions_post_permission_denied(client, user_without_organisation, user_codelist): data = {"ecl": "<<128133004"} with assert_no_difference(user_codelist.versions.count): rsp = post( client, user_codelist.get_versions_api_url(), data, user_without_organisation, ) assert rsp.status_code == 403
def test_codelists_post_permission_denied(client, user, user_without_organisation): data = { "name": "New codelist", "coding_system_id": "snomedct", "codes": ["128133004", "156659008"], } with assert_no_difference(user.codelists.count): rsp = post(client, user.get_codelists_api_url(), data, user_without_organisation) assert rsp.status_code == 403