39 lines
1.8 KiB
Python
39 lines
1.8 KiB
Python
|
|
from app.economy.backend import router
|
||
|
|
from app.workflows import integration
|
||
|
|
|
||
|
|
|
||
|
|
def test_queue_checks_activation_once_per_customer_without_changing_methods(monkeypatch):
|
||
|
|
calls=[]
|
||
|
|
def active(customer):
|
||
|
|
calls.append(customer)
|
||
|
|
return customer==17
|
||
|
|
monkeypatch.setattr(integration,'active_for_customer',active)
|
||
|
|
monkeypatch.setattr(router,'execute_query',lambda *args:[{'time_id':1,'revision':2,'entry_revision':2,'method':'subscription','status':'decided','details':{'billing':{'agreement_id':2}}}])
|
||
|
|
rows=[{'id':1,'customer_id':17,'billing_method':'draft'}, {'id':2,'customer_id':17,'billing_method':'draft'}, {'id':3,'customer_id':18,'billing_method':'invoice'}]
|
||
|
|
router._attach_workflow_decisions(rows)
|
||
|
|
assert calls==[17,18]
|
||
|
|
assert rows[0]['billing_method']=='subscription'
|
||
|
|
assert rows[0]['fixed_price_agreement_id']==2
|
||
|
|
assert rows[1]['workflow_active'] is True
|
||
|
|
assert rows[2]['billing_method']=='invoice'
|
||
|
|
assert rows[2]['workflow_active'] is False
|
||
|
|
|
||
|
|
|
||
|
|
def test_case_tags_are_batched_and_legacy_used_only_for_cases_without_generic_tags(monkeypatch):
|
||
|
|
calls=[]
|
||
|
|
def query(sql,params):
|
||
|
|
calls.append((sql,params))
|
||
|
|
if 'FROM entity_tags' in sql:
|
||
|
|
return [{'sag_id':196,'id':7,'name':'ABA','color':'#009999','icon':'bi-tag'}]
|
||
|
|
return [{'sag_id':197,'id':9,'name':'Legacy'}]
|
||
|
|
monkeypatch.setattr(router,'execute_query',query)
|
||
|
|
rows=[{'id':1,'sag_id':196},{'id':2,'sag_id':196},{'id':3,'sag_id':197},{'id':4,'sag_id':None}]
|
||
|
|
router._attach_case_tags(rows)
|
||
|
|
assert len(calls)==2
|
||
|
|
assert calls[0][1]==([196,197],)
|
||
|
|
assert calls[1][1]==([197],)
|
||
|
|
assert rows[0]['case_tags']==rows[1]['case_tags']
|
||
|
|
assert rows[0]['case_tags'][0]['name']=='ABA'
|
||
|
|
assert rows[2]['case_tags'][0]['name']=='Legacy'
|
||
|
|
assert rows[3]['case_tags']==[]
|