Пример #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()])
Пример #2
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()
def test_minimize_score_with_worsened_symptom(integration_db):
    """
    Minimize ingredients contained in Recipe[0] are:

    saury fish:  10  (ref. 10)
    cabbage:  200  (ref. 30|200 )
    fish:  30   (ref: 20 )

    this time the formula would be:
    saury-fish (ignored) - (60 * 1.5) - (30 * 1.5)
    """
    from datetime import datetime

    integration_db.patient_symptoms.insert_one({
        'symptom_id':
        TAGS[0]['tag_id'],
        'patient_id':
        PATIENT['_id'],
        'created_at':
        datetime(2019, 10, 15),
        'updated_at':
        datetime(2019, 10, 15),
        'symptoms_scale':
        7
    })

    assert_equal_objects(
        MinimizedScore(RECIPES[0]['_id'], PATIENT['_id']).worsen_ingredients,
        ['saury fish', 'cabbage', 'fish', 'komatsuna', 'pak choi'])
    assert MinimizedScore(RECIPES[0]['_id'], PATIENT['_id']).value == -135
Пример #4
0
 def test_dicts_2(self):
     assert_equal_objects({
         'list': [3, 2],
         'age': 20
     }, {
         'list': [2, 3],
         'age': 20
     })
def test_symptoms_sorted_by_date(symptoms_progress_test_db):
    patient_id, symptom_id_1, symptom_id_2 = symptoms_progress_test_db

    assert_equal_objects(
        SymptomsProgress(patient_id).symptoms_sorted_by_date, {
            symptom_id_1: [8, 2, 3],
            symptom_id_2: [1, 5]
        })
Пример #6
0
    def test_patient_other_restriction_not_empty(self, collection_mock):
        collection_mock.find_one.return_value = {
            'other_restriction': 'Less sugar,more red meat'
        }

        assert_equal_objects(
            PatientOtherRestrictions(patient_id()).read_as_list(),
            ['less', 'sugar', 'more', 'red', 'meat'])
Пример #7
0
def test_ingredients_names_quantities(mocker):
    mocker.patch('saana_lib.recipe.Recipe.ingredients',
                 new_callable=mocker.PropertyMock,
                 return_value=[{
                     'food_ingredient_fullname': 'Lactose',
                     'quantity': 2
                 }])
    assert_equal_objects(
        Recipe(recipe_id()).ingredients_name_quantity, {'Lactose': 2})
Пример #8
0
def test_ingredients_id_prop_values(mocker):
    mocker.patch('saana_lib.recipe.Recipe.recipe',
                 new_callable=mocker.PropertyMock,
                 return_value={
                     'food': [{
                         'food_ingredient_id': 1
                     }, {
                         'food_ingredient_id': 2
                     }]
                 })
    assert_equal_objects(Recipe(recipe_id()).ingredients_id, [1, 2])
Пример #9
0
 def test_filter_prioritize_values_case_1(self, avoid_all_tags):
     avoid_all_tags.return_value = [{'avoid': ['soy', 'flax']}]
     assert_equal_objects(
         IngredientFilter.filter_prioritize(patient_id(), {
             'beets': 0,
             'flax': 1,
             'carrot': 2
         }), {
             'beets': 0,
             'carrot': 2
         })
Пример #10
0
    def test_filter_prioritize_values_case_2(self, avoid_all_tags, mocker):
        avoid_all_tags.return_value = [{'avoid': ['soy', 'flax']}]
        mocker.patch('saana_lib.patient.MinimizeIngredients.all',
                     new_callable=mocker.PropertyMock,
                     return_value={'carrot': 1})

        assert_equal_objects(
            IngredientFilter.filter_prioritize(patient_id(), {
                'beets': 0,
                'flax': 1,
                'carrot': 2
            }), {'beets': 0})
Пример #11
0
 def test_dict_5(self):
     assert_equal_objects({
         'dict': {
             'nested': {
                 'val': 1
             }
         }
     }, {
         'dict': {
             'nested': {
                 'val': 1
             }
         }
     })
