Skip to content
Snippets Groups Projects
Commit f354b92d authored by Christian Boettcher's avatar Christian Boettcher
Browse files

bearer auth with basic test

parent 1aee0b98
Branches
Tags
No related merge requests found
Pipeline #85400 passed
import requests
import requests.auth
class BearerAuth(requests.auth.AuthBase):
def __init__(self, token: str) -> None:
super().__init__()
self.token = token
def __call__(self, r: requests.Request) -> requests.Request:
r.headers['Authorization'] = 'Bearer {}'.format(self.token)
return r
\ No newline at end of file
from unittest import TestCase
class DummyTest(TestCase):
def test_dummy(self):
print("Test Print")
self.assertEqual(4, 2*2)
\ No newline at end of file
from unittest import TestCase
from requests import Request
from datacat_integration.auth import BearerAuth
class AuthTest(TestCase):
def test_auth_creation(self):
token = "dummy_token_text"
header_key = "Authorization"
header_value = f"Bearer {token}"
auth: BearerAuth = BearerAuth(token)
r: Request = Request(auth=auth)
auth.__call__(r)
headers = r.headers
self.assertTrue(headers[header_key], header_value)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment