Пример #1
0
def test_negative_test_cases():

    assert get_matching_meals(meal_data, []) == []
    assert get_matching_meals(meal_data, None) == []
    assert get_matching_meals(None, None) == []
    assert get_matching_meals(None, [11]) == []
    assert get_matching_meals([], [11]) == []
    assert get_matching_meals(
        [{}], [11]) == "'meal_id key is not present in meal_data'"

    assert get_matching_meals([
        {"id": 1,"foods": [{"food_id": 1,"food_name": "Idli"},{"food_id": 10,"food_name": "Sambar"}]}], [11]) == \
        "'meal_id key is not present in meal_data'"

    assert get_matching_meals([
        {"meal_id": 1, "food": [{"food_id": 1, "food_name": "Idli"},
                                {"food_id": 10, "food_name": "Sambar"}]}], [11]) == \
                                    "'foods key is not present in meal_data'"

    assert get_matching_meals([
        {"meal_id": 1, "foods": [{"id": 1, "food_name": "Idli"},
                                {"id": 10, "food_name": "Sambar"}]}], [11]) == \
                                "'food_id key is not present in meal_data[foods]'"

    assert get_matching_meals([
        {"id": 1, "foods": [{"food_id": 1, "food_name": "Idli"}, {"food_id": 10, "food_name": "Sambar"}]}], []) == \
           []
Пример #2
0
 def test(self):
     self.assertEqual(get_matching_meals(meal_data=meal_data, food_ids=[1]),
                      [1, 2, 3])
     self.assertEqual(
         get_matching_meals(meal_data=meal_data, food_ids=[11]), [2, 3])
     self.assertEqual(
         get_matching_meals(meal_data=meal_data, food_ids=[1, 10]), [1, 3])
Пример #3
0
def test_positive():
    assert get_matching_meals(meal_data, [1, 10]) == [1, 3]
    assert get_matching_meals(meal_data, [1]) == [1, 2, 3]
    assert get_matching_meals(meal_data, [11]) == [2, 3]
    assert get_matching_meals(meal_data, [10]) == [1, 3, 4]
    assert get_matching_meals(meal_data, [1, 11]) == [2, 3]
    assert get_matching_meals(meal_data, [1, 10, 11]) == [3]
Пример #4
0
def get_meal_id():
    try:
        data = request.data
        logging.debug(json.loads(data))
        data = json.loads(data)
        if not data:
            raise ValidationError("meal_data and food_ids are missing in request body", status.HTTP_400_BAD_REQUEST)

        meal_data = validate_keys(data, 'meal_data', list)
        food_ids = validate_keys(data, 'food_ids', list)
        meal_ids = get_matching_meals(meal_data, food_ids)
        if type(meal_ids) != list:
            raise KeyError(meal_ids, status.HTTP_400_BAD_REQUEST)

        logging.debug(json.dumps({"meal_ids": meal_ids, "status": "Success"}))
        response = Response(
            response=json.dumps({"meal_ids": meal_ids, "status": "Success"}),
            status=status.HTTP_200_OK,
            mimetype='application/json'
        )
        return response
    except ValidationError as error:
        logging.debug(json.dumps({"error_message": error.msg, "status": "Failed"}))
        return Response(
            response=json.dumps({"error_message": error.msg, "status": "Failed"}),
            status=error.status_code,
            mimetype='application/json'
        )
    except KeyError as error:
        logging.debug(json.dumps({"error_message": str(error.msg), "status": "Failed"}))
        return Response(
            response=json.dumps({"error_message": str(error.msg), "status": "Failed"}),
            status=status.HTTP_400_BAD_REQUEST,
            mimetype='application/json'
        )

    except Exception as _:
        logging.debug(json.dumps({"error_message": "Internal Server Error"}))
        return Response(
            response=json.dumps({"error_message": "Internal Server Error"}),
            status=status.HTTP_500_INTERNAL_SERVER_ERROR,
            mimetype='application/json'
        )
Пример #5
0
 def test_meallist_get_no_output(self):
     self.food_ids = [110]
     self.expected = "No matching data found"
     rv = get_matching_meals(self.meallist, self.food_ids)
     self.assertCountEqual(rv, self.expected)
Пример #6
0
 def test_meallist_get_empty(self):
     self.food_ids = []
     self.expected = "Meal or food data missing(cannot be blank)"
     rv = get_matching_meals(self.meallist, self.food_ids)
     self.assertCountEqual(rv, self.expected, "success")
Пример #7
0
 def test_meallist_get_3combo(self):
     self.food_ids = [1, 10, 11]
     self.expected = [3]
     rv = get_matching_meals(self.meallist, self.food_ids)
     self.assertCountEqual(rv, self.expected, "success")
Пример #8
0
 def test_meallist_get_no_keyError_mealid(self):
     self.food_ids = [1]
     self.meallist[0]['meal_i'] = self.meallist[0].pop('meal_id')
     self.expected = "key 'meal_id' is missing"
     rv = get_matching_meals(self.meallist, self.food_ids)
     self.assertCountEqual(rv, self.expected)
Пример #9
0
 def test_meallist_get_no_otherids(self):
     self.food_ids = [2]
     self.expected = [4]
     rv = get_matching_meals(self.meallist, self.food_ids)
     self.assertCountEqual(rv, self.expected)