File: test_token_auth.py

package info (click to toggle)
python-semantic-release 10.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 3,112 kB
  • sloc: python: 36,523; sh: 340; makefile: 156
file content (43 lines) | stat: -rw-r--r-- 966 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest
from requests import Request

from semantic_release.hvcs.token_auth import TokenAuth


@pytest.fixture
def example_request():
    return Request(
        "GET",
        url="http://example.com",
        headers={
            "User-Agent": "Python3",
            "Content-Type": "application/json",
            "Accept": "application/json",
        },
    )


def test_token_eq():
    t1 = TokenAuth("foo")
    t2 = TokenAuth("foo")

    assert t1 == t2


def test_token_neq():
    t1 = TokenAuth("foo")
    t2 = TokenAuth("bar")

    assert t1 != t2


def test_call_token_auth_sets_headers(example_request):
    old_headers = example_request.headers.copy()
    old_headers.pop("Authorization", None)
    t1 = TokenAuth("foo")
    new_req = t1(example_request)

    auth_header = new_req.headers.pop("Authorization")
    assert auth_header == "token foo"
    assert new_req.headers == old_headers
    assert new_req.__dict__ == example_request.__dict__