Пример #12
0
 def test_filter_minimize_values_case_1(self, avoid_all_tags):
     avoid_all_tags.return_value = [{'avoid': ['soy', 'flax']}]
     assert_equal_objects(
         IngredientFilter.filter_minimize(patient_id(), {
             'soy': 0,
             'flax': 1,
             'carrot': {
                 'min1': 2,
                 'min2': 30
             }
         }), {'carrot': {
             'min1': 2,
             'min2': 30
         }})
Пример #13
0
    def test_prioritize_recommendation(self, mocker):
        """Verify the content of the list being returned"""
        mocker.patch('saana_lib.recommendation.PrioritizeIngredients.all',
                     new_callable=mocker.PropertyMock,
                     return_value={
                         "onion": 0,
                         "flax": 2
                     })
        get_ingr_mock = mocker.patch(
            'saana_lib.recommendation.Recommendation.get_or_create_ingredient')
        _ = PrioritizeRecommendation(patient_id()).as_list()

        assert_equal_objects(
            [arg[0][0] for arg in get_ingr_mock.call_args_list],
            ["onion", "flax"])
Пример #14
0
 def test_multiplier_ingredients_values(self, sorted_symptoms_mock, mocker):
     tags = mocker.patch('saana_lib.patient.db.tags')
     tags.find.return_value = [{
         'prior': {
             'milk': 2
         }
     }, {
         'prior': {
             'nuts': 0
         }
     }]
     sorted_symptoms_mock.return_value = {patient_id().__str__(): [1, 1]}
     assert_equal_objects(
         SymptomsProgress(patient_id()).better_multiplier_ingredients,
         ['milk', 'nuts'])
def test_record_is_modified(integration_db, content_iterator_mock):
    headers = 'type,name,saury fish,fish,cabbage,pak choi,komatsuna'
    content_iterator_mock.return_value = [headers, '', 'diarrhea,symptoms,,M,,,']

    matrix = Matrix()
    updated_counter = matrix.store()
    assert updated_counter == (1, {})
    diarrhea = integration_db.tags.find_one({'name': 'diarrhea'})
    assert_equal_objects(
        diarrhea['minimize'],
        {'insoluble fiber': {
            'min2': '15',
            'min1': '10'
        }, 'fish': 0}
    )
Пример #16
0
 def test_dicts_4(self):
     assert_equal_objects({
         'k1': {
             'list': [3, 2, 4]
         },
         'k2': {
             'name': 'Bob'
         }
     }, {
         'k1': {
             'list': [4, 3, 2]
         },
         'k2': {
             'name': 'Bob'
         }
     })
Пример #17
0
def test_ingredients_id_quantities_values(mocker):
    mocker.patch('saana_lib.recipe.Recipe.recipe',
                 new_callable=mocker.PropertyMock,
                 return_value={
                     'food': [{
                         'food_ingredient_id': 1,
                         'quantity': 10
                     }, {
                         'food_ingredient_id': 2,
                         'quantity': 30
                     }]
                 })
    assert_equal_objects(
        Recipe(recipe_id()).ingredients_id_quantity, {
            1: 10,
            2: 30
        })
Пример #18
0
    def test_avoid_recommendation_values(self, mocker, datetime_mock):
        """
        This test verifies both, that the correct property is called,
        and check the content values being returned
        """
        all_prop = mocker.patch('saana_lib.patient.AvoidIngredients.all',
                                new_callable=mocker.PropertyMock,
                                return_value={"onion", "flax"})
        get_ingr_mock = mocker.patch(
            'saana_lib.recommendation.Recommendation.get_or_create_ingredient')
        _ = AvoidRecommendation(patient_id()).as_list()

        assert_equal_objects(
            [arg[0][0] for arg in get_ingr_mock.call_args_list],
            ["onion", "flax"])
        all_prop.assert_called_once_with()
        assert datetime_mock.now.call_count == 4
Пример #19
0
 def test_remove_element(self):
     assert_equal_objects(
         self.matrix_obj.remove_element(
             'potato', {
                 'avoid': ['seaweed'],
                 'minimize': {
                     'potato': 2
                 },
                 'prior': {
                     'spinach': 0
                 },
             }), {
                 'avoid': ['seaweed'],
                 'minimize': {},
                 'prior': {
                     'spinach': 0
                 },
             })
