示例#1
0
class TestSchemaOrg(unittest.TestCase):
    def setUp(self):
        with open("tests/test_data/schemaorg.testhtml",
                  encoding="utf-8") as pagedata:
            self.schema = SchemaOrg(pagedata.read())

    def test_total_time_with_schema_missing_all_data_should_raise_exception(
            self):
        keys = ["totalTime", "cookTime", "prepTime"]
        for k in keys:
            if k in self.schema.data:
                del self.schema.data[k]
        with self.assertRaises(SchemaOrgException):
            self.assertEqual(self.schema.total_time(), None)

    def test_total_time_with_schema__all_zeros(self):
        keys = ["totalTime", "cookTime", "prepTime"]
        for k in keys:
            self.schema.data[k] = "PT0M"
        self.assertEqual(self.schema.total_time(), 0)
        del self.schema.data["totalTime"]
        self.assertEqual(self.schema.total_time(), 0)

    def test_graph_schema_without_context(self):
        with open("tests/test_data/schemaorg_graph.testhtml",
                  encoding="utf-8") as pagedata:
            schema = SchemaOrg(pagedata.read())
        self.assertNotEqual(schema.data, {})
示例#2
0
    def setUp(self):
        # tests are run from tests.py
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'test_data',
                             'allrecipes.testhtml')) as file_opened:
            self.harvester_class = SchemaOrg(file_opened, test=True)

        patcher = patch(
            "recipe_scrapers.tests.test_allrecipes.harvester_class",
            create=True,
            return_value=self.harvester_class,
        )
        self.ars = ars()

        self.ars.setUp()
        patcher.start()
        self.addCleanup(patcher.stop)
示例#3
0
 def __init__(self, page_data, url=None):
     self.wild_mode = False
     self.meta_http_equiv = False
     self.soup = BeautifulSoup(page_data, "html.parser")
     self.url = url
     self.recipe = None
     try:
         self.schema = SchemaOrg(page_data)
     except (JSONDecodeError, AttributeError):
         pass
示例#4
0
class TestSchemaOrg(unittest.TestCase):
    def setUp(self):
        with open("tests/test_data/schemaorg.testhtml", encoding="utf-8") as pagedata:
            self.schema = SchemaOrg(pagedata.read(), None)

    def test_total_time_with_schema_missing_all_data(self):
        keys = ["totalTime", "cookTime", "prepTime"]
        for k in keys:
            if k in self.schema.data:
                del self.schema.data[k]
        self.assertEqual(self.schema.total_time(), 0)
示例#5
0
 def __init__(self, page_data, url=None):
     self.wild_mode = False
     # self.exception_handling = None  # TODO add new method here, old one was deprecated
     self.meta_http_equiv = False
     self.soup = BeautifulSoup(page_data, "html.parser")
     self.url = url
     self.recipe = None
     try:
         self.schema = SchemaOrg(page_data)
     except (JSONDecodeError, AttributeError):
         pass
示例#6
0
class TestSchemaOrgScraper(TestCase):
    def setUp(self):
        # tests are run from tests.py
        with open(
                os.path.join(os.path.dirname(os.path.realpath(__file__)),
                             'test_data',
                             'allrecipes.testhtml')) as file_opened:
            self.harvester_class = SchemaOrg(file_opened, test=True)

        patcher = patch(
            "recipe_scrapers.tests.test_allrecipes.harvester_class",
            create=True,
            return_value=self.harvester_class,
        )
        self.ars = ars()

        self.ars.setUp()
        patcher.start()
        self.addCleanup(patcher.stop)

    def test_host(self):
        self.assertEqual('schema.org', self.harvester_class.host())

    def test_title(self):
        self.ars.test_title()

    def test_total_time(self):
        self.ars.test_total_time()

    def test_yields(self):
        self.ars.test_yields()

    def test_image(self):
        self.ars.test_image()

    def test_ingredients(self):
        self.ars.test_ingredients()

    def test_instructions(self):
        self.ars.test_instructions()

    def test_ratings(self):
        self.ars.test_ratings()
示例#7
0
 def setUp(self):
     with open("tests/test_data/schemaorg.testhtml",
               encoding="utf-8") as pagedata:
         self.schema = SchemaOrg(pagedata.read())
示例#8
0
 def test_graph_schema_without_context(self):
     with open("tests/test_data/schemaorg_graph.testhtml",
               encoding="utf-8") as pagedata:
         schema = SchemaOrg(pagedata.read())
     self.assertNotEqual(schema.data, {})