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 self.failover_scraper = ""

13

14 def _filter_database_data(self, all_data):

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

16 try:

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

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

19 )

20 except KeyError:

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

22 sys.exit(1)

23

24 def set_vendor_data(self):

25 """Create Vendor object class"""

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

27

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

29 vendor_data = self._filter_database_data(all_data)

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

31 if "name" in vendor_data: 31 ↛ 33line 31 didn't jump to line 33, because the condition on line 31 was never false

32 self.vendor_name = vendor_data["name"]

33 if "isbn_key" in vendor_data: 33 ↛ 35line 33 didn't jump to line 35, because the condition on line 33 was never false

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

35 if "failover_scraper" in vendor_data:

36 self.failover_scraper = vendor_data["failover_scraper"]