def test_get_as_system_client(self, __): DashboardSetting.objects.set_dict( 'upload-archivesspace_v0.0', { "base_url": "http://foobar.tld", "user": "******", "passwd": "12345", "repository": "5", }) client = get_as_system_client() assert client.base_url == "http://foobar.tld" assert client.user == "user" assert client.passwd == "12345" assert client.repository == "/repositories/5" # It raises error when "base_url" is missing. DashboardSetting.objects.set_dict('upload-archivesspace_v0.0', { "user": "******", "passwd": "12345", "repository": "5", }) with pytest.raises(ArchivesSpaceError): client = get_as_system_client() # It raises error when "base_url" is empty. DashboardSetting.objects.set_dict('upload-archivesspace_v0.0', { "base_url": "", "user": "******", "passwd": "12345", "repository": "5", }) with pytest.raises(ArchivesSpaceError): client = get_as_system_client()
def _get_client_by_type(system): if system == "archivesspace": return get_as_system_client() elif system == "atk": return get_atk_system_client() else: raise ValueError("Unrecognized access system: {}".format(system))
def wrapper(*args, **kwargs): try: client = get_as_system_client() except AuthenticationError: response = { "success": False, "message": "Unable to authenticate to ArchivesSpace server using the default user! Check administrative settings.", } return django.http.HttpResponseServerError( json.dumps(response), content_type="application/json" ) except ArchivesSpaceError: response = { "success": False, "message": "Unable to connect to ArchivesSpace server at the default location! Check administrative settings.", } return django.http.HttpResponseServerError( json.dumps(response), content_type="application/json" ) return func(client, *args, **kwargs)