class DatastoreBackendTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True KIND_PREFIX_IN_TEST = 't2' def setUp(self): from kay.auth import create_new_user s = LazySettings(settings_module='kay.tests.datastore_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) create_new_user("foobar", "password", is_admin=False) def tearDown(self): self.client.test_logout() def test_login(self): response = self.client.get(url_for('auth_testapp/index')) self.assertEqual(response.status_code, 200) response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 302) self.assert_(response.headers.get('Location').endswith( '/auth/login?next=http%253A%252F%252Flocalhost%252Fsecret')) self.client.test_login(username='******') response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 302)
class SessionMiddlewareWithSecureCookieTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True def setUp(self): s = LazySettings(settings_module='kay.tests.securecookie_session_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) def tearDown(self): pass def test_countup(self): response = self.client.get('/countup') self.assertEqual(response.status_code, 200) self.assertEqual(response.data, '1') response = self.client.get('/countup') self.assertEqual(response.data, '2') response = self.client.get('/countup') self.assertEqual(response.data, '3') response = self.client.get('/countup') self.assertEqual(response.data, '4') response = self.client.get('/countup') self.assertEqual(response.data, '5')
class EReporterTest(GAETestBase): def setUp(self): s = LazySettings( settings_module='kay.tests.ereporter_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) #self.client.test_logout() # Suppress logging error messages self._base_logger = logging.getLogger("") self._old_logging_handlers = self._base_logger.handlers self._base_logger.handlers = filter( lambda h: not isinstance(h, logging.StreamHandler), self._old_logging_handlers, ) def tearDown(self): self.client.test_logout() self._base_logger.handlers = self._old_logging_handlers def test_ereporter(self): from kay.ext.ereporter.models import ExceptionRecord self.assertEqual(ExceptionRecord.all().count(), 0, "ExceptionRecord objects already exist!") response = self.client.get(url_for('ereporter_testapp/index')) self.assertEqual(response.status_code, 500, "Expected 500 error code.") self.assertEqual(ExceptionRecord.all().count(), 1) # Simulate the key expiring. memcache.flush_all(); response = self.client.get(url_for('ereporter_testapp/index')) self.assertEqual(response.status_code, 500, "Expected 500 error code.") self.assertEqual(ExceptionRecord.all().count(), 1, "More than one ExceptionRecord object was created!") self.assertEqual(ExceptionRecord.all()[0].count, 2, "ExceptionRecord count not incremented!")
class ServerErrorTest(GAETestBase): """ Regression test for issue 54 that checks to make sure that responses for error conditions extend BaseResponse. http://code.google.com/p/kay-framework/issues/detail?id=54 """ def setUp(self): s = LazySettings(settings_module="kay.tests.regressiontests.server_error_settings") app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() # Suppress logging error messages self._base_logger = logging.getLogger("") self._old_logging_handlers = self._base_logger.handlers self._base_logger.handlers = [NullHandler()] def tearDown(self): self.client.test_logout() self._base_logger.handlers = self._old_logging_handlers def test_login(self): response = self.client.get(url_for("server_error_testapp/index")) self.assertEqual(response.status_code, 500) self.assertTrue(isinstance(response, BaseResponse))
class CronOnlyDebugTestCase(GAETestBase): def setUp(self): s = LazySettings(settings_module='kay.tests.settings') s.DEBUG = True app = get_application(settings=s) self.client = Client(app, BaseResponse) def test_cron_only_failure(self): from kay.utils import is_dev_server response = self.client.get("/cron") if is_dev_server(): self.assertEqual(response.status_code, 200) else: self.assertEqual(response.status_code, 403) response = self.client.get("/class_based_test_root/cron") if is_dev_server(): self.assertEqual(response.status_code, 200) else: self.assertEqual(response.status_code, 403) def test_cron_only(self): response = self.client.get("/cron", headers=(('X-AppEngine-Cron', 'true'),)) self.assertEqual(response.status_code, 200) self.assertTrue(response.data == "OK") response = self.client.get("/class_based_test_root/cron", headers=(('X-AppEngine-Cron', 'true'),)) self.assertEqual(response.status_code, 200) self.assertTrue(response.data == "OK")
class MaintenanceCheckTestCase(unittest.TestCase): def setUp(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test','/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) s = LazySettings(settings_module='kay.tests.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) if apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map.has_key('capability_service'): del(apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map['capability_service']) def tearDown(self): pass def test_success(self): """Test with normal CapabilityServiceStub""" apiproxy_stub_map.apiproxy.RegisterStub( 'capability_service', capability_stub.CapabilityServiceStub()) response = self.client.get('/') self.assertEqual(response.status_code, 200) def test_failure(self): """Test with DisabledCapabilityServiceStub """ apiproxy_stub_map.apiproxy.RegisterStub( 'capability_service', mocked_capability_stub.DisabledCapabilityServiceStub()) response = self.client.get('/') self.assertEqual(response.status_code, 302) self.assertEqual(response.headers['Location'], 'http://localhost/maintenance_page') response = self.client.get('/index2') self.assertEqual(response.status_code, 302) self.assertEqual(response.headers['Location'], 'http://localhost/no_decorator') response = self.client.get('/no_decorator') self.assertEqual(response.status_code, 200)
class CronOnlyTestCase(GAETestBase): def setUp(self): s = LazySettings(settings_module='kay.tests.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) def test_cron_only(self): response = self.client.get("/cron", headers=(('X-AppEngine-Cron', 'true'),)) self.assertEqual(response.status_code, 200) self.assertTrue(response.data == "OK") def test_cron_only_failure(self): response = self.client.get("/cron") self.assertEqual(response.status_code, 403)
class DatastoreBackendTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True KIND_PREFIX_IN_TEST = 't2' def setUp(self): s = LazySettings(settings_module='kay.tests.datastore_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) def tearDown(self): self.client.test_logout() def test_login(self): from kay.auth import create_new_user create_new_user("foobar", "password", is_admin=False) response = self.client.get(url_for('auth_testapp/index')) self.assertEqual(response.status_code, 200) response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 302) self.assert_(response.headers.get('Location').endswith( '/auth/login?next=http%253A%252F%252Flocalhost%252Fsecret')) self.client.test_login(username='******') response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 302) def test_create_inactive_user(self): from kay.auth.models import DatastoreUser from kay.utils import crypto user = DatastoreUser.create_inactive_user("testuser", "password", "*****@*****.**", do_registration=False) self.assertEqual(user.key().name(), DatastoreUser.get_key_name("testuser")) self.assertEqual(user.user_name, "testuser") self.assertTrue(crypto.check_pwhash(user.password, "password")) self.assertEqual(user.email, "*****@*****.**")
def setUp(self): s = LazySettings(settings_module="kay.tests.regressiontests.server_error_settings") app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() # Suppress logging error messages self._base_logger = logging.getLogger("") self._old_logging_handlers = self._base_logger.handlers self._base_logger.handlers = [NullHandler()]
def setUp(self): try: self.original_user = os.environ['USER_EMAIL'] self.original_is_admin = os.environ['USER_IS_ADMIN'] del os.environ['USER_EMAIL'] del os.environ['USER_IS_ADMIN'] except Exception: pass s = LazySettings(settings_module='kay.tests.google_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout()
class ServerErrorTest(GAETestBase): def setUp(self): s = LazySettings( settings_module='kay.tests.regressiontests.server_error_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() # Suppress logging error messages self._base_logger = logging.getLogger("") self._old_logging_handlers = self._base_logger.handlers self._base_logger.handlers = [NullHandler()] def tearDown(self): self.client.test_logout() self._base_logger.handlers = self._old_logging_handlers def test_login(self): response = self.client.get(url_for('server_error_testapp/index')) self.assertEqual(response.status_code, 500) self.assertTrue(isinstance(response, BaseResponse))
class CronOnlyAdminTestCase(GAETestBase): def setUp(self): s = LazySettings(settings_module='kay.tests.decorator_settings') s.DEBUG = True app = get_application(settings=s) self.client = Client(app, BaseResponse) def test_cron_only_admin(self): from kay.auth.models import DatastoreUser user = DatastoreUser( key_name=DatastoreUser.get_key_name("foobar"), user_name="foobar", password=DatastoreUser.hash_password("password") ) user.is_admin = True user.put() self.client.test_login(username='******') response = self.client.get('/cron') self.assertEqual(response.status_code, 200) self.assertTrue(response.data == "OK")
def setUp(self): s = LazySettings( settings_module='kay.tests.ereporter_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) #self.client.test_logout() # Suppress logging error messages self._base_logger = logging.getLogger("") self._old_logging_handlers = self._base_logger.handlers self._base_logger.handlers = filter( lambda h: not isinstance(h, logging.StreamHandler), self._old_logging_handlers, )
class SessionMiddlewareOnCookieWithSecureAttributeTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True def setUp(self): import os s = LazySettings(settings_module='kay.tests.cookie_session_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.server_name = os.environ['SERVER_NAME'] def tearDown(self): pass def test_if_cookie_is_marked_as_secure(self): url = 'https://%s/countup' % self.server_name response = self.client.get('/countup', url) self.assert_('secure' in response.headers['Set-Cookie'], 'The Set-Cookie header does not contain secure flag.')
def setUp(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test','/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) s = LazySettings(settings_module='kay.tests.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) if apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map.has_key('capability_service'): del(apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map['capability_service'])
class StackedDecoratorsTestCase(GAETestBase): def setUp(self): s = LazySettings(settings_module='kay.tests.stacked_decorators.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) def test_stacked_decorators(self): self.client.test_login(email='*****@*****.**') response = self.client.get('/') self.assertEqual(response.status_code, 200) response = self.client.get('/class') self.assertEqual(response.status_code, 200) response = self.client.get('/ndb') self.assertEqual(response.status_code, 200) response = self.client.get('/class_ndb') self.assertEqual(response.status_code, 200)
class RestTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True KIND_PREFIX_IN_TEST = "t2" def setUp(self): s = LazySettings(settings_module='kay.tests.rest_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() def tearDown(self): self.client.test_logout() def test_rest_operations(self): self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get('/rest/metadata') self.assertEqual(response.status_code, 200) response = self.client.get('/rest/metadata/RestModel') self.assertEqual(response.status_code, 200) response = self.client.post( '/rest/RestModel', data= '<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>12</i_prop><s_prop>string</s_prop></RestModel>' ) self.assertEqual(response.status_code, 200) key = response.data elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 12) response = self.client.post( '/rest/RestModel/%s' % key, data= '<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>14</i_prop></RestModel>' ) self.assertEqual(response.status_code, 200) key2 = response.data self.assertEqual(key, key2) elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 14) response = self.client.get('/rest/RestModel') self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s/s_prop' % key) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "string") response = self.client.get('/rest/RestModel/%s/i_prop' % key) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "14") response = self.client.delete('/rest/RestModel/%s' % key) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key) self.assertEqual(response.status_code, 404)
class RestJSONTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True def setUp(self): s = LazySettings(settings_module='kay.tests.rest_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() def tearDown(self): self.client.test_logout() def test_rest_json(self): headers = Headers({"Accept": "application/json"}) response = self.client.get('/rest/metadata', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.get('/rest/metadata', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get('/rest/metadata', headers=headers) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.get('/rest/metadata/RestModel', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.get('/rest/metadata/RestModel', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get('/rest/metadata/RestModel', headers=headers) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.post( '/rest/RestModel', data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.post( '/rest/RestModel', data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.post( '/rest/RestModel', data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 200) key = response.data elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 12) self.client.test_logout() response = self.client.post( '/rest/RestModel/%s' % key, data='{"RestModel": {"i_prop": 14}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.post( '/rest/RestModel/%s' % key, data='{"RestModel": {"i_prop": 14}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.post( '/rest/RestModel/%s' % key, data='{"RestModel": {"i_prop": 14}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 200) key2 = response.data self.assertEqual(key, key2) elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 14) response = self.client.post( '/rest/RestModel', data= '[{"RestModel": {"i_prop": 1, "s_prop": "foobar1"}},{"RestModel": {"i_prop": 2, "s_prop": "foobar2"}}]', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 200) key3, key4 = response.data.split(',') elm3 = RestModel.get(key3) elm4 = RestModel.get(key4) self.assertEqual(elm3.s_prop, "foobar1") self.assertEqual(elm3.i_prop, 1) self.assertEqual(elm4.s_prop, "foobar2") self.assertEqual(elm4.i_prop, 2) response = self.client.get('/rest/RestModel', headers=headers) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s/s_prop' % key, headers=headers) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "string") response = self.client.get('/rest/RestModel/%s/i_prop' % key, headers=headers) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "14") self.client.test_logout() response = self.client.delete('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.delete('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.delete('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 404)
def setUp(self): s = LazySettings(settings_module='kay.tests.settings') s.DEBUG = True app = get_application(settings=s) self.client = Client(app, BaseResponse)
def setUp(self): s = LazySettings( settings_module='kay.tests.securecookie_session_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse)
def setUp(self): s = LazySettings(settings_module='kay.tests.rest_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout()
class RestJSONTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True def setUp(self): s = LazySettings(settings_module='kay.tests.rest_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() def tearDown(self): self.client.test_logout() def test_rest_json(self): headers = Headers({"Accept": "application/json"}) response = self.client.get('/rest/metadata', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.get('/rest/metadata', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get('/rest/metadata', headers=headers) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.get('/rest/metadata/RestModel', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.get('/rest/metadata/RestModel', headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get('/rest/metadata/RestModel', headers=headers) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.post( '/rest/RestModel', data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.post( '/rest/RestModel', data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.post( '/rest/RestModel', data='{"RestModel": {"i_prop": 12, "s_prop": "string"}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 200) key = response.data elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 12) self.client.test_logout() response = self.client.post( '/rest/RestModel/%s' % key, data='{"RestModel": {"i_prop": 14}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.post( '/rest/RestModel/%s' % key, data='{"RestModel": {"i_prop": 14}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.post( '/rest/RestModel/%s' % key, data='{"RestModel": {"i_prop": 14}}', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 200) key2 = response.data self.assertEqual(key, key2) elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 14) response = self.client.post( '/rest/RestModel', data='[{"RestModel": {"i_prop": 1, "s_prop": "foobar1"}},{"RestModel": {"i_prop": 2, "s_prop": "foobar2"}}]', content_type="application/json; charset=utf-8") self.assertEqual(response.status_code, 200) key3, key4 = response.data.split(',') elm3 = RestModel.get(key3) elm4 = RestModel.get(key4) self.assertEqual(elm3.s_prop, "foobar1") self.assertEqual(elm3.i_prop, 1) self.assertEqual(elm4.s_prop, "foobar2") self.assertEqual(elm4.i_prop, 2) response = self.client.get('/rest/RestModel', headers=headers) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s/s_prop' % key, headers=headers) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "string") response = self.client.get('/rest/RestModel/%s/i_prop' % key, headers=headers) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "14") self.client.test_logout() response = self.client.delete('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**") response = self.client.delete('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 403) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.delete('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key, headers=headers) self.assertEqual(response.status_code, 404)
def setUp(self): from kay.auth import create_new_user s = LazySettings(settings_module='kay.tests.datastore_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) create_new_user("foobar", "password", is_admin=False)
def setUp(self): import os s = LazySettings(settings_module='kay.tests.cookie_session_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.server_name = os.environ['SERVER_NAME']
class CacheTestCase(GAETestBase): def setUp(self): s = LazySettings(settings_module='kay.tests.cache_test.settings') self.app = get_application(settings=s) self.client = Client(self.app, BaseResponse) memcache.flush_all() def test_cache_middleware(self): # make sure that CACHE_MIDDLEWARE_ANONYMOUSE_ONLY works self.client.test_login(email='*****@*****.**') response = self.client.get(url_for('cache_testapp/index')) self.assertEqual(response.status_code, 200) c = memcache.get('http://localhost/?lang=en', namespace='CACHE_MIDDLEWARE') self.assertEqual(c, None) self.client.test_logout() # user logout, so the cache works response = self.client.get(url_for('cache_testapp/index')) self.assertEqual(response.status_code, 200) c = memcache.get('http://localhost/?lang=en', namespace='CACHE_MIDDLEWARE') self.assertEqual(c.data, response.data) def test_cache_decorator_with_function_view(self): # make sure that CACHE_MIDDLEWARE_ANONYMOUSE_ONLY works self.client.test_login(email='*****@*****.**') response = self.client.get(url_for('cache_testapp/decorator')) self.assertEqual(response.status_code, 200) c = memcache.get('http://localhost/decorator?lang=en', namespace='CACHE_DECORATOR') self.assertEqual(c, None) self.client.test_logout() # user logout, so the cache works response = self.client.get(url_for('cache_testapp/decorator')) self.assertEqual(response.status_code, 200) c = memcache.get('http://localhost/decorator?lang=en', namespace='CACHE_DECORATOR') self.assertEqual(c.data, response.data) def test_cache_decorator_with_class_view(self): # make sure that CACHE_MIDDLEWARE_ANONYMOUSE_ONLY works self.client.test_login(email='*****@*****.**') response = self.client.get(url_for('cache_testapp/decorator_class')) self.assertEqual(response.status_code, 200) c = memcache.get('http://localhost/decorator_class?lang=en', namespace='CACHE_DECORATOR') self.assertEqual(c, None) self.client.test_logout() # user logout, so the cache works response = self.client.get(url_for('cache_testapp/decorator_class')) self.assertEqual(response.status_code, 200) c = memcache.get('http://localhost/decorator_class?lang=en', namespace='CACHE_DECORATOR') self.assertEqual(c.data, response.data)
class MaintenanceCheckTestCase(unittest.TestCase): def setUp(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test','/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) s = LazySettings(settings_module='kay.tests.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) if apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map.has_key('capability_service'): del(apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map['capability_service']) def tearDown(self): pass def test_success(self): """Test with normal CapabilityServiceStub""" apiproxy_stub_map.apiproxy.RegisterStub( 'capability_service', capability_stub.CapabilityServiceStub()) response = self.client.get('/') self.assertEqual(response.status_code, 200) response = self.client.get('/class_based_test_root/') self.assertEqual(response.status_code, 200) def test_failure(self): """Test with DisabledCapabilityServiceStub """ apiproxy_stub_map.apiproxy.RegisterStub( 'capability_service', mocked_capability_stub.DisabledCapabilityServiceStub()) response = self.client.get('/') self.assertEqual(response.status_code, 302) self.assertEqual(response.headers['Location'], 'http://localhost/maintenance_page') response = self.client.get('/class_based_test_root/') self.assertEqual(response.status_code, 302) self.assertEqual(response.headers['Location'], 'http://localhost/maintenance_page') response = self.client.get('/index2') self.assertEqual(response.status_code, 302) self.assertEqual(response.headers['Location'], 'http://localhost/no_decorator') response = self.client.get('/class_based_test_root/index2') self.assertEqual(response.status_code, 302) self.assertEqual(response.headers['Location'], 'http://localhost/no_decorator') response = self.client.get('/no_decorator') self.assertEqual(response.status_code, 200)
def setUp(self): s = LazySettings(settings_module='kay.tests.stacked_decorators.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse)
def setUp(self): s = LazySettings(settings_module='kay.tests.securecookie_session_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse)
class GoogleBackendTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True KIND_PREFIX_IN_TEST = 't1' def setUp(self): try: self.original_user = os.environ['USER_EMAIL'] self.original_is_admin = os.environ['USER_IS_ADMIN'] del os.environ['USER_EMAIL'] del os.environ['USER_IS_ADMIN'] except Exception: pass s = LazySettings(settings_module='kay.tests.google_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() def tearDown(self): self.client.test_logout() def test_login(self): response = self.client.get(url_for('auth_testapp/index')) self.assertEqual(response.status_code, 200) response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 302) self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 200) self.client.test_logout() response = self.client.get(url_for('auth_testapp/secret')) self.assertEqual(response.status_code, 302)
class GAEMABackendTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True KIND_PREFIX_IN_TEST = 't3' def setUp(self): s = LazySettings(settings_module='kay.tests.gaema_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) def tearDown(self): self.client.test_logout(service='shehas.net') def test_login(self): response = self.client.get(url_for('gaema_testapp/index')) self.assertEqual(response.status_code, 200) response = self.client.get( url_for('gaema_testapp/secret', domain_name='shehas.net')) self.assertEqual(response.status_code, 302) self.assert_( response.headers.get('Location').endswith( '/_ah/gaema/marketplace_login/a/shehas.net')) self.client.test_login(service='shehas.net', user_data={ 'claimed_id': 'http://shehas.net/123', 'email': '*****@*****.**' }) response = self.client.get( url_for('gaema_testapp/secret', domain_name='shehas.net')) self.assertEqual(response.status_code, 200) response = self.client.get( url_for('gaema_testapp/secret', domain_name='example.com')) self.assertEqual(response.status_code, 302) self.assert_( response.headers.get('Location').endswith( '/_ah/gaema/marketplace_login/a/example.com')) self.client.test_logout(service='shehas.net') response = self.client.get( url_for('gaema_testapp/secret', domain_name='shehas.net')) self.assertEqual(response.status_code, 302)
def setUp(self): s = LazySettings(settings_module='kay.tests.datastore_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse)
class RestTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True def setUp(self): s = LazySettings(settings_module='kay.tests.rest_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) self.client.test_logout() def tearDown(self): self.client.test_logout() def test_rest_operations(self): self.client.test_login(email="*****@*****.**", is_admin="1") response = self.client.get('/rest/metadata') self.assertEqual(response.status_code, 200) response = self.client.get('/rest/metadata/RestModel') self.assertEqual(response.status_code, 200) response = self.client.post('/rest/RestModel', data='<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>12</i_prop><s_prop>string</s_prop></RestModel>') self.assertEqual(response.status_code, 200) key = response.data elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 12) response = self.client.post( '/rest/RestModel/%s' % key, data='<?xml version="1.0" encoding="utf-8"?><RestModel><i_prop>14</i_prop></RestModel>') self.assertEqual(response.status_code, 200) key2 = response.data self.assertEqual(key, key2) elm = RestModel.get(key) self.assertEqual(elm.s_prop, "string") self.assertEqual(elm.i_prop, 14) response = self.client.get('/rest/RestModel') self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s/s_prop' % key) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "string") response = self.client.get('/rest/RestModel/%s/i_prop' % key) self.assertEqual(response.status_code, 200) self.assertEqual(response.data, "14") response = self.client.delete('/rest/RestModel/%s' % key) self.assertEqual(response.status_code, 200) response = self.client.get('/rest/RestModel/%s' % key) self.assertEqual(response.status_code, 404)
def setUp(self): init_recording() app = get_application() self.client = Client(app, BaseResponse) self.client.test_login()
def setUp(self): s = LazySettings(settings_module='kay.tests.cache_test.settings') self.app = get_application(settings=s) self.client = Client(self.app, BaseResponse) memcache.flush_all()
class GAEMABackendTestCase(GAETestBase): KIND_NAME_UNSWAPPED = False USE_PRODUCTION_STUBS = True CLEANUP_USED_KIND = True KIND_PREFIX_IN_TEST = 't3' def setUp(self): s = LazySettings(settings_module='kay.tests.gaema_settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) def tearDown(self): self.client.test_logout(service='shehas.net') def test_login(self): response = self.client.get(url_for('gaema_testapp/index')) self.assertEqual(response.status_code, 200) response = self.client.get(url_for('gaema_testapp/secret', domain_name='shehas.net')) self.assertEqual(response.status_code, 302) self.assert_(response.headers.get('Location').endswith( '/_ah/gaema/marketplace_login/a/shehas.net')) self.client.test_login(service='shehas.net', user_data={'claimed_id': 'http://shehas.net/123', 'email': '*****@*****.**'}) response = self.client.get(url_for('gaema_testapp/secret', domain_name='shehas.net')) self.assertEqual(response.status_code, 200) response = self.client.get(url_for('gaema_testapp/secret', domain_name='example.com')) self.assertEqual(response.status_code, 302) self.assert_(response.headers.get('Location').endswith( '/_ah/gaema/marketplace_login/a/example.com')) self.client.test_logout(service='shehas.net') response = self.client.get(url_for('gaema_testapp/secret', domain_name='shehas.net')) self.assertEqual(response.status_code, 302)