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_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(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