def test_does_openfoodfact_class_makes_category_requests(monkeypatch): def mock_request(mock): return MockResponse() monkeypatch.setattr(requests, "get", mock_request) mock_result = Openfoodfact_request.category_request("mock1", "mock2") print(mock_result) assert mock_result["mock"] == "fake"
def product_id_requester(self, category): """Makes a category request in order to fill a product id list""" product_id_list = [] i = 0 while i < dt.MAX_PAGE: category_data = Openfoodfact_request.category_request(category, i) i += 1 for dictionnary in category_data["products"]: # append product_id_list with products id product_id_list.append(dictionnary["_id"]) return product_id_list
def product_data_requester(product_id): """Makes a product request in order to gather product data""" product_data = Openfoodfact_request.product_request(product_id) return product_data