Coverage for src/artemis_sg/vendor.py: 83%

1 import logging

2 import sys

3

4 from artemis_sg.config import CFG

5

6

7 class Vendor:

8 def __init__(self, code):

9 self.vendor_code = code

10 self.vendor_name = ""

11 self.isbn_key = ""

12

13 def _filter_database_data(self, all_data):

14 namespace = f"{type(self).__name__}.{self._filter_database_data.__name__}"

15 try:

16 return next( 16 ↛ exitline 16 didn't jump to the function exit

17 (item for item in all_data if item["code"] == self.vendor_code), None

18 )

19 except KeyError:

20 logging.error(f"{namespace}: Vendor code not found in database")

21 sys.exit(1)

22

23 def set_vendor_data(self):

24 """Create Vendor object class"""

25 namespace = f"{type(self).__name__}.{self.set_vendor_data.__name__}"

26

27 all_data = CFG["asg"]["vendors"]

28 vendor_data = self._filter_database_data(all_data)

29 logging.debug(f"{namespace}: Vendor data is: '{vendor_data}'")

30 self.vendor_name = vendor_data["name"]

31 self.isbn_key = vendor_data["isbn_key"].upper()