#!/usr/bin/env python3 # run from dir above changedetectionio/ dir # python3 -m unittest changedetectionio.tests.unit.test_restock_logic import unittest import os import changedetectionio.processors.restock_diff.processor as restock_diff # mostly class TestDiffBuilder(unittest.TestCase): def test_logic(self): assert restock_diff.is_between(number=10, lower=9, upper=11) == True, "Between 9 and 11" assert restock_diff.is_between(number=10, lower=0, upper=11) == True, "Between 9 and 11" assert restock_diff.is_between(number=10, lower=None, upper=11) == True, "Between None and 11" assert not restock_diff.is_between(number=12, lower=None, upper=11) == True, "12 is not between None and 11" def test_itemprop_availability_opengraph_fallback(self): """Availability/currency missing from JSON-LD should be filled from OpenGraph (Facebook commerce 'product:availability' / 'product:price:currency' meta tags).""" html_content = """

Some Product

""" value = restock_diff.get_itemprop_availability(html_content) assert value.get('price') == 155.55, "price should be found via JSON-LD" assert value.get('currency') == 'EUR', "currency should be found via OpenGraph fallback" # Normalised the same way a schema.org value is, so that the in-stock matcher # (which looks for 'instock') sees it. OpenGraph spells it 'in stock'. assert value.get('availability') == 'instock', "availability should be found via OpenGraph fallback and normalised" assert any(s in value.get('availability') for s in ['instock', 'instoreonly']), \ "a product advertised as available must read as in stock, not out of stock" if __name__ == '__main__': unittest.main()