test_pricefetch.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from partmgr_tstlib import *
  2. from partmgr.pricefetch import *
  3. class Test_Pricefetch(TestCase):
  4. def test_reichelt(self):
  5. testData = (
  6. ("RAD 1/63", PriceFetcher.Result.FOUND),
  7. ("RAD 1/42", PriceFetcher.Result.NOTFOUND),
  8. (" RAD 1.000/63 ", PriceFetcher.Result.FOUND),
  9. )
  10. self.__runPriceFetchTest("reichelt", testData)
  11. @unittest.skip("Conrad fetcher is currently broken")
  12. def test_conrad(self):
  13. testData = (
  14. ("405132 - 62", PriceFetcher.Result.FOUND),
  15. ("405132", PriceFetcher.Result.FOUND),
  16. ("9999999 - 99", PriceFetcher.Result.NOTFOUND),
  17. ("9999999", PriceFetcher.Result.NOTFOUND),
  18. ("405191", PriceFetcher.Result.FOUND),
  19. ("405191 - 62", PriceFetcher.Result.FOUND),
  20. ("408042 - 62", PriceFetcher.Result.FOUND),
  21. ("408042", PriceFetcher.Result.FOUND),
  22. )
  23. self.__runPriceFetchTest("conrad", testData)
  24. @unittest.skip("Pollin fetcher is currently broken")
  25. def test_pollin(self):
  26. testData = (
  27. ("702 737", PriceFetcher.Result.FOUND),
  28. ("94-702737", PriceFetcher.Result.FOUND),
  29. (" 94-702 737 ", PriceFetcher.Result.FOUND),
  30. ("99-999 999", PriceFetcher.Result.NOTFOUND),
  31. ("000 000", PriceFetcher.Result.NOTFOUND),
  32. ("94-702 737", PriceFetcher.Result.FOUND),
  33. ("711 677", PriceFetcher.Result.FOUND),
  34. )
  35. self.__runPriceFetchTest("pollin", testData)
  36. def __runPriceFetchTest(self, name, testData):
  37. fetcher = PriceFetcher.get(name)()
  38. for i, res in enumerate(fetcher.getPrices(d[0] for d in testData)):
  39. print(f"getPrices() result: {res}")
  40. orderCode, expectedStatus = testData[i]
  41. self.assertEqual(res.status, expectedStatus)
  42. self.assertEqual(res.orderCode, orderCode.strip())
  43. if expectedStatus == PriceFetcher.Result.FOUND:
  44. self.assertTrue(res.price > 0.0)
  45. self.assertEqual(res.currency, Param_Currency.CURR_EUR)