Coverage for dibbler / queries / throw_product.py: 24%

11 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-18 03:35 +0000

1from datetime import datetime 

2 

3from sqlalchemy.orm import Session 

4 

5from dibbler.models import Product, Transaction, User 

6 

7 

8def throw_product( 

9 sql_session: Session, 

10 user: User, 

11 product: Product, 

12 product_count: int, 

13 time: datetime | None = None, 

14 message: str | None = None, 

15) -> Transaction: 

16 if user.id is None: 

17 raise ValueError("User must be persisted in the database.") 

18 

19 if product.id is None: 

20 raise ValueError("Product must be persisted in the database.") 

21 

22 if product_count <= 0: 

23 raise ValueError("Product count must be positive.") 

24 

25 # TODO: verify time is not behind last transaction's time 

26 

27 raise NotImplementedError( 

28 "Please don't use this function until relevant calculations have been added to user_balance." 

29 ) 

30 

31 transaction = Transaction.throw_product( 

32 user_id=user.id, 

33 product_id=product.id, 

34 product_count=product_count, 

35 time=time, 

36 message=message, 

37 ) 

38 

39 sql_session.add(transaction) 

40 sql_session.commit() 

41 

42 return transaction