From 0ed9cbc3eda00524a25647b3a9d3a5c3514bcd6d Mon Sep 17 00:00:00 2001 From: Rajdeep Dua Date: Tue, 11 Feb 2014 17:54:54 +0530 Subject: [PATCH] Split TestPolicyApi into multiple tests Change-Id: I41af7f3b1f9323190ced3fd5ddf90c448afe3e7d --- congress/tests/functional/test_api.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/congress/tests/functional/test_api.py b/congress/tests/functional/test_api.py index da9bdf4a6..9331361f7 100755 --- a/congress/tests/functional/test_api.py +++ b/congress/tests/functional/test_api.py @@ -260,15 +260,14 @@ class TestTablesApi(AbstractApiTest): class TestPolicyApi(AbstractApiTest): API_SERVER_PATH = os.path.join(SRC_PATH, 'server', 'server.py') - def test_policy(self): - """Test table list API method.""" - # POST + def test_post_not_implemented(self): self.hconn.request('POST', '/policy') r = self.hconn.getresponse() body = self.check_response(r, 'POST policy', status=httplib.NOT_IMPLEMENTED, content_type=None) + def test_get_empty_policy(self): empty_policy = {'rules': []} # Get (empty) self.hconn.request('GET', '/policy') @@ -277,26 +276,25 @@ class TestPolicyApi(AbstractApiTest): self.assertEqual(body, empty_policy, 'Get policy (empty) returns empty ruleset') - # Update - fake_policy = {'rules': ["foo", "bar"]} + def test_update_policy(self): + empty_policy = {"rules": []} + fake_policy = {"rules": ["foo", "bar"]} self.hconn.request('PUT', '/policy', json.dumps(fake_policy)) r = self.hconn.getresponse() body = self.check_json_response(r, 'Update policy') self.assertEqual(body, fake_policy, 'Update policy returns new policy') - # Get self.hconn.request('GET', '/policy') - r = self.hconn.getresponse() - body = self.check_json_response(r, 'Get policy') - self.assertEqual(body, fake_policy, 'Get policy returns new policy') + body = self.hconn.getresponse().read() + body_json = json.loads(body) + self.assertEqual(body_json["rules"], fake_policy["rules"]) - # Delete + def test_delete_policy(self): self.hconn.request('DELETE', '/policy') r = self.hconn.getresponse() body = self.check_response(r, 'DELETE policy', status=httplib.NOT_IMPLEMENTED, content_type=None) - if __name__ == '__main__': unittest.main(verbosity=2)