def test_basic_login(self, requests_mock): requests_mock.get( "https://demo.dev/test_auth", status_code=200, request_headers=dict(Authorization="Basic dXNlcjpwYXNz"), ) conn = Connector("https://demo.dev", "user", "pass") conn.set_basic_auth_data("/test_auth") conn.login()
def test_get_basic_relogin(self, requests_mock): # Define more specific mock aafter less specific ones, since they are # matched in bottom-up order. requests_mock.get("https://demo.dev/data", status_code=401) requests_mock.get( "https://demo.dev/test", status_code=200, request_headers=dict(Authorization="Basic dXNlcjpwYXNz"), ) requests_mock.get( "https://demo.dev/data", status_code=200, request_headers=dict(Authorization="Basic dXNlcjpwYXNz"), ) conn = Connector("https://demo.dev", "user", "pass") conn.set_basic_auth_data("/test") r = conn.get("/data") assert r.status == 200 assert r.json is None
def test_basic_login_invalid_credentials(self, requests_mock): requests_mock.get("https://demo.dev/test_auth", status_code=401) conn = Connector("https://demo.dev", "user", "notpass") conn.set_basic_auth_data("/test_auth") with pytest.raises(AuthException): conn.login()
def test_basic_logout(self, requests_mock): conn = Connector("https://demo.dev", "user", "pass") conn.set_basic_auth_data("/test_auth") conn.logout()