Example #1
0
    def test_should_query_webdriver(self):
        import os
        # import pandas as pd
        from products import Product
        ProductDatabase.clear_database()
        filename = 'test.json'

        extractor = PageExtractor('submarino')
        products_list = extractor.query_webdriver("goblet of fire")
        products = [Product(item_attrs) for item_attrs in products_list]
        extractor.store_products_on_json(products, filename)
        # import pdb; pdb.set_trace()
        filtered_products = ProductDatabase.filter(price__gte=700,
                                                   price__lt=1000)
        extractor.store_products_on_json(filtered_products,
                                         'test_filtered.json')

        # df = pd.DataFrame({
        #     'name': [prod.name for prod in filtered_products],
        #     'price': [prod.price for prod in filtered_products]
        # })

        assert os.path.exists(filename) == True
        # We cant check it like this since the add_product on ProductDatabase checks whether the product was already inserted
        # assert len(products_list) == ProductDatabase.get_products_total()
        assert ProductDatabase.get_products_total() != 0
Example #2
0
    def test_should_store_products_on_json(self, store, query):
        import os
        ProductDatabase.clear_database()
        filename = 'test.json'

        extractor = PageExtractor(store)
        products_list = extractor.retrieve_products_from_query(query)
        extractor.store_products_on_json(products_list, filename)

        # import pdb; pdb.set_trace()
        assert os.path.exists(filename) == True
        # Cannot check for equal because there might be items repited which were not inserted in the database
        assert len(products_list) >= ProductDatabase.get_products_total()