def test_load_org_info_from_csv(test_models): # flake8: noqa OrgInfo.load_from_csv( """Organisation,Title,First Name,Last Name,Role,Email,Phone,Permission to post to web,Country Code,City of home campus,common:disambiguated-organization-identifier,common:disambiguation-source Organisation_0,Title_0,First Name_0,Last Name_0,Role_0,Email_0,Phone_0,Permission to post to web_0,Country Code_0,City of home campus_0,common:disambiguated-organization-identifier_0,common:disambiguation-source Organisation_1,Title_1,First Name_1,Last Name_1,Role_1,Email_1,Phone_1,yes,Country Code_1,City of home campus_1,common:disambiguated-organization-identifier_1,common:disambiguation-source """) assert OrgInfo.select().count() == 2 oi = OrgInfo.get(name="Organisation_1") assert oi.is_public
def test_file_upload_with_encodings(client, mocker): """Test BOM handling in the uploaded file.""" client.login_root() for no, (e, bom) in enumerate([ ("utf-8", None), ("utf-8", codecs.BOM_UTF8), ("utf-16", None), ("utf-16", codecs.BOM_UTF16), ("utf-32", None), ("utf-32", codecs.BOM_UTF32), ]): data = f"disambiguated id,disambiguation source,name\n123,ABC,대학 #{no} WITH {e}".encode( e) if bom: data = bom + data resp = client.post("/load/org", follow_redirects=True, data={ "save": "Upload", "file_": ( BytesIO(data), "raw-org-data-with-bom.csv", ), }) assert resp.status_code == 200 assert OrgInfo.select().count() == no + 1
def test_load_org_info_from_csv(models): # flake8: noqa OrgInfo.load_from_csv( """Organisation,Title,First Name,Last Name,Role,Email,Phone,Permission to post to web,Country Code,City of home campus,common:disambiguated-organization-identifier,common:disambiguation-source Organisation_0,Title_0,First Name_0,Last Name_0,Role_0,Email_0,Phone_0,Permission to post to web_0,Country Code_0,City of home campus_0,common:disambiguated-organization-identifier_0,common:disambiguation-source Organisation_1,Title_1,First Name_1,Last Name_1,Role_1,Email_1,Phone_1,yes,Country Code_1,City of home campus_1,common:disambiguated-organization-identifier_1,common:disambiguation-source """) assert OrgInfo.select().count() == 2 oi = OrgInfo.get(name="Organisation_1") assert oi.is_public OrgInfo.load_from_csv( StringIO("""Name,Disambiguated Id,Disambiguation Source AgResearch Ltd,3713,RINGGOLD Aqualinc Research Ltd,9429035717133,NZBN Ara Institute of Canterbury,6006,Education Organisation Number Auckland District Health Board,1387,RINGGOLD Auckland University of Technology,1410,RINGGOLD Bay of Plenty District Health Board,7854,RINGGOLD Capital and Coast District Health Board,8458,RINGGOLD Cawthron Institute,5732,RINGGOLD CRL Energy Ltd,9429038654381,NZBN Health Research Council,http://dx.doi.org/10.13039/501100001505,FUNDREF Hutt Valley District Health Board,161292,RINGGOLD Institute of Environmental Science and Research,8480,RINGGOLD Institute of Geological & Nuclear Sciences Ltd,5180,RINGGOLD """)) assert OrgInfo.select().count() == 15
def test_onboard_org(request_ctx): """Test to organisation onboarding.""" org = Organisation.create(name="THE ORGANISATION", tuakiri_name="THE ORGANISATION", confirmed=False, orcid_client_id="CLIENT ID", orcid_secret="Client Secret", city="CITY", country="COUNTRY", disambiguated_id="ID", disambiguation_source="SOURCE", is_email_sent=True) u = User.create(email="*****@*****.**", name="TEST USER", roles=Role.TECHNICAL, orcid="123", confirmed=True, organisation=org) second_user = User.create(email="*****@*****.**", name="TEST USER", roles=Role.ADMIN, orcid="1243", confirmed=True, organisation=org) org_info = OrgInfo.create(name="THE ORGANISATION", tuakiri_name="THE ORGANISATION") org.tech_contact = u org_info.save() org.save() OrgInvitation.get_or_create(email=u.email, org=org, token="sdsddsd") UserOrg.create(user=u, org=org, is_admin=True) with request_ctx("/confirm/organisation") as ctx: login_user(u) u.save() assert u.is_tech_contact_of(org) rv = ctx.app.full_dispatch_request() assert rv.status_code == 200 assert b"<!DOCTYPE html>" in rv.data, "Expected HTML content" assert b"Take me to ORCID to obtain my Client ID and Client Secret" in rv.data,\ "Expected Button on the confirmation page" with request_ctx("/confirm/organisation") as ctxx: second_user.save() login_user(second_user) rv = ctxx.app.full_dispatch_request() assert rv.status_code == 302 assert rv.location.startswith("/admin/viewmembers/") with request_ctx("/confirm/organisation", method="POST", data={ "orcid_client_id": "APP-FDFN3F52J3M4L34S", "orcid_secret": "4916c2d7-085e-487e-94d0-32450a9cfe6c", "country": "NZ", "city": "Auckland", "disambiguated_id": "xyz", "disambiguation_source": "xyz", "name": "THE ORGANISATION" }) as cttxx: login_user(u) u.save() with patch("orcid_hub.authcontroller.requests") as requests: requests.post.return_value = Mock(data=b'XXXX', status_code=200) rv = cttxx.app.full_dispatch_request() assert rv.status_code == 302 assert rv.location.startswith("/link")
def test_onboard_org(client): """Test to organisation onboarding.""" org = Organisation.create(name="THE ORGANISATION:test_onboard_org", tuakiri_name="THE ORGANISATION:test_onboard_org", confirmed=False, orcid_client_id="CLIENT ID", orcid_secret="Client Secret", city="CITY", country="COUNTRY", disambiguated_id="ID", disambiguation_source="RINGGOLD", is_email_sent=True) u = User.create(email="*****@*****.**", name="TEST USER", roles=Role.TECHNICAL, orcid="123", confirmed=True, organisation=org) second_user = User.create(email="*****@*****.**", name="TEST USER", roles=Role.ADMIN, orcid="1243", confirmed=True, organisation=org) UserOrg.create(user=second_user, org=org, is_admin=True) org_info = OrgInfo.create(name="A NEW ORGANISATION", tuakiri_name="A NEW ORGANISATION") org.tech_contact = u org_info.save() org.save() client.login_root() with patch("orcid_hub.utils.send_email"): resp = client.post("/invite/organisation", data=dict(org_name="A NEW ORGANISATION", org_email="*****@*****.**"), follow_redirects=True) assert User.select().where( User.email == "*****@*****.**").exists() resp = client.post("/invite/organisation", data=dict(org_name="A NEW ORGANISATION", org_email="*****@*****.**", tech_contact='y'), follow_redirects=True) assert User.select().where( User.email == "*****@*****.**").exists() org = Organisation.get(name="A NEW ORGANISATION") user = User.get(email="*****@*****.**") assert user.name is None assert org.tech_contact == user client.logout() resp = client.login(user, **{ "Sn": "TECHNICAL", "Givenname": "CONTACT", "Displayname": "Test User", "shib_O": "NEW ORGANISATION" }, follow_redirects=True) user = User.get(email="*****@*****.**") org = user.organisation assert user.is_tech_contact_of(org) resp = client.get("/confirm/organisation") assert resp.status_code == 200 org = Organisation.get(org.id) assert b"<!DOCTYPE html>" in resp.data, "Expected HTML content" assert b"Take me to ORCID to obtain my Client ID and Client Secret" in resp.data with patch("orcid_hub.authcontroller.requests") as requests: requests.post.return_value = Mock(data=b'XXXX', status_code=200) resp = client.post("/confirm/organisation", data={ "orcid_client_id": "APP-1234567890ABCDEF", "orcid_secret": "12345678-1234-1234-1234-1234567890ab", "country": "NZ", "city": "Auckland", "disambiguated_id": "XYZ123", "disambiguation_source": "RINGGOLD", "name": org.name, "email": user.email, }) assert resp.status_code == 302 url = urlparse(resp.location).path assert url == "/link" resp = client.get(url) client.logout() org = Organisation.get(org.id) assert org.disambiguated_id == "XYZ123" assert org.disambiguation_source == "RINGGOLD" assert org.orcid_client_id == "APP-1234567890ABCDEF" assert org.orcid_secret == "12345678-1234-1234-1234-1234567890ab" user = User.get(email="*****@*****.**") resp = client.login(user, **{ "Sn": "NEW ORGANISATION", "Givenname": "ADMINISTRATOR", "Displayname": "Admin User", "shib_O": "NEW ORGANISATION" }, follow_redirects=True) assert b"Take me to ORCID to allow A NEW ORGANISATION permission to access my ORCID record" in resp.data resp = client.get("/confirm/organisation") assert resp.status_code == 302 assert urlparse(resp.location).path == "/admin/viewmembers/" resp = client.get("/admin/viewmembers/") assert b"*****@*****.**" in resp.data resp = client.get("/admin/viewmembers/export/csv/") assert resp.headers["Content-Type"] == "text/csv; charset=utf-8" assert b"*****@*****.**" in resp.data assert b"*****@*****.**" in resp.data