def test_direction_effect(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=culture&direction=asc") posts = json.loads(response.data) self.assertTrue(is_correctly_sorted(posts, "id", "asc")) response = tester.get("/api/posts?tags=culture&direction=desc") posts = json.loads(response.data) self.assertTrue(is_correctly_sorted(posts, "id", "desc"))
def test_direction_valid(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=foo&sdirection=asc") code = response.status_code self.assertEqual(code, 200) response = tester.get("/api/posts?tags=foo&direction=rise") code = response.status_code self.assertEqual(code, 400)
def test_sortBy_effect(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=culture&sortBy=id") posts = json.loads(response.data) self.assertTrue(is_correctly_sorted(posts, "id", "asc")) response = tester.get("/api/posts?tags=culture&sortBy=likes") posts = json.loads(response.data) self.assertTrue(is_correctly_sorted(posts, "likes", "asc"))
def test_sortBy_valid(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=foo&sortBy=id") code = response.status_code self.assertEqual(code, 200) response = tester.get("/api/posts?tags=foo&sortBy=author") code = response.status_code self.assertEqual(code, 400)
def test_tags_necessity(self): tester = app.test_client(self) response = tester.get("/api/posts") code = response.status_code self.assertEqual(code, 400) response = tester.get("/api/posts?tags=foo") code = response.status_code self.assertEqual(code, 200)
def test_tags_no_duplication(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=culture&direction=asc") posts = json.loads(response.data) self.assertTrue(is_not_duplicated(posts, "id"))
def test_ping(self): tester = app.test_client(self) response = tester.get("/api/ping") code = response.status_code self.assertEqual(code, 200)
def test_more_paras(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=foo,void,bar&sortBy=likes&direction=asc&author=Mike") code = response.status_code self.assertEqual(code, 200)
def test_tags_format(self): tester = app.test_client(self) response = tester.get("/api/posts?tags=foo,void,bar") code = response.status_code self.assertEqual(code, 200)