def test_store_twice_overrides_cookie_file(self): cookie_content = "nasenmann.org; expires: never" OCDBApi.store_login_cookie(cookie_content) cookie_content = "hell-yeah!; expires: now" OCDBApi.store_login_cookie(cookie_content) result = OCDBApi.read_login_cookie() self.assertEqual(cookie_content, result)
def test_delete_login_cookie(self): cookie_content = "nasenmann.org; expires: never" OCDBApi.store_login_cookie(cookie_content) login_info_file = os.path.join(USER_DIR, "login_info") self.assertTrue(os.path.isfile(login_info_file)) OCDBApi.delete_login_cookie() self.assertFalse(os.path.isfile(login_info_file))
def test_constr(self): api = OCDBApi() self.assertIsNotNone(api.config) self.assertIsNotNone(api.server_url) api = OCDBApi( server_url="https://bibosrv", config_store=MemConfigStore(server_url="https://bertsrv")) self.assertIsNotNone(api.config) self.assertEqual("https://bibosrv", api.server_url)
def setUp(self): warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*") os.environ['OCDB_SERVER_URL'] = TEST_URL self.api = OCDBApi(**self.api_kwargs) httpretty.enable()
def test_load_login_cookie_not_existing(self): result = OCDBApi.read_login_cookie() self.assertIsNone(result)
def test_store_and_load_login_cookie(self): cookie_content = "nasenmann.org; expires: never" OCDBApi.store_login_cookie(cookie_content) result = OCDBApi.read_login_cookie() self.assertEqual(cookie_content, result)
def test_make_url(self): api = OCDBApi(config_store=MemConfigStore()) with self.assertRaises(ValueError) as cm: api._make_url('/datasets') self.assertEqual('"server_url" is not configured', f'{cm.exception}') server_url_with_trailing_slash = 'http://localhost:2385/' api = OCDBApi(config_store=MemConfigStore( server_url=server_url_with_trailing_slash)) self.assertEqual( 'http://localhost:2385/eocdb/api/' + TEST_VERSION + '/datasets', api._make_url('datasets')) self.assertEqual( 'http://localhost:2385/eocdb/api/' + TEST_VERSION + '/datasets', api._make_url('/datasets')) server_url_without_trailing_slash = 'http://localhost:2385' api = OCDBApi(config_store=MemConfigStore( server_url=server_url_without_trailing_slash)) self.assertEqual( 'http://localhost:2385/eocdb/api/' + TEST_VERSION + '/datasets', api._make_url('datasets')) self.assertEqual( 'http://localhost:2385/eocdb/api/' + TEST_VERSION + '/datasets', api._make_url('/datasets'))
def test_api_with_defaults(self): api_with_defaults = OCDBApi() self.assertIsNotNone(api_with_defaults.config) self.assertTrue(api_with_defaults.server_url is None or api_with_defaults.server_url is not None)
def setUp(self): warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*") self.api = OCDBApi(**self.api_kwargs) httpretty.enable()