Пример #20
0
def test_minimize_ingredients(mocker):
    """This test shows that filter_minimize is not
    transparent in the process.
    """
    all_tags = mocker.patch('saana_lib.patient.MinimizeIngredients.all_tags',
                            new_callable=mocker.PropertyMock,
                            return_value=[{
                                'minimize': {
                                    'soy': 2,
                                    'flax': 3,
                                    'basil': 2
                                }
                            }])
    mocker.patch('saana_lib.patient.IngredientFilter.filter_minimize',
                 return_value={})

    assert_equal_objects(MinimizeIngredients(patient_id()).all, {})
    all_tags.assert_called_once_with()
Пример #21
0
 def test_symptoms_worsen(self, sorted_symptoms_mock, mocker):
     sorted_symptoms_mock.return_value = {patient_id().__str__(): [2, 1]}
     m = mocker.patch('saana_lib.tag.db.tags')
     m.find_one.return_value = {
         'prior': {
             'burdock': 0
         },
         'minimize': {
             'spinach': 0
         },
         'avoid': {
             'okra': 0
         },
         'nutrient': {
             'vitamin': 0
         }
     }
     assert_equal_objects(
         SymptomsProgress(patient_id()).worsen,
         ['burdock', 'spinach', 'vitamin'])
def test_one_update_one_upsert(integration_db, content_iterator_mock):
    headers = 'type,name,saury fish,fish,cabbage,pak choi,komatsuna'
    content_iterator_mock.return_value = [
        headers,
        '',
        'diarrhea,symptoms,,M,,,',
        'breast,cancer,A,A,A,P-20,P-40|500',
    ]

    matrix = Matrix()
    updated_counter = matrix.store()

    assert updated_counter == (2, {})
    breast_cancer = integration_db.tags.find_one({'name': 'breast', 'type': 'cancer'})
    assert_equal_objects(
        breast_cancer['avoid'],
        ['saury fish', 'fish', 'cabbage']
    )
    assert_equal_objects(
        breast_cancer['prior'],
        {'pak choi': 20.0, 'komatsuna': {'min1': 40.0, 'min2': 500.0}}
    )
Пример #23
0
 def test_symptoms_scales_are_constants(self, sorted_symptoms_mock, mocker):
     """If the symptoms scale remain constant, they will be
     considered a good sign.
     """
     sorted_symptoms_mock.return_value = {patient_id().__str__(): [2, 2]}
     m = mocker.patch('saana_lib.tag.db.tags')
     m.find_one.return_value = {
         'prior': {
             'burdock': 0
         },
         'minimize': {
             'spinach': 0
         },
         'avoid': {
             'okra': 0
         },
         'nutrient': {
             'vitamin': 0
         }
     }
     assert_equal_objects(
         list(SymptomsProgress(patient_id()).better)[0],
         ['burdock', 'spinach', 'vitamin'])
Пример #24
0
 def test_avoid_and_other_restrictions_values(self, all_tags,
                                              other_restrictions):
     other_restrictions.return_value = ['spinach']
     assert_equal_objects(
         AvoidIngredients(patient_id()).all,
         {"broccoli", "flax", "kale", "onion", "spinach"})
Пример #25
0
 def test_tag_prioritize_sequence_quantity_range(self):
     tag = Tag(content_row=[['flax', 'P-200|300']])
     assert_equal_objects({'flax': {
         'lower': '200',
         'upper': '300'
     }}, tag.prioritize_sequence)
Пример #26
0
 def test_dict_7(self):
     base = {'a': 1, 'b': 2, 'c': 3}
     assert_equal_objects(
         [1, 2, 3],
         [v for k, v in base.items()]
     )
Пример #27
0
 def test_lists_3(self):
     assert_equal_objects([{'a': [0, 1]}], [{'a': [1, 0]}])
Пример #28
0
 def test_list_2(self):
     assert_equal_objects([1, 2], [2, 1])
Пример #29
0
 def test_strings_2(self):
     assert_equal_objects('aa', 'aa')
Пример #30
0
 def test_integers_1(self):
     assert_equal_objects(1, 1)