Пример #1
0
    def testSolutionError(self, mock_process, mock_response):
        """Test a solution that produces a runtime error"""
        mock_response.side_effect = [
            MockResponse(json=PROBLEMS_RESPONSE),
            MockResponse(json=PROBLEM_VERBOSE)]
        mock_process.return_value = MockProcess(returncode=1)
        result = auacm.problems.test_solution(['fake.py'])

        self.assertIn('runtime error', result.lower())
Пример #2
0
    def testSolutionBad(self, mock_process, mock_response):
        """Test a failing solution"""
        mock_response.side_effect = [
            MockResponse(json=PROBLEMS_RESPONSE),
            MockResponse(json=PROBLEM_VERBOSE)]
        mock_process.return_value = MockProcess(return_value='Not the answer')
        result = auacm.problems.test_solution(['fake.py'])

        self.assertIn('wrong answer', result.lower())
Пример #3
0
    def testGetScoreboardBad(self, mock_get):
        """Attepmpt toget a scoreboard from a comeptition that doesn't exist"""
        mock_get.side_effect = [
            MockResponse(json=COMPETITIONS_RESPONSE),
            MockResponse(ok=False)
        ]

        self.assertRaises(auacm.exceptions.CompetitionNotFoundError,
                          auacm.competition.get_scoreboard,
                          ['electric boogaloo'])
Пример #4
0
    def testSolutionGood(self, mock_process, mock_response):
        """Test a passing solutoin"""
        mock_response.side_effect = [
            MockResponse(json=PROBLEMS_RESPONSE),
            MockResponse(json=PROBLEM_VERBOSE)]
        answer = PROBLEM_VERBOSE['data']['sample_cases'][0]['output']
        mock_process.return_value = MockProcess(return_value=answer)
        result = auacm.problems.test_solution(['fake.py'])

        self.assertIn('passed all sample cases', result.lower())
Пример #5
0
    def testProblemVerbose(self, mock_get):
        """Get more data about a problem by specifying verbose"""
        mock_get.side_effect = [
            MockResponse(json=PROBLEMS_RESPONSE),
            MockResponse(json=PROBLEM_VERBOSE)]

        result = auacm.problems.get_problem_info(['problem 1'])
        self.assertIn('Name: Fake Problem 1', result)
        self.assertIn('Input', result)
        self.assertIn('Output', result)
        self.assertIn('Sample Case 1', result)
Пример #6
0
    def testGetScoreboardWithProblems(self, mock_get):
        """Get a scoreboard with the problem statuses"""
        mock_get.side_effect = [
            MockResponse(json=COMPETITIONS_RESPONSE),
            MockResponse(json=COMPETITION_DETAIL)
        ]

        result = auacm.competition.get_scoreboard(['-v', 'ongoing'])

        self.assertIn('A: Fake Problem A', result)
        self.assertIn('Brando The Mando: 10', result)
Пример #7
0
    def testGetOneCompetitionByName(self, mock_get):
        """Successfully get one competition by its name"""
        mock_get.side_effect = [
            MockResponse(json=COMPETITIONS_RESPONSE),
            MockResponse(json=COMPETITION_DETAIL)
        ]

        result = auacm.competition.get_comps(['ongoing'])

        self.assertIn('ongoing fake mock', result.lower())
        self.assertIn('fake problem a', result.lower())
        self.assertIn('brando the mando', result.lower())
Пример #8
0
    def testCCompiledSolutionGood(self, mock_call, mock_process,
                                  mock_response):
        """Test a compiled solution written in C that works"""
        mock_response.side_effect = [
            MockResponse(json=PROBLEMS_RESPONSE),
            MockResponse(json=PROBLEM_VERBOSE)]
        mock_call.return_value = 0
        answer = PROBLEM_VERBOSE['data']['sample_cases'][0]['output']
        mock_process.return_value = MockProcess(return_value=answer)

        result = auacm.problems.test_solution(['fake.c'])
        self.assertIn('passed all sample cases', result.lower())
Пример #9
0
    def testGetProblemById(self, mock_get):
        """Get a *single* problem by searching with the id"""
        mock_get.return_value = MockResponse(json=PROBLEMS_RESPONSE)

        result = auacm.problems.problems(['-i', '2'])
        self.assertEqual(1, len(result.splitlines()))
        self.assertIn('Fake Problem 2', result)
Пример #10
0
    def testGetAllProblems(self, mock_get):
        """Get all the problems with the most basic form of the command"""
        mock_get.return_value = MockResponse(json=PROBLEMS_RESPONSE)

        result = auacm.problems.problems()
        self.assertIn('Fake Problem 1', result)
        self.assertIn('Fake Problem 2', result)
Пример #11
0
    def testBadGetProblemId(self, mock_get):
        """Search for a problem (by id) that doesn't exist"""
        mock_get.return_value = MockResponse(json=PROBLEMS_RESPONSE)

        self.assertRaises(
            auacm.exceptions.ProblemNotFoundError,
            auacm.problems.problems, ['-i', '99999999'])
Пример #12
0
    def testGetOneCompetitionById(self, mock_get):
        """Successfully get one competition by its id"""
        mock_get.return_value = MockResponse(json=COMPETITION_DETAIL)

        result = auacm.competition.get_comps(['-i', '2'])

        self.assertIn('ongoing fake mock', result.lower())
        self.assertIn('fake problem a', result.lower())
        self.assertIn('brando the mando', result.lower())
Пример #13
0
    def testGetScoreboardGood(self, mock_get):
        """Get a valid scoreboard from a competition"""
        mock_get.return_value = MockResponse(json=COMPETITION_DETAIL)

        result = auacm.competition.get_scoreboard(['-i', '2'])
        self.assertIn(('brando the mando' + ' ' * 15)[:15], result.lower())
        self.assertIn('rank', result.lower())
        self.assertIn('solved', result.lower())
        self.assertIn('time', result.lower())
Пример #14
0
    def testWhoami(self, mock_response):
        """Successful 'whoami'"""
        mock_response.return_value = MockResponse(
            json={'data': {
                'username': '******'
            }})

        returned = auacm.user.whoami([])
        self.assertIn('username', returned)
Пример #15
0
    def testGetAllCompetitons(self, mock_get):
        """Successfully get all the competitions"""
        mock_get.return_value = MockResponse(json=COMPETITIONS_RESPONSE)

        result = auacm.competition.get_comps()

        self.assertIn('upcoming fake mock', result.lower())
        self.assertIn('ongoing fake mock', result.lower())
        self.assertIn('past fake mock', result.lower())
Пример #16
0
    def testLogin(self, mock_response, mock_file, mock_pass, mock_input):
        """Successful login"""
        mock_input.return_value = 'Username'
        mock_pass.return_value = 'password'
        mock_file.return_value = MockFile()
        mock_response.return_value = MockResponse(
            cookies={'session': 'Fake session'})

        self.assertIn('success', auacm.user.login([]).lower())
        self.assertEqual('Fake session', auacm.session)
Пример #17
0
    def testGoodSubmit(self, mock_post, mock_get, mock_open):
        """A valid submission"""
        mock_open.return_value = MockFile()
        mock_get.side_effect = [
            MockResponse(json=PROBLEMS_RESPONSE),
            MockResponse(json={'data': {
                'status': 'start'
            }}),
            MockResponse(json={'data': {
                'status': 'good'
            }})
        ]
        mock_post.return_value = MockResponse(
            json={'data': {
                'submissionId': '0'
            }})

        result = auacm.submit.submit(['problem 1', 'fake.c'], False)
        self.assertIn('running', result.lower())
        self.assertIn('correct', result.lower())
Пример #18
0
 def testBadConnection(self, mock_get):
     """Unsuccessful connection to the server"""
     mock_get.return_value = MockResponse(ok=False)
     self.assertRaises(auacm.exceptions.ConnectionError, auacm.main.test,
                       [])
Пример #19
0
 def testConnection(self, mock_get):
     """Successful connection to the server"""
     mock_get.return_value = MockResponse()
     self.assertIn('success', auacm.main.test([]))
Пример #20
0
    def testGetOneCompetitionBadName(self, mock_get):
        """Attempt to get a competition that doesn't exist by name"""
        mock_get.side_effect = [MockResponse(json=COMPETITIONS_RESPONSE)]

        self.assertRaises(auacm.exceptions.CompetitionNotFoundError,
                          auacm.competition.get_comps, ['not real'])
Пример #21
0
    def testGetOneCompetitionBad(self, mock_get):
        """Attempt to get a competition that doesn't exist"""
        mock_get.return_value = MockResponse(ok=False, status_code=404)

        self.assertRaises(auacm.exceptions.CompetitionNotFoundError,
                          auacm.competition.get_comps, ['-i', '99999999'])