aboutsummaryrefslogtreecommitdiff
path: root/tests/http/test_magic.py
blob: f645677984922fcd3ad2f1258c1206ce496195b5 (plain)
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
44
45
46
47
48
from uuid import uuid4

from generalresearch.redis_helper import RedisConfig

from jb.api.magic_token import (
    consume_amt_account_link_token,
    consume_magic_token,
    create_amt_account_link_token,
    create_magic_token,
)
from jb.models.auth import AmtAccountLink


class TestViewFunctions:

    def test_create_amt_account_link_token(
        self, redis_config: RedisConfig, amt_worker_id: str
    ):
        email = f"{uuid4().hex[:8]}@jamesbillings67.com"
        res = create_amt_account_link_token(
            email=email, amt_worker_id=amt_worker_id, redis_config=redis_config
        )
        assert isinstance(res, str)

    def test_create_and_retrieve_token(
        self, redis_config: RedisConfig, amt_worker_id: str
    ):
        email = f"{uuid4().hex[:8]}@jamesbillings67.com"
        token = create_amt_account_link_token(
            email=email, amt_worker_id=amt_worker_id, redis_config=redis_config
        )

        res = consume_amt_account_link_token(token=token, redis_config=redis_config)
        assert isinstance(res, AmtAccountLink)
        assert res.email == email
        assert res.amt_worker_id == amt_worker_id

    def test_create_magic_link(self, redis_config: RedisConfig, amt_worker_id: str):
        email = f"{uuid4().hex[:8]}@jamesbillings67.com"
        res = create_magic_token(user_email=email, redis_config=redis_config)
        assert isinstance(res, str)

    def test_consume_magic_link(self, redis_config: RedisConfig, amt_worker_id: str):
        email = f"{uuid4().hex[:8]}@jamesbillings67.com"
        token = create_magic_token(user_email=email, redis_config=redis_config)

        res = consume_magic_token(token=token, redis_config=redis_config)
        assert res == email