<commit_before>import unittest
from datetime import date

from mock import patch

from app.brain.custom_exceptions import ThisShouldNeverHappenException
from app.brain.exercises_management.rep_exercises_management import RepExercisesManagement
from app.models import RepExercisesTaxonomy, RepExercisesHistory


class RepExercisesManagementTests(unittest.TestCase):
    def setUp(self):
        history_1 = RepExercisesHistory(
            user_id=1,
            exercise_id=27,
            sets=2,
            reps=12,
            weight=45,
            date=date(year=2016, month=4, day=12)
        )
        history_2 = RepExercisesHistory(
            user_id=1,
            exercise_id=27,
            sets=2,
            reps=12,
            weight=45,
            date=date(year=2016, month=4, day=16)
        )
        history_3 = RepExercisesHistory(
            user_id=1,
            exercise_id=27,
            sets=2,
            reps=16,
            weight=40,
            date=date(year=2016, month=4, day=14)
        )
        self.history = [
            history_1,
            history_2,
            history_3
        ]

        self.history_sorted = [
            history_1,
            history_3,
            history_2
        ]

        self.exercises = [
            RepExercisesTaxonomy(
                name='c_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=False,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=False,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='e_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=True,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=False,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='b_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=False,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=True,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='a_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=True,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=False,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='d_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=False,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=True,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            )
        ]
        self.exercises[0].id = 1
        self.exercises[1].id = 2
        self.exercises[2].id = 3
        self.exercises[3].id = 4
        self.exercises[4].id = 5

    @patch(
        'app.brain.exercises_management.rep_exercises_management.RepExercisesTaxonomyService.get_list_of_all_exercises')
    def test_get_valid_id_exercise_pairs(self, taxonomy_service_mock):
        taxonomy_service_mock.return_value = self.exercises
        expected_results = [('4', 'a_exercise'), ('3', 'b_exercise'), ('1', 'c_exercise'), ('5', 'd_exercise'),
                            ('2', 'e_exercise')]
        actual_results = RepExercisesManagement.get_valid_id_exercise_pairs()
        self.assertListEqual(actual_results, expected_results)

    @patch(
        'app.brain.exercises_management.rep_exercises_management.RepExercisesHistoryService'
        '.get_user_history_by_exercise'
    )
    def test_get_user_history_by_exercise_id(self, db_mock):
        db_mock.return_value = self.history
        user_id = 1
        exercise_id = 27
        expected_results = self.history_sorted
        actual_results = RepExercisesManagement.get_user_history_by_exercise_id(user_id, exercise_id)

        # make sure contents and order the same
        self.assertListEqual(actual_results, expected_results)

        # make sure contents are in ascending date order
        self.assertListEqual(actual_results, sorted(actual_results, key=lambda x: x.date))<commit_msg>no results returned from service rep exercises management unit test<commit_after>import unittest
from datetime import date

from mock import patch

from app.brain.custom_exceptions import ThisShouldNeverHappenException
from app.brain.exercises_management.rep_exercises_management import RepExercisesManagement
from app.models import RepExercisesTaxonomy, RepExercisesHistory


class RepExercisesManagementTests(unittest.TestCase):
    def setUp(self):
        history_1 = RepExercisesHistory(
            user_id=1,
            exercise_id=27,
            sets=2,
            reps=12,
            weight=45,
            date=date(year=2016, month=4, day=12)
        )
        history_2 = RepExercisesHistory(
            user_id=1,
            exercise_id=27,
            sets=2,
            reps=12,
            weight=45,
            date=date(year=2016, month=4, day=16)
        )
        history_3 = RepExercisesHistory(
            user_id=1,
            exercise_id=27,
            sets=2,
            reps=16,
            weight=40,
            date=date(year=2016, month=4, day=14)
        )
        self.history = [
            history_1,
            history_2,
            history_3
        ]

        self.history_sorted = [
            history_1,
            history_3,
            history_2
        ]

        self.exercises = [
            RepExercisesTaxonomy(
                name='c_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=False,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=False,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='e_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=True,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=False,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='b_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=False,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=True,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='a_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=True,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=False,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            ),
            RepExercisesTaxonomy(
                name='d_exercise',
                is_back=True,
                is_chest=True,
                is_shoulders=False,
                is_biceps=True,
                is_triceps=True,
                is_legs=False,
                is_core=True,
                is_balance=False,
                is_cardio=False,
                is_weight_per_hand=True
            )
        ]
        self.exercises[0].id = 1
        self.exercises[1].id = 2
        self.exercises[2].id = 3
        self.exercises[3].id = 4
        self.exercises[4].id = 5

    @patch(
        'app.brain.exercises_management.rep_exercises_management.RepExercisesTaxonomyService.get_list_of_all_exercises')
    def test_get_valid_id_exercise_pairs(self, taxonomy_service_mock):
        taxonomy_service_mock.return_value = self.exercises
        expected_results = [('4', 'a_exercise'), ('3', 'b_exercise'), ('1', 'c_exercise'), ('5', 'd_exercise'),
                            ('2', 'e_exercise')]
        actual_results = RepExercisesManagement.get_valid_id_exercise_pairs()
        self.assertListEqual(actual_results, expected_results)

    @patch(
        'app.brain.exercises_management.rep_exercises_management.RepExercisesHistoryService'
        '.get_user_history_by_exercise'
    )
    def test_get_user_history_by_exercise_id(self, db_mock):
        db_mock.return_value = self.history
        user_id = 1
        exercise_id = 27
        expected_results = self.history_sorted
        actual_results = RepExercisesManagement.get_user_history_by_exercise_id(user_id, exercise_id)

        # make sure contents and order the same
        self.assertListEqual(actual_results, expected_results)

        # make sure contents are in ascending date order
        self.assertListEqual(actual_results, sorted(actual_results, key=lambda x: x.date))

        # make sure the service method was called
        db_mock.assert_called_once_with(user_id, exercise_id)

    @patch(
        'app.brain.exercises_management.rep_exercises_management.RepExercisesHistoryService'
        '.get_user_history_by_exercise'
    )
    def test_get_user_history_by_exercise_id_no_matches(self, db_mock):
        db_mock.return_value = []
        user_id = 1
        exercise_id = 26

        actual_results = RepExercisesManagement.get_user_history_by_exercise_id(user_id, exercise_id)
        expected_results = []

        # make sure contents and order the same
        self.assertListEqual(actual_results, expected_results)
{'fraction_non_alphanumeric': 0.07371577827222599, 'fraction_numerical': 0.014220760375350682, 'mean_word_length': 1.6238578680203046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1793851', 'n_tokens_mistral': 3211, 'n_tokens_neox': 2959, 'n_words': 435}