Exemple #1
0
 def _list_problems(args):
     prob_getter = ProblemGetter(db_gateway=DjangoGateway(),
                                 presenter=CliPresenter())
     kwargs = {}
     if args.filter_name:
         kwargs['name_substr'] = args.filter_name
     if args.filter_tags_all:
         kwargs['tags_all'] = args.filter_tags_all
     if args.filter_tags_any:
         kwargs['tags_any'] = args.filter_tags_any
     if args.sort_by:
         kwargs['sorted_by'] = args.sort_by
     prob_getter.list_problems(**kwargs)
Exemple #2
0
    def test_get_knowledge_status(self, mock_get_knowledge_status,
                                  mock_get_problems):
        """ test that all data is retrieved, including unlogged problems """
        problem_df = pd.DataFrame(
            data={
                'difficulty': [Difficulty.EASY] * 2,
                'problem': ['problem_1', 'unlogged_problem'],
                'problem_id': [1, 2],
                'tags': ['tag_1, tag_2', 'unlogged_tag'],
                'url': ['some_url.com'] * 2
            })

        knowledge_status = pd.DataFrame(
            data={
                'difficulty': [Difficulty.EASY] * 3,
                'problem': ['problem_1', 'problem_1', 'unlogged_problem'],
                'problem_id': [1, 1, 2],
                'url': ['some_url.com'] * 3,
                'ease': [1, 1, np.nan],
                'interval': [2, 2, np.nan],
                'KS': [5, 5, np.nan],
                'result': ['KNEW_BY_HEART', 'KNEW_BY_HEART', np.nan],
                'RF': [1, 1, np.nan],
                'tag': ['tag_1', 'tag_2', 'unlogged_tag'],
                'ts_logged': [self.time_1, self.time_1, np.nan]
            })

        expected_res = pd.DataFrame(
            data={
                'difficulty': [Difficulty.EASY] * 2,
                'problem': ['problem_1', 'unlogged_problem'],
                'problem_id': [1, 2],
                'url': ['some_url.com'] * 2,
                'KS': [5., 0.],
                'RF': [1, np.nan],
                'tags': ['tag_1, tag_2', 'unlogged_tag']
            })

        mock_get_problems.return_value = problem_df
        mock_get_knowledge_status.return_value = knowledge_status
        p_g = ProblemGetter(db_gateway=Mock(), presenter=Mock())

        # call
        p_g.list_problems()

        res = p_g.presenter.list_problems.call_args[0][0]

        assert_frame_equal(expected_res, res, check_like=True)