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)
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()
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)
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()
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()
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]))
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()
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]))
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()
def test_ajax_request_does_work(): res = test_app.get('/ajax_only', xhr=True) assert res.status == '200 OK' assert res.ubody == 'success'
def test_normal_request_returns_400(): res = test_app.get('/ajax_only', expect_errors=True) assert res.status_int == 400
def _logout(): rv = json.loads(test_app.get("/api/logout").data) assert 200 == rv["status"]
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']