From e7dbf89f31711271e61f653e1cc7fb2c2b57cc6e Mon Sep 17 00:00:00 2001 From: antialias Date: Fri, 30 Nov 2012 18:04:13 -0500 Subject: to improve code coverage, began writing tests for leap.base.auth. --- src/leap/base/tests/test_auth.py | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/leap/base/tests/test_auth.py (limited to 'src/leap/base/tests/test_auth.py') diff --git a/src/leap/base/tests/test_auth.py b/src/leap/base/tests/test_auth.py new file mode 100644 index 00000000..a6f2ceb9 --- /dev/null +++ b/src/leap/base/tests/test_auth.py @@ -0,0 +1,57 @@ +from BaseHTTPServer import BaseHTTPRequestHandler +try: + import unittest2 as unittest +except ImportError: + import unittest + +import requests +from mock import Mock + +from leap.base import auth +from leap.base import exceptions +from leap.eip.tests.test_checks import NoLogRequestHandler +from leap.testing.basetest import BaseLeapTest +from leap.testing.https_server import BaseHTTPSServerTestCase + + +class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest): + __name__ = "leap_srp_register_test" + provider = "testprovider.example.org" + + class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler): + responses = { + '/': ['OK', ''], + } + + def do_GET(self): + path = urlparse.urlparse(self.path) + message = '\n'.join(self.responses.get( + path.path, None)) + self.send_response(200) + self.end_headers() + self.wfile.write(message) + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_srp_auth_should_implement_check_methods(self): + SERVER = "https://localhost:8443" + srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False) + + self.assertTrue(hasattr(srp_auth, "init_session"), + "missing meth") + self.assertTrue(hasattr(srp_auth, "get_registration_uri"), + "missing meth") + self.assertTrue(hasattr(srp_auth, "register_user"), + "missing meth") + + def test_srp_auth_basic_functionality(self): + SERVER = "https://localhost:8443" + srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False) + + self.assertIsInstance(srp_auth.session, requests.sessions.Session) + self.assertEqual(srp_auth.get_registration_uri(), + "https://localhost:8443/1/users.json") -- cgit v1.2.3 From 4c2f68b1158f3840f33a38a81a5fc03495d28466 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 7 Dec 2012 02:22:33 +0900 Subject: pep8 --- src/leap/base/tests/test_auth.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/leap/base/tests/test_auth.py') diff --git a/src/leap/base/tests/test_auth.py b/src/leap/base/tests/test_auth.py index a6f2ceb9..17b84b52 100644 --- a/src/leap/base/tests/test_auth.py +++ b/src/leap/base/tests/test_auth.py @@ -1,14 +1,15 @@ from BaseHTTPServer import BaseHTTPRequestHandler +import urlparse try: import unittest2 as unittest except ImportError: import unittest import requests -from mock import Mock +#from mock import Mock from leap.base import auth -from leap.base import exceptions +#from leap.base import exceptions from leap.eip.tests.test_checks import NoLogRequestHandler from leap.testing.basetest import BaseLeapTest from leap.testing.https_server import BaseHTTPSServerTestCase @@ -20,8 +21,7 @@ class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest): class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler): responses = { - '/': ['OK', ''], - } + '/': ['OK', '']} def do_GET(self): path = urlparse.urlparse(self.path) @@ -53,5 +53,6 @@ class LeapSRPRegisterTests(BaseHTTPSServerTestCase, BaseLeapTest): srp_auth = auth.LeapSRPRegister(provider=SERVER, verify=False) self.assertIsInstance(srp_auth.session, requests.sessions.Session) - self.assertEqual(srp_auth.get_registration_uri(), - "https://localhost:8443/1/users.json") + self.assertEqual( + srp_auth.get_registration_uri(), + "https://localhost:8443/1/users.json") -- cgit v1.2.3