def testGetHostname_CurrentModule(self): self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.request_data.get_module(None).AndReturn('default') self.dispatcher.get_hostname('default', '1', None).AndReturn('localhost:8080') self.mox.ReplayAll() self.assertEqual('localhost:8080', modules.get_hostname(version='1')) self.mox.VerifyAll()
def testGetHostname_NoArgs(self): """Test we pass through the expected args when none are given.""" expected_request = modules_service_pb2.GetHostnameRequest() service_response = modules_service_pb2.GetHostnameResponse() service_response.hostname = 'abc' self.SetSuccessExpectations('GetHostname', expected_request, service_response) self.assertEqual('abc', modules.get_hostname())
def testGetHostname_CurrentVersionDifferentModule(self): self.request_data.get_dispatcher().AndReturn(self.dispatcher) self.request_data.get_version(None).AndReturn('1') self.dispatcher.get_versions('other').AndReturn(['1']) self.dispatcher.get_hostname('other', '1', None).AndReturn('localhost:8080') self.mox.ReplayAll() self.assertEqual('localhost:8080', modules.get_hostname(module='other')) self.mox.VerifyAll()
def testGetHostname_InstanceZero(self): """Test we pass through the expected args when instance zero is given.""" expected_request = modules_service_pb2.GetHostnameRequest() expected_request.module = 'module1' expected_request.instance = '0' service_response = modules_service_pb2.GetHostnameResponse() service_response.hostname = 'abc' self.SetSuccessExpectations('GetHostname', expected_request, service_response) self.assertEqual('abc', modules.get_hostname(module='module1', instance=0))
def testGetHostname_NoModule(self): """Test we pass through the expected args when no module is specified.""" expected_request = modules_service_pb2.GetHostnameRequest() expected_request.version = 'v1' expected_request.instance = '3' service_response = modules_service_pb2.GetHostnameResponse() service_response.hostname = 'abc' self.SetSuccessExpectations('GetHostname', expected_request, service_response) self.assertEqual('abc', modules.get_hostname(version='v1', instance='3'))
def GetInfo(self, name): return base.AppInfo(name=name, hostname=modules.get_hostname(module=name))
# import logging # from datetime import timedelta from google.appengine.api.modules import modules from google.appengine.ext import ndb import jinja2 from models import Period, Dataset, Report, CartodbDownloadEntry from util import * # from google.appengine.api import urlfetch import webapp2 __author__ = 'jotegui' _HOSTNAME = modules.get_hostname(module="tools-usagestats") JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')), extensions=['jinja2.ext.autoescape'], autoescape=True) class PeriodStatus(webapp2.RequestHandler): def get(self, period): period_key = ndb.Key("Period", period) entity = period_key.get() if entity: status = entity.status else:
# limitations under the License. __author__ = '@jotegui' __contributors__ = "Javier Otegui, John Wieczorek" __copyright__ = "Copyright 2018 vertnet.org" __version__ = "Status.py 2018-11-01T19:34-03:00" import json from google.appengine.api.modules import modules from google.appengine.ext import ndb import jinja2 from models import Period, Dataset, Report, CartoDownloadEntry from util import * import webapp2 _HOSTNAME = modules.get_hostname(module="tools-usagestats") JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__),'templates')), extensions=['jinja2.ext.autoescape'], autoescape=True) class Status(webapp2.RequestHandler): def get(self): # Check if datasets are loaded in datastore # Items in datastore d = Dataset.query().count() # Items in Carto q = "select count(*) as c from resource_staging" + \
import logging import webapp2 from google.appengine.api import taskqueue from google.appengine.api.modules import modules module = modules.get_current_module_name() version = modules.get_current_version_name() hostname = modules.get_hostname() where = "__module=%s__version=%s__hostname=%s" %(module, version, hostname) SEP = "__" LOCATOR = "LAST_TESTS - " skip_headers = ["X-Appengine-Country","Cache-Control","Content-Type","User-Agent","Accept","Accept-Language", "X-Appengine-Citylatlong","X-Appengine-Region", "X-Appengine-City", "X-Appengine-Default-Namespace", "X-Google-Apps-Metadata", "X-Zoo"] def to_log(msg): return msg.replace(SEP, " ") def to_html(msg): return msg.replace(SEP, "<br/>") def headers(request): return SEP + "HEADERS" + SEP + SEP.join([k+ "->" + v for k,v in request.headers.iteritems() if k not in skip_headers])