コード例 #1
0
 def test_get_meals_search_by(self):
     expected = 'Chicken'  # Note that this is dangerous, test can start to fail if new meals are added or change positions
     client = meal_db.MealDBClient(key=API_KEY, api_base_url=BASE_URL)
     df_response = client.get_meals_search_by(search_type='meal_name',
                                              search_value='chicken',
                                              output_type='pandas')
     response = df_response.strCategory.loc[0]
     self.assertEqual(response, expected)
コード例 #2
0
 def test_get_meals_filter_by(self):
     expected = 'Brown Stew Chicken'  # Note that this is dangerous, test can start to fail if new meals are added or change positions
     client = meal_db.MealDBClient(key=API_KEY, api_base_url=BASE_URL)
     df_response = client.get_meals_filter_by(filter_type='ingredient',
                                              filter_value='chicken',
                                              n_meals=1,
                                              output_type='pandas')
     response = df_response.strMeal.loc[0]
     self.assertEqual(response, expected)
コード例 #3
0
 def test_list_filter_values(self):
     list_expected = [
         'Beef', 'Breakfast', 'Chicken', 'Dessert', 'Goat', 'Lamb',
         'Miscellaneous', 'Pasta', 'Pork', 'Seafood', 'Side', 'Starter',
         'Vegan', 'Vegetarian'
     ]
     client = meal_db.MealDBClient(key=API_KEY, api_base_url=BASE_URL)
     list_response = client.list_filter_values(filter_type='category')
     self.assertEqual(list_response, list_expected)
コード例 #4
0
    def test_connect_api_fail(self):
        responses.add(
            responses.GET,
            'https://www.themealdb.com/api/json/v1/1/filter.php?c=Sea',
            json={'error': 'not found'},
            status=404)

        endpoint = '/filter.php?c=Sea'
        client = meal_db.MealDBClient(key=API_KEY)
        client_response = client._connect_api(endpoint)
        self.assertEqual(client_response.status_code, 404)
コード例 #5
0
ファイル: cli.py プロジェクト: lauragualda/data-engineering
def random(key_config, n_meals, csv_path, debug):
    if debug:
        logging.getLogger().setLevel(logging.DEBUG)

    key = _load_config(json_path=key_config)['api_key']
    client = meal_db.MealDBClient(key)
    try:
        client.get_meals_random(int(n_meals),
                                output_type='csv',
                                csv_path=csv_path)
        logging.info('Successfully pulled data from API.')
    except Exception as err:
        logging.error('Pulling data process failed.', extra={'error': err})
        sys.exit(err)
コード例 #6
0
 def test_connect_random_endpoint(self):
     expected = 5
     client = meal_db.MealDBClient(key=API_KEY, api_base_url=BASE_URL)
     df_response = client.get_meals_random(n_meals=5, output_type='pandas')
     response = len(df_response)
     self.assertEqual(response, expected)