示例#1
0
    def testHideUnreleasedProblem(self):
        """Test that GET-ting an unreleased problem returns a 404"""
        unreleased_cid = self._setUpUnreleasedComp()

        resp = test_app.get('/api/problems/{}'.format(self.p.pid))
        self.assertEqual(404, resp.status_code)

        self._tearDownComp(unreleased_cid)
示例#2
0
    def testGetOne(self):
        """Test getting just one blog post"""
        post =  self._insert_test_post()[0]
        post_id = post.id

        response = json.loads(test_app.get('/api/blog/{}'.format(post_id))
                              .data.decode())
        post_response = response['data']

        self.assertEqual(200, response['status'])
        self._assert_posts_equal(post_response, post)

        session.delete(post)
        session.commit()
示例#3
0
    def testHideUnreleasedProblems(self):
        """
        Test that GET-ting all problems doesn't return unreleased problems
        """
        unreleased_cid = self._setUpUnreleasedComp()

        resp = test_app.get('/api/problems')
        self.assertEqual(200, resp.status_code)
        rv = json.loads(resp.data.decode())['data']

        # Test problem should be hidden
        for prob in rv:
            self.assertNotEqual(self.p.pid, prob['pid'])

        self._tearDownComp(unreleased_cid)
示例#4
0
    def testGetAll(self):
        """Test getting all the blog posts"""
        # Put some posts in the test database
        posts = self._insert_test_post(3)
        post_ids = [post.id for post in posts]

        response = json.loads(test_app.get('/api/blog').data.decode())
        post_response = response['data']

        self.assertEqual(200, response['status'])
        for (resp, post) in zip(post_response, posts):
            self._assert_posts_equal(resp, post)

        for post in posts:
            session.delete(post)
        session.commit()
示例#5
0
    def testGetOneComp(self):
        """Test retrieving a single competition by id"""
        competition = self._insert_comp_into_db()[0]

        response = test_app.get('/api/competitions/{}'.format(competition.cid))
        self.assertIsNotNone(response)
        self.assertEqual(200, response.status_code)
        response_body = json.loads(response.data.decode())['data']

        self.assertEqual(competition.cid, response_body['competition']['cid'])
        self.assertIn('compProblems', response_body)
        self.assertIn('competition', response_body)
        self.assertIn('teams', response_body)
        self.assertEqual(competition.to_dict(), response_body['competition'])

        session.delete(competition)
        session.commit()
示例#6
0
    def testGetOne(self):
        """Should get detailed info about one specific problem"""
        resp = test_app.get("/api/problems/" + str(test_problem["pid"]))
        self.assertEqual(200, resp.status_code)

        rv = json.loads(resp.data)
        self.assertFalse("Please log in" in str(rv))

        # Time limit doesn't get returned from the API, so take it out of our
        # validation
        data_validate = copy.deepcopy(test_problem_data)
        data_validate.pop("time_limit")

        prob = rv["data"]
        for key in test_problem:
            self.assertEqual(str(test_problem[key]), str(prob[key]))
        for key in data_validate:
            self.assertEqual(str(test_problem_data[key]), str(prob[key]))
示例#7
0
    def testGetAllComp(self):
        """Test retrieving all competitions"""
        competitions = self._insert_comp_into_db(3)

        response = test_app.get('/api/competitions')
        response_body = json.loads(response.data.decode())['data']

        self.assertEqual(200, response.status_code)
        all_comps = (response_body['ongoing'] + response_body['upcoming'] +
                     response_body['past'])
        for competition in competitions:
            self.assertIn(
                competition.to_dict(),
                all_comps
            )

        for competition in competitions:
            session.delete(competition)
        session.commit()
示例#8
0
    def testGetAll(self):
        """Should get basic info about all the problems"""
        # Check that the request went through
        resp = test_app.get("/api/problems")
        self.assertEqual(200, resp.status_code)
        rv = json.loads(resp.data)
        self.assertFalse("Please log in" in str(rv))

        # Find the test problem in the list returned
        found = None
        for prob in rv["data"]:
            if prob["pid"] == test_problem["pid"]:
                found = prob

        self.assertTrue(len(rv["data"]) > 0)
        self.assertFalse(found is None)

        # All the original values should be maintained
        for k in test_problem:
            self.assertEqual(str(test_problem[k]), str(found[k]))
示例#9
0
    def testGetCompTeams(self):
        """Test retreiving the teams for a competition"""
        competition = self._insert_comp_into_db()[0]
        cid = competition.cid
        user = CompUser(cid=cid, username=self.username, team='Team Test')
        user.commit_to_session(session)

        response = test_app.get('/api/competitions/{}/teams'.format(cid))
        self.assertEqual(200, response.status_code)
        response_data = json.loads(response.data.decode())['data']

        self.assertIn('Team Test', response_data)
        self.assertEqual(
            self.username,
            response_data['Team Test'][0]['username']
        )

        session.delete(user)
        session.delete(competition)
        session.commit()
示例#10
0
def test_ajax_request_does_work():
    res = test_app.get('/ajax_only', xhr=True)
    assert res.status == '200 OK'
    assert res.ubody == 'success'
示例#11
0
def test_normal_request_returns_400():
    res = test_app.get('/ajax_only', expect_errors=True)
    assert res.status_int == 400
示例#12
0
def _logout():
    rv = json.loads(test_app.get("/api/logout").data)
    assert 200 == rv["status"]
示例#13
0
文件: util.py 项目: AuburnACM/auacm
 def logout(self):
     """Log the test user out of the app"""
     response = json.loads(test_app.get('/api/logout').data.decode())
     assert 200 == response['status']