aboutsummaryrefslogtreecommitdiff
path: root/tests/managers/thl/test_buyer.py
blob: 69ea105d3862334ab2776fc2339ca256066bfffb (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
from generalresearch.models import Source


class TestBuyer:

    def test(
        self,
        delete_buyers_surveys,
        buyer_manager,
    ):

        bs = buyer_manager.bulk_get_or_create(source=Source.TESTING, codes=["a", "b"])
        assert len(bs) == 2
        buyer_a = bs[0]
        assert buyer_a.id is not None
        bs2 = buyer_manager.bulk_get_or_create(source=Source.TESTING, codes=["a", "c"])
        assert len(bs2) == 2
        buyer_a2 = bs2[0]
        buyer_c = bs2[1]
        # a isn't created again
        assert buyer_a == buyer_a2
        assert bs2[0].id is not None

        # and its cached
        assert buyer_c.id == buyer_manager.source_code_pk[f"{Source.TESTING.value}:c"]