def testGetAuthForRequest(self): """Verifies that self.auth is set properly according to API key.""" key = model.Authorization.Create(source='xyz').id # No API key request = test_utils.SetupRequest('/foo') self.assertEquals(None, base_handler.GetAuthForRequest(request)) # HTTP request with an API key should be disallowed request = test_utils.SetupRequest('/foo?key=' + key) self.assertRaises(base_handler.ApiError, base_handler.GetAuthForRequest, request) # HTTPS request with an unrecognized API key request = test_utils.SetupRequest('/foo?key=abc') request.scheme = 'https' self.assertRaises(base_handler.ApiError, base_handler.GetAuthForRequest, request) # HTTPS request with a valid API key request = test_utils.SetupRequest('/foo?key=' + key) request.scheme = 'https' auth = base_handler.GetAuthForRequest(request) self.assertEquals('xyz', auth.source) # Disabled API key model.Authorization.SetEnabled(key, False) self.assertRaises(base_handler.ApiError, base_handler.GetAuthForRequest, request) # Re-enabled API key model.Authorization.SetEnabled(key, True) auth = base_handler.GetAuthForRequest(request) self.assertEquals('xyz', auth.source)
def testMapRegion(self): """Verifies that the 'region' property affects the Maps API URL.""" m1 = test_utils.CreateMap({'title': 'no region'}) m2 = test_utils.CreateMap({'title': 'has region', 'region': 'in'}) with test_utils.RootLogin(): cm_config = maps.GetConfig( test_utils.SetupRequest('/.maps/' + m1.id), m1) self.assertTrue('region=' not in cm_config['maps_api_url']) cm_config = maps.GetConfig( test_utils.SetupRequest('/.maps/' + m2.id), m2) self.assertTrue('region=in' in cm_config['maps_api_url'])
def testMapsApiUrlI18n(self): """Verifies that language and region are set correctly for the Maps API.""" cm_config = maps.GetConfig(test_utils.SetupRequest('/')) self.assertTrue('language=en' in cm_config['maps_api_url']) self.assertFalse('region=' in cm_config['maps_api_url']) cm_config = maps.GetConfig(test_utils.SetupRequest('/?hl=ja', 'ja')) self.assertTrue('language=ja' in cm_config['maps_api_url']) self.assertFalse('region=' in cm_config['maps_api_url']) cm_config = maps.GetConfig( test_utils.SetupRequest('/?hl=th&gl=IN', 'th')) self.assertTrue('language=th' in cm_config['maps_api_url']) self.assertTrue('region=IN' in cm_config['maps_api_url'])
def testMapIdInConfig_DraftMap(self): """Verifies the map ID is added to the map_root always.""" with test_utils.RootLogin(): my_map = test_utils.CreateMap() cfg = maps.GetConfig( test_utils.SetupRequest('/.maps/' + my_map.id), my_map) self.assertEqual(my_map.id, cfg['map_root']['id'])
def testMapIdInConfig_PublishedMap(self): with test_utils.RootLogin(): my_map = test_utils.CreateMap() my_entry = model.CatalogEntry.Create(test_utils.PRIMARY_DOMAIN, 'label', my_map) cfg = maps.GetConfig(test_utils.SetupRequest( '/a/%s/label' % test_utils.PRIMARY_DOMAIN), catalog_entry=my_entry) self.assertEqual(my_map.id, cfg['map_root']['id'])
def RunTestHandler(self, method, path, status, **headers): route = app.RootPathRoute([app.Route('/test', TestHandler)]) test_app = webapp2.WSGIApplication([route]) request = test_utils.SetupRequest(path) request.method = method request.headers.update(headers) response = webapp2.Response() test_app.app.router.dispatch(request, response) self.assertEquals(status, response.status_int) return request, response
def testClientConfigOverride(self): """Verifies that query parameters can override client config settings.""" cm_config = maps.GetConfig( test_utils.SetupRequest('/?dev=1&show_login=1')) self.assertEquals(True, cm_config['show_login'])
def setUp(self): super(CardTest, self).setUp() self.request = test_utils.SetupRequest('/.card/foo')