blob: 6776ab333b016ffd89c2b0b7344e8810f4c6923d (
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
|
from __future__ import annotations
from collections.abc import Callable
from generalresearch.managers.thl.buyer import BuyerManager
from generalresearch.models import Source
class TestBuyer:
def test(
self,
delete_buyers_surveys: Callable[..., None],
buyer_manager: BuyerManager,
):
delete_buyers_surveys()
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"]
|