tests updated Signed-off-by: Imesh Gunaratne <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/dfb6a246 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/dfb6a246 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/dfb6a246 Branch: refs/heads/stratos-4.1.x Commit: dfb6a246da2fe5180b6f785e4a269677706487de Parents: 1762e6c Author: Milindu Sanoj Kumarage <[email protected]> Authored: Tue Aug 18 00:02:23 2015 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Oct 13 16:32:50 2015 +0530 ---------------------------------------------------------------------- .../src/main/python/tests/test_print.py | 33 ------ .../python/tests/test_printable_tree_print.py | 114 ------------------- .../src/main/python/tests/test_stratos_utils.py | 97 ++++++++++++++++ 3 files changed, 97 insertions(+), 147 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/dfb6a246/components/org.apache.stratos.python.cli/src/main/python/tests/test_print.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cli/src/main/python/tests/test_print.py b/components/org.apache.stratos.python.cli/src/main/python/tests/test_print.py deleted file mode 100644 index 8d0b5aa..0000000 --- a/components/org.apache.stratos.python.cli/src/main/python/tests/test_print.py +++ /dev/null @@ -1,33 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -import sys -import unittest -from cli import Utils - - -class MyTestCase(unittest.TestCase): - def test_something(self): - tree = Utils.PrintableTree( - """[{"id":"network-partition-2","partitions":[{"id":"partition-2","partitionMax":0,"property":[{"name":"region","value":"default"}],"public":false},{"id":"partition-3","partitionMax":0,"property":[{"name":"region","value":"default"}],"public":false}]},{"id":"network-partition-1","partitions":[{"id":"partition-1","partitionMax":0,"property":[{"name":"region","value":"default"}],"public":false}]}]""") - tree.print_tree() - output = "hello world!" - self.assertEqual(output, 'hello world!') - - -if __name__ == '__main__': - unittest.main() http://git-wip-us.apache.org/repos/asf/stratos/blob/dfb6a246/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py b/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py deleted file mode 100644 index d22139b..0000000 --- a/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py +++ /dev/null @@ -1,114 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -from cli import Stratos -from cli import Configs -import responses - - -class TestClass: - - def __init__(self): - pass - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_400(): - responses.add(responses.GET, Configs.stratos_api_url, - body='', status=400, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} - - @staticmethod - @responses.activate - def test_http_get_handler_on_200(): - responses.add(responses.GET, Configs.stratos_api_url, - body='{"keyOne": "valueOne"}', status=200, - content_type='application/json') - - r = Stratos.get("") - - assert r == {"keyOne": "valueOne"} http://git-wip-us.apache.org/repos/asf/stratos/blob/dfb6a246/components/org.apache.stratos.python.cli/src/main/python/tests/test_stratos_utils.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cli/src/main/python/tests/test_stratos_utils.py b/components/org.apache.stratos.python.cli/src/main/python/tests/test_stratos_utils.py new file mode 100644 index 0000000..85acb4b --- /dev/null +++ b/components/org.apache.stratos.python.cli/src/main/python/tests/test_stratos_utils.py @@ -0,0 +1,97 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import unittest +from cli import Stratos +from cli import Configs +from cli.exceptions import BadResponseError +import responses + + +class MyTestCase(unittest.TestCase): + + + @responses.activate + def test_http_get_handler_on_200(self): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.post("") + + assert r == {"keyOne": "valueOne"} + + @responses.activate + def test_http_get_handler_on_400(self): + responses.add(responses.GET, Configs.stratos_api_url, + body='', status=400, + content_type='application/json') + + self.assertRaises(BadResponseError, Stratos.get("")) + + @responses.activate + def test_http_get_handler_on_404(self): + responses.add(responses.GET, Configs.stratos_api_url, + body='', status=404, + content_type='application/json') + + self.assertRaises(BadResponseError, Stratos.get("")) + + @responses.activate + def test_http_get_handler_on_500(self): + responses.add(responses.GET, Configs.stratos_api_url, + body='', status=500, + content_type='application/json') + + self.assertRaises(BadResponseError, Stratos.get("")) + + @responses.activate + def test_http_post_handler_on_200(self): + responses.add(responses.POST, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.post("") + + assert r is True + + @responses.activate + def test_http_post_handler_on_400(self): + responses.add(responses.POST, Configs.stratos_api_url, + body='', status=400, + content_type='application/json') + + self.assertRaises(BadResponseError, Stratos.post("")) + + @responses.activate + def test_http_post_handler_on_404(self): + responses.add(responses.POST, Configs.stratos_api_url, + body='', status=404, + content_type='application/json') + + self.assertRaises(BadResponseError, Stratos.post("")) + + @responses.activate + def test_http_post_handler_on_500(self): + responses.add(responses.POST, Configs.stratos_api_url, + body='', status=500, + content_type='application/json') + + self.assertRaises(BadResponseError, Stratos.post("")) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file
