示例#1
0
 def _show_problem_history(cls, _):
     problem_name = cls._get_problem_name()
     prob_getter = ProblemGetter(db_gateway=DjangoGateway(),
                                 presenter=CliPresenter())
     try:
         prob_getter.show_problem_history(name=problem_name)
     except ValueError as err:
         print(err)
示例#2
0
    def _list_tags(args):
        kwargs = {}
        if args.filter:
            kwargs['sub_str'] = args.filter
        if args.sort_by:
            kwargs['sorted_by'] = args.sort_by

        tag_getter = TagGetter(db_gateway=DjangoGateway(),
                               presenter=CliPresenter())
        tag_getter.list_tags(**kwargs)
示例#3
0
 def _list_problem_tag_combos(args):
     kwargs = {}
     if args.sort_by:
         kwargs['sorted_by'] = args.sort_by
     if args.filter_tags:
         kwargs['tag_substr'] = args.filter_tags
     if args.filter_problems:
         kwargs['problem_substr'] = args.filter_problems
     prob_getter = ProblemGetter(db_gateway=DjangoGateway(),
                                 presenter=CliPresenter())
     prob_getter.list_problem_tag_combos(**kwargs)
示例#4
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)
示例#5
0
 def _add_problem(cls, _):
     """Record a new problem"""
     prob_adder = ProblemAdder(db_gateway=DjangoGateway(),
                               presenter=CliPresenter())
     user_input = cls._record_problem_data()
     try:
         prob_adder.add_problem(difficulty=user_input['difficulty'],
                                url=user_input['url'],
                                name=user_input['name'],
                                tags=cls._get_tags_from_user())
     except ValueError as err:
         print(err)
         return
    def test_create_problem(self):
        dgw = DjangoGateway()
        problem = dgw.create_problem(problem=self.problem)
        self.assertIsInstance(problem, Problem)
        self.assertEqual(problem.name, 'test_problem')

        orm_problems = OrmProblem.objects.all()
        self.assertEqual(orm_problems.count(), 1)

        orm_problem = orm_problems.first()
        self.assertEqual(orm_problem.name, 'test_problem')
        self.assertNotEqual(orm_problem.pk,
                            99)  # pk is independent of problem_id
        self.assertEqual(orm_problem.url, 'https://testurl.com')
        self.assertEqual([t.name for t in orm_problem.tags.all()], ['tag1'])
示例#7
0
    def _add_problem_log(cls, _):
        """Log the execution of a problem"""
        problem_name = cls._get_problem_name()
        try:
            result = cls._get_user_input_result()
        except ValueError as err:
            print(f"\nSupplied invalid Result!\n{err}")
            return
        comment = cls._get_comment()

        prob_logger = ProblemLogger(db_gateway=DjangoGateway(),
                                    presenter=CliPresenter())
        try:
            prob_logger.log_problem(comment=comment,
                                    problem_name=problem_name,
                                    result=result,
                                    tags=cls._get_tags_from_user())
        except ValueError as err:
            print(err)
    def test_create_problem_log(self):
        dgw = DjangoGateway()
        ts = dt.datetime(2021, 3, 6, 10, 0, tzinfo=tzlocal())
        log = ProblemLogCreator.create(
            comment='test comment',
            problem_id=1,
            result=Result.SOLVED_OPTIMALLY_IN_UNDER_25,
            tags=[TagCreator.create(name=self.tag.name)],
            timestamp=ts)

        dgw.create_problem_log(problem_log=log)

        self.assertEqual(OrmProblemLog.objects.count(), 1)

        orm_log = OrmProblemLog.objects.first()
        self.assertEqual(orm_log.problem.name, 'testname')
        self.assertEqual(orm_log.result,
                         Result.SOLVED_OPTIMALLY_IN_UNDER_25.value)
        self.assertEqual(orm_log.tags.count(), 1)
        self.assertEqual(orm_log.tags.first().name, 'test-tag')
        self.assertEqual(orm_log.timestamp, ts)
        self.assertEqual(orm_log.comment, 'test comment')
示例#9
0
 def _add_tag(cls, _):
     """Create new Tag"""
     tag_adder = TagAdder(db_gateway=DjangoGateway(),
                          presenter=CliPresenter())
     tag_adder.add_tag(name=cls._clean_input(input('Tag name: ')))