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

1# -*- coding: utf-8 -*-

2

3 import logging

4 import sys

5

6 from artemis_sg.config import CFG

7

8

9 class Vendor:

10 def __init__(self, code):

11 self.vendor_code = code

12 self.vendor_name = ""

13 self.isbn_key = ""

14

15 def _filter_database_data(self, all_data):

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

17 try:

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

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

20 )

21 except KeyError:

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

23 sys.exit(1)

24

25 def set_vendor_data(self):

26 """Create Vendor object class"""

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

28

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

30 vendor_data = self._filter_database_data(all_data)

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

32 self.vendor_name = vendor_data["name"]

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