Ejemplo n.º 1
0
 def test_recommendations_in_time_frame_values(self, mocker):
     m = mocker.patch(
         'saana_lib.recommendation.db.patient_recipe_recommendation', )
     m.find.return_value = [{'recipe_id': obj_id()}]
     start = datetime.now()
     assert_equal_objects(self.klass.recommendations_in_time_frame(start),
                          [obj_id()])
Ejemplo n.º 2
0
def tests_cmd_line_arguments(mocker):
    args_mock = mocker.MagicMock()
    args_mock.patient_id = obj_id()
    mocker.patch('argparse.ArgumentParser.parse_args', return_value=args_mock)
    rank_class = mocker.patch('main.RankingToDatabase')
    _ = run()
    rank_class.assert_called_once_with(patient_id=obj_id())
    assert tuple(rank_class.mock_calls[1])[0] == '().store'
Ejemplo n.º 3
0
def test_two_same_recommendations_are_created(integration_db, mocker):
    """No duplicate error is raised"""

    from pymongo.collection import ObjectId

    res = integration_db.mst_food_ingredients.insert_one({
        'name': 'flax',
        'created_at': datetime.now().isoformat(),
        'updated_at': datetime.now().isoformat(),
    })

    integration_db.patient_ingredient_recommendation.insert_one({
        'patient_id': ObjectId('5cab584074e88f0cb0977a08'),
        'ingredient_id': res.inserted_id,
        'type': "min",
        'quantity': 0,
        'created_at': datetime.now().isoformat(),
        'updated_at': datetime.now().isoformat(),
    })

    mocker.patch(
        'saana_lib.patient.MinimizeIngredients.all',
        new_callable=mocker.PropertyMock,
        return_value={"flax": 0}
    )

    _ = MinimizeRecommendation(obj_id().__str__()).to_db()

    assert integration_db.patient_ingredient_recommendation.estimated_document_count() == 2
    assert integration_db.patient_ingredient_recommendation.find_one()['type'] == 'min'
Ejemplo n.º 4
0
def test_prioritize_ingredients(mocker):
    all_tags = mocker.patch('saana_lib.patient.PatientTags.all_tags',
                            new_callable=mocker.PropertyMock,
                            return_value=[{
                                'prior': {
                                    "broccoli": 0,
                                    "flax": 21,
                                }
                            }, {
                                'prior': {
                                    "kale": 0,
                                    "onion": 1,
                                    "flax": 2
                                }
                            }])

    mocker.patch('saana_lib.patient.IngredientFilter.filter_prioritize',
                 return_value={
                     "broccoli": 0,
                     "flax": 21,
                     "kale": 0,
                     "onion": 1
                 })
    assert_equal_objects(
        PrioritizeIngredients(obj_id()).all, {
            "broccoli": 0,
            "flax": 21,
            "kale": 0,
            "onion": 1
        })
    all_tags.assert_called_once_with()
Ejemplo n.º 5
0
    def test_proxy_content_to_file(self, mocker):
        """mock called three times, one for the

        """
        mock = mocker.patch('saana_lib.ranking.datetime')
        mock.now.return_value = datetime(2019, 5, 18, 15, 17, 8, 132263)

        m = mocker.patch('saana_lib.ranking.out_to_xls')
        mocker.patch('saana_lib.ranking.Ranking.compute',
                     return_value=dict((i, [{
                         'recipe_id': 'id',
                         'score': 1
                     }]) for i in range(3, 0, -1)))
        RankingToFile(obj_id()).store()
        assert m.call_count == 4
        m.assert_called_with("{}-{}".format(obj_id().__str__(), '2019-05-18'),
                             ["id", "1"])
Ejemplo n.º 6
0
    def test_one_minimize_ingredient_in_recipe(self, mocker):
        minimize_all = mocker.patch(
            'saana_lib.recommendation.MinimizeIngredients.all',
            new_callable=mocker.PropertyMock,
            return_value={
                'seaweed': {
                    'min1': 0,
                    'min2': 2
                },
                'fish': 2
            })
        ingredients_id_quantity = mocker.patch(
            'saana_lib.recipe.Recipe.ingredients_name_quantity',
            new_callable=mocker.PropertyMock,
            return_value={
                'cabbage': 20,
                'fish': 3
            })

        res = list(MinimizedScore(obj_id(), obj_id()).ingredient_set)
        assert res == [('fish', 3, 2)]
        assert ingredients_id_quantity.call_count == 1
        minimize_all.assert_called_once_with()
Ejemplo n.º 7
0
def test_nutrients(mocker):
    all_tags = mocker.patch('saana_lib.patient.Nutrients.all_tags',
                            new_callable=mocker.PropertyMock,
                            return_value=[{
                                'nutrient': {
                                    1: 2,
                                    3: 4
                                }
                            }])

    nutrient_filter = mocker.patch('saana_lib.patient.NutrientFilter.filter',
                                   return_value={})
    _ = Nutrients(obj_id()).all
    all_tags.assert_called_once_with()
    nutrient_filter.assert_called_once_with(patient_id(), {1: 2, 3: 4})
Ejemplo n.º 8
0
 def test_recommendations_in_time_frame_default_end(self, mocker):
     m = mocker.patch(
         'saana_lib.recommendation.db.patient_recipe_recommendation', )
     start = datetime.now()
     _ = self.klass.recommendations_in_time_frame(start)
     m.find.assert_called_once_with(
         {
             'patient_id': obj_id(),
             'created_at': {
                 '$lte': start,
                 "$gte": start - timedelta(days=7)
             }
         }, {
             'recipe_id': 1,
             '_id': 0
         })
Ejemplo n.º 9
0
    def test_filter_prioritize(self, mocker):
        mocker.patch('saana_lib.patient.PrioritizeIngredients.all_tags',
                     new_callable=mocker.PropertyMock,
                     return_value=[{
                         'prior': {
                             'soy': 0,
                             'flax': 2
                         }
                     }])
        filter_prioritize = mocker.patch(
            'saana_lib.patient.IngredientFilter.filter_prioritize')

        _ = PrioritizeIngredients(patient_id()).all
        filter_prioritize.assert_called_once_with(obj_id(), {
            'soy': 0,
            'flax': 2
        })
Ejemplo n.º 10
0
 def test_tag_initialisation_with_tag_id(self, mocker):
     m = mocker.patch('saana_lib.tag.db.tags')
     _ = Tag(tag_id=obj_id())
     m.find_one.assert_called_once_with({'tag_id': obj_id()})
Ejemplo n.º 11
0
 def test_recommendation_have_same_score(self, mocker):
     mocker.patch('saana_lib.recommendation.RecipeRecommendation.score',
                  new_callable=mocker.PropertyMock,
                  return_value=10)
     _ = Ranking(obj_id()).compute()
     assert len(_[10]) == 3