def setUp(self): V.Object.REQUIRED_PROPERTIES = True V.base.reset_type_names() self.complex_validator = self.parse({ "n": "number", "?i": V.Nullable("integer", 0), "?b": bool, "?e": V.Enum(["r", "g", "b"]), "?d": V.AnyOf("date", "datetime"), "?s": V.String(min_length=1, max_length=8), "?p": V.Nullable(re.compile(r"\d{1,4}$")), "?l": [{ "+s2": "string" }], "?t": (unicode, "number"), "?h": V.Mapping(int, ["string"]), "?o": V.NonNullable({"+i2": "integer"}), })
def setUp(self): super(OptionalPropertiesTestValidator, self).setUp() V.Object.REQUIRED_PROPERTIES = False self.complex_validator = self.parse({ "+n": "+number", "i": V.Nullable("integer", 0), "b": bool, "e": V.Enum(["r", "g", "b"]), "d": V.AnyOf("date", "datetime"), "s": V.String(min_length=1, max_length=8), "p": V.Nullable(re.compile(r"\d{1,4}$")), "l": [{ "+s2": "string" }], "t": (unicode, "number"), "h": V.Mapping(int, ["string"]), "o": V.NonNullable({"+i2": "integer"}), })
def new_thread(env): schema = v.parse({'+ids': [int], '+action': v.Enum(('new', 'merge'))}) params = schema.validate(env.request.json) action = params['action'] if action == 'new': id = params['ids'][0] syncer.new_thread(env, id) return {'url': env.url_for('thread', {'id': id})} elif action == 'merge': thrid = syncer.merge_threads(env, params['ids']) return {'url': env.url_for('thread', {'id': thrid})}
def test_enum(self): self._testValidation(V.Enum([1, 2, 3]), valid=[1, 2, 3], invalid=[0, 4, "1", [1]]) self._testValidation(V.Enum([u"foo", u"bar"]), valid=["foo", "bar"], invalid=["", "fooabar", ["foo"]]) self._testValidation(V.Enum([True]), valid=[True], invalid=[False, [True]]) self._testValidation(V.Enum([{ "foo": u"bar" }]), valid=[{ u"foo": "bar" }]) self._testValidation(V.Enum([{ "foo": u"quux" }]), invalid=[{ u"foo": u"bar" }])
class Handler(RequestHandler): @validated({"+name": valideer.Enum(("steve", "joe"))}) def get(self, arguments): self.finish("Hello, %s!" % arguments.get('name', 'nobody')) @validated(body={"name": valideer.Enum(("steve", "joe"))}) def post(self, body): self.finish("Hello, %s!" % body.get('name', 'nobody')) @validated(body=False, arguments=False) def patch(self): self.finish("Hello, World!") @validated(arguments={"joe": "bool"}, body={"+name": valideer.Enum(("steve", "joe"))}) def put(self, arguments, body): self.finish("Hello, %s!" % arguments.get('name', 'nobody')) def _handle_request_exception(self, e): if isinstance(e, valideer.ValidationError): self.set_status(400) self._reason = str(e) self.write_error(400, reason=str(e)) else: super(Handler, self)._handle_request_exception(e)
class ArtifactMessage(BaseMessage): project = attr.ib() artifact_type = attr.ib() artifact = attr.ib() success = attr.ib() filename = attr.ib(default=None) last_hash = attr.ib(default=None) _validator = V.parse({ "project": "string", "artifact_type": V.Enum({"tool", "package", "file"}), "artifact": "string", # TODO(arsen): architecture "success": "boolean", "?filename": "?string", "?last_hash": V.Nullable(_is_blake2b_digest) })
def mark(env): def name(value): if isinstance(value, str): value = [value] return [v for v in value if v] schema = v.parse({ '+action': v.Enum(('+', '-', '=')), '+name': v.AdaptBy(name), '+ids': [int], 'old_name': v.AdaptBy(name), 'thread': v.Nullable(bool, False), 'last': v.Nullable(str) }) data = schema.validate(env.request.json) if not data['ids']: return 'OK' ids = tuple(data['ids']) if data['thread']: i = env.sql(''' SELECT id FROM emails WHERE thrid IN %s AND created <= %s ''', [ids, data['last']]) ids = tuple(r[0] for r in i) mark = ft.partial(syncer.mark, env, ids=ids, new=True) if data['action'] == '=': if data.get('old_name') is None: raise ValueError('Missing parameter "old_name" for %r' % data) if data['old_name'] == data['name']: return [] mark('-', set(data['old_name']) - set(data['name'])) mark('+', set(data['name']) - set(data['old_name'])) return 'OK' mark(data['action'], data['name']) return 'OK'
def get_conf(conf=None): if not conf: with open('conf.json', 'br') as f: conf = json.loads(f.read().decode()) exists = v.Condition(lambda v: Path(v).exists()) strip_slash = v.AdaptBy(lambda v: str(v).rstrip('/')) app_dir = Path(__file__).parent.resolve() base_dir = app_dir.parent log_handlers = ['console_simple', 'console_detail', 'file'] with v.parsing(additional_properties=False): schema = v.parse({ 'debug': v.Nullable(bool, False), '+pg_username': str, '+pg_password': str, '+cookie_secret': str, 'google_id': str, 'google_secret': str, 'readonly': v.Nullable(bool, True), 'enabled': v.Nullable(bool, True), 'log_handlers': (v.Nullable([v.Enum(log_handlers)], log_handlers[:1])), 'log_level': v.Nullable(str, 'DEBUG'), 'log_file': v.Nullable(str, ''), 'path_attachments': v.Nullable(str, str(base_dir / 'attachments')), 'path_theme': v.Nullable(exists, str(base_dir / 'front')), 'imap_body_maxsize': v.Nullable(int, 50 * 1024 * 1024), 'imap_batch_size': v.Nullable(int, 2000), 'imap_debug': v.Nullable(int, 0), 'smtp_debug': v.Nullable(bool, False), 'async_pool': v.Nullable(int, 0), 'ui_ga_id': v.Nullable(str, ''), 'ui_is_public': v.Nullable(bool, False), 'ui_use_names': v.Nullable(bool, True), 'ui_per_page': v.Nullable(int, 100), 'ui_greeting': v.Nullable(str, ''), 'ui_ws_proxy': v.Nullable(bool, False), 'ui_ws_enabled': v.Nullable(bool, True), 'ui_ws_timeout': v.Nullable(int, 1000), 'ui_firebug': v.Nullable(bool, False), 'ui_tiny_thread': v.Nullable(int, 5), 'ui_by_thread': v.Nullable(bool, False), 'from_emails': v.Nullable([str], []), 'host_ws': v.Nullable(str, 'ws://localhost/async/'), 'host_web': v.Nullable(strip_slash, 'http://localhost:8000'), 'search_lang': v.Nullable([str], ['simple', 'english']), }) conf = schema.validate(conf) path = Path(conf['path_attachments']) if not path.exists(): path.mkdir() return conf
def compose(env, id=None): if not env.storage.get('gmail_info'): return env.abort(400) schema = v.parse({ 'target': v.Nullable(v.Enum(('all', 'forward'))) }) args = schema.validate(env.request.args) fr = env.from_emails[0] ctx = { 'fr': fr, 'to': '', 'subj': '', 'body': '', 'files': [], 'quoted': False, 'forward': False, 'id': id, 'draft': False, 'from_emails': env.from_emails } parent = {} if id: parent = env.sql(''' SELECT thrid, "to", fr, cc, bcc, subj, reply_to, html, time, attachments, embedded FROM emails WHERE id=%s LIMIT 1 ''', [id]).fetchone() to_all = parent['to'][:] + parent['cc'][:] fr = env.from_email(parent['fr']) if fr: to = to_all else: fr_ = env.from_email(to_all) if fr_: fr = fr_ to_all = [ a for a in to_all if parseaddr(a)[1] != parseaddr(fr)[1] ] to = (parent['reply_to'] or parent['fr'])[:] forward = args.get('target') == 'forward' if forward: to = [] elif args.get('target') == 'all': to += to_all ctx.update({ 'fr': fr, 'to': ', '.join(to), 'subj': 'Re: %s' % f.humanize_subj(parent['subj'], empty=''), 'quote': ctx_quote(env, parent, forward), 'quoted': forward, 'forward': forward, }) thrid = parent.get('thrid') saved = env.storage('compose', thrid=thrid) saved_path = env.files.subpath('compose', thrid=thrid) if saved.get(): ctx.update(saved.get()) ctx['draft'] = saved.get() is not None ctx['title'] = ctx.get('subj') or 'New message' if ctx['forward'] and not ctx['draft']: env.files.copy(f.slugify(id), saved_path) files = list(parent['attachments']) + list(parent['embedded'].values()) for i in files: path = i['path'].replace(id, saved_path) asset = env.files.to_dict(**dict(i, path=path)) ctx['files'].append(asset) quote = ctx.get('quote') if quote: parent_url = re.escape(env.files.url(i['path'])) ctx['quote'] = re.sub(parent_url, asset['url'], quote) ctx['links'] = { a: env.url_for('draft', {'thrid': str(thrid or 'new'), 'action': a}) for a in ('preview', 'rm', 'send', 'upload') } return ctx
class TestSuiteCitySDKKlarschiff(citysdk311.TestSuiteCitySDK): SCHEMA_REQUESTSEXT = { "+service_requests": { "+request": [{ "extended_attributes": { "title": "string", #TOOD: are EXT attributes optional even if requested? "service_object_id": "string", "service_object_type": "string", "detailed_status": valideer.Enum([ "RECEIVED", "IN_PROCESS", "PROCESSED", "ARCHIVED", "REJECTED" ]), "detailed_status_datetime": valideer.AdaptBy(parser.parse), "media_urls": { "media_url": ["string"] } }, "photo_required": "boolean", "trust": "integer", "votes": "integer", "+service_request_id": "string", "+status": valideer.Enum(["OPEN", "CLOSED"]), "status_notes": "string", "+service_name": "string", "+service_code": "string", "description": "string", "agency_responsible": "string", "service_notice": "string", "requested_datetime": valideer.AdaptBy(parser.parse), "updated_datetime": valideer.AdaptBy(parser.parse), "expected_datetime": valideer.AdaptBy(parser.parse), "address": "string", #TODO: Make Position XOR address "address_id": "string", "zipcode": "string", "+lat": valideer.AdaptTo(float, "number"), "+long": valideer.AdaptTo(float, "number"), "media_url": "string", }] #TODO: make URL regex } } SCHEMA_COMMENTS = { "+comments": { #TODO: Conditional Array? "+comment": { "+id": "integer", "+jurisdiction_id": "string", "+comment": "string", "+datetime": valideer.AdaptBy(parser.parse), "+service_request_id": "string", "+author": "string", #TODO: Validate as email } } } SCHEMA_NOTES = { "+notes": { #TODO: Conditional Array? "+note": { "+jurisdiction_id": "string", "+comment": "string", "+datetime": valideer.AdaptBy(parser.parse), "+service_request_id": "string", "+author": "string" } } } def __init__(self, host): self.api = CitysdkKlarschiff(host) citysdk311.TestSuiteCitySDK.__init__(self, host, self.api) def testRequestsExtKS(self): print("Testing GET extended requests"), repl = self.api.getRequests() expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") replFields = self.xmlToDict(repl.content) print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_REQUESTSEXT) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e))) def testGetRequestsExFilteredKS(self, agency): print("Testing GET requests with extended filters") print("-agency"), repl = self.api.getRequests(lat=12.13955, long=54.09138, radius=2000) #TODO calculate that point self.testEmptyRequestSet(repl) print("-detailed_status"), repl = self.api.getRequests(statusEx="RECEIVED") self.testEmptyRequestSet(repl) def testGetComments(self, apikey): repl = self.api.getComments(66, apikey) expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") replFields = self.xmlToDict(repl.content) print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_COMMENTS) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e))) def testGetNotes(self, apikey): repl = self.api.getNotes(66, apikey) expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") replFields = self.xmlToDict(repl.content) print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_NOTES) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e)))
class TestSuite(object): '''Open311 basic test. Inherited classes just run it's own tests''' SCHEMA_SERVICE = { "+services": { "+service": [{ "+service_code": "string", "+service_name": "string", "description": "string", "+metadata": valideer.Enum(["true", "false"]), "+type": valideer.Enum(["realtime", "batch", "blackbox"]), "+keywords": "string", "group": "string", }] } } SCHEMA_DEF = { "+service_code": "string", "+attributes": [{ "+variable": valideer.Enum(["true", "false"]), "+code": "string", "+datatype": valideer.Enum([ "string", "number", "datetime", "text", "singlevaluelist", "multivaluelist" ]), "+required": valideer.Enum(["true", "false"]), "+datatype_description": "string", "+order": valideer.Range(valideer.Number, 0), "description": "string" }] } SCHEMA_REQUESTS = { "+service_requests": { "+request": [{ "+service_request_id": "string", "+status": valideer.Enum(["open", "closed"]), "status_notes": "string", "+service_name": "string", "+service_code": "string", "description": "string", "agency_responsible": "string", "service_notice": "string", "requested_datetime": valideer.AdaptBy(parser.parse), "updated_datetime": valideer.AdaptBy(parser.parse), "expected_datetime": valideer.AdaptBy(parser.parse), "address": "string", #TODO: Make Position XOR address "address_id": "string", "zipcode": "string", "+lat": valideer.AdaptTo(float, "number"), "+long": valideer.AdaptTo(float, "number"), "media_url": "string", }] #TODO: make URL regex } } SCHEMA_REQUEST = { "+service_requests": { #TODO: Try to remove slightly redundant schema "+request": { "+service_request_id": "string", "+status": valideer.Enum(["open", "closed"]), "status_notes": "string", "+service_name": "string", "+service_code": "string", "description": "string", "agency_responsible": "string", "service_notice": "string", "requested_datetime": valideer.AdaptBy(parser.parse), "updated_datetime": valideer.AdaptBy(parser.parse), "expected_datetime": valideer.AdaptBy(parser.parse), "address": "string", #TODO: Make Position XOR address "address_id": "string", "+zipcode": "string", "+lat": valideer.AdaptTo(float, "number"), "+long": valideer.AdaptTo(float, "number"), "media_url": "string", } #TODO: make URL regex } } @staticmethod def __noNone(path, key, value): '''we skip dict none values for like <key/> elements ''' if value is None: return key, "" '''we skip additional typisation fields''' if (isinstance(value, dict)): if "@nil" in value: return key, "" if "@type" in value: if "#text" in value: return key, value["#text"] #if value.hasKey("@type"): oder alle mit @ return key, value def __init__(self, host, api=None, apikey=None): self.host = host if api is None: api = georeporter(host, apikey) self.api = api self.__cacheTransfers() def showDifferences(self, expect, result, msgTest): '''helper for visual compare of two lists''' #TODO: Add normalizing option - lowercase, trim, ... s = set(expect) diff = [x for x in result if x not in s] print("- " + msgTest), if len(diff) == 0: print("OK") else: print("differs at: %s (expected: %s)" % (str(diff), str(expect))) def __cacheTransfers(self): '''call api just one time for defaults''' print "caching..." print "-", self.cache_services = self.api.getServices() print "-", self.cache_requests = self.api.getRequests() #TODO: Write to disk? def __getFirstServiceCode(self): serviceCode = None root = etree.fromstring(self.cache_services.content) for service in root.getchildren(): fields = self.xmlToDict(etree.tostring(service)) try: if fields["metadata"] == "true": serviceCode = fields["service_code"] return serviceCode except: pass #TODO: Log that metadata is mandatory? return serviceCode def __getFirstRequestId(self): srid = None root = etree.fromstring(self.cache_requests.content) for servicereq in root.getchildren(): fields = self.xmlToDict(etree.tostring(servicereq))["request"] if "service_request_id" in fields: srid = fields["service_request_id"] return srid return srid def xmlToDict(self, repl): '''Transform XML tree to dict tree''' tmp = xmltodict.parse(repl, postprocessor=self.__noNone) replFields = json.loads(json.dumps(tmp)) return replFields #TODO: Test discovery def testGetServices(self): print("Testing GET services") repl = self.cache_services expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_SERVICE) replFields = self.xmlToDict(repl.content) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs %s " % (str(e))) def testGetServicsDef(self): #TODO: walk trough all definitions print("Testing GET service definition"), firstCode = self.__getFirstServiceCode() if firstCode is not None: repl = self.api.getServiceDef(firstCode) expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [ repl.status_code, repl.encoding, repl.headers["content-type"] ] self.showDifferences(expect, resp, "http skelleton") print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_DEF) replFields = self.xmlToDict(repl) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e))) else: print "(No service definitions available for testing)" def testCreateRequest(self, email="*****@*****.**", lat=54.0867, lon=12.1359, descr="test", title="test", code="18"): #TODO: Extract attributes print("Testing POST request"), repl = self.api.createRequest(lat, lon, code, email, descr, attr={"title": title}, jurisdinction="rostock.de", tolerantSSL=True) expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") #TODO: Attributes of metadata / service definitions #TODO: what more can we check here? #TODO: Some might return token instead def testGetRequests(self): print("Testing GET requests"), repl = self.cache_requests expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_REQUESTS) replFields = self.xmlToDict(repl.content) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e))) def testGetRequestsFiltered(self): print("Testing GET requests with filters") #TODO: How to generate indipendend queries? #TODO: How to check logic on expected results? print("-service_request_id"), repl = self.api.getRequests(service_request_id="3,5") self.testEmptyRequestSet(repl) print("-service_code") repl = self.api.getRequests(service_code=18) self.testEmptyRequestSet(repl) print("-start_date") past = datetime.datetime.utcnow() - datetime.timedelta(2) repl = self.api.getRequests(start_date=past.isoformat()) self.testEmptyRequestSet(repl) print("-end_date") repl = self.api.getRequests(end_date=past.isoformat()) self.testEmptyRequestSet(repl) print("-status") repl = self.api.getRequests(status="closed") self.testEmptyRequestSet(repl) #TODO: None older than 90days? def testGetRequest(self): print("Testing GET request"), srid = self.__getFirstRequestId() repl = self.api.getRequest(srid) expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") print("- XML structure") with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_REQUEST) replFields = self.xmlToDict(repl.content) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e))) def testGetRequestFromToken(self): print("Testing GET ID by token"), mytoken = "123" #TODO: Implement lookup for an valid token? repl = self.api.getIdByToken(mytoken) expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") def testEmptyRequestSet(self, repl): expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") print "- queryset", replFields = self.xmlToDict(repl.content) amount = 1 #if no subdicts, just a single request try: for item in replFields["service_requests"]["request"]: if isinstance(item, dict): amount += 1 if (amount > 0): print "ok (%d)" % amount else: print("failed (empty)") except KeyError: print("failed (empty)")
import os import valideer from tornado import gen from valideer import accepts from urllib import urlencode from tornado import httpclient from tornado.escape import json_decode from tornado.httputil import url_concat from .logger import traceback endpoints = valideer.Enum( ('charges', 'customers', 'cards', 'subscription', 'plans', 'coupons', 'discount', 'invoices', 'upcoming', 'lines', 'invoiceitems', 'dispute', 'close', 'transfers', 'cancel', 'recipients', 'application_fees', 'refund', 'account', 'balance', 'subscriptions', 'history', 'events', 'tokens', 'incoming')) class Stripe(object): __name__ = 'Stripe' """ https://stripe.com/docs/api """ def __init__(self, api_key=None): self.api_key = api_key or os.getenv('STRIPE_API_KEY', None) assert self.api_key, 'stripe api_key must be set' self._endpoints = ['https://%s:@api.stripe.com/v1' % self.api_key] @accepts(endpoint=endpoints) def __getattr__(self, endpoint):
class TestSuiteCitySDK(basic311.TestSuite): '''Cover CitySDK specific tests''' SCHEMA_REQUESTSEXT = { "+service_requests": { "+request": [{ "extended_attributes": { "title": "string", #TOOD: are EXT attributes optional even if requested? "service_object_id": "string", "service_object_type": "string", "detailed_status": valideer.Enum([ "RECEIVED", "IN_PROCESS", "PROCESSED", "ARCHIVED", "REJECTED" ]), #TODO: Add Public works status "media_urls": { "media_url": ["string"] } } #TODO: some implement , "+service_request_id": "string", "+status": valideer.Enum(["open", "closed"]), "status_notes": "string", "+service_name": "string", "+service_code": "string", "description": "string", "agency_responsible": "string", "service_notice": "string", "requested_datetime": valideer.AdaptBy(parser.parse), "updated_datetime": valideer.AdaptBy(parser.parse), "expected_datetime": valideer.AdaptBy(parser.parse), "address": "string", #TODO: Make Position XOR address "address_id": "string", "zipcode": "string", "+lat": valideer.AdaptTo(float, "number"), "+long": valideer.AdaptTo(float, "number"), "media_url": "string", }] #TODO: make URL regex } } def __init__(self, host, apikey, api=None): if (api is None): api = CitySDKParticipation(host, apikey) basic311.TestSuite.__init__(self, host, api) def testLocale(self, locale): print("Testing GET services (%s)" % locale), repl = self.api.getServices(locale) #TODO: Exact specs. for locale codes? expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") #Default and custom should differ replFields = self.xmlToDict(repl.content) if len(replFields["services"]) > 0: serviceLocale = replFields["services"]["service"][0] replFieldsEN = self.xmlToDict(self.cache_services.content) serviceEN = replFieldsEN["services"]["service"][0] if not (serviceLocale["service_name"] == serviceEN["service_name"]): print("ok") else: print("is ignored (same as defaults)") else: print "empty" def testRequestsExt(self): print("Testing GET extended requests"), # repl=self.cache_requests repl = self.api.getRequests() expect = [200, "UTF-8", "text/xml; charset=utf-8"] resp = [repl.status_code, repl.encoding, repl.headers["content-type"]] self.showDifferences(expect, resp, "http skelleton") replFields = self.xmlToDict(repl.content) print("- limits"), l = len(replFields["service_requests"]) if (l > 200): print("to much (%d)" % l) #90 days or first 200 else: print("ok") print("- XML structure"), with valideer.parsing(additional_properties=True): validator = valideer.parse(self.SCHEMA_REQUESTSEXT) try: validator.validate(replFields) print("OK") except ValidationError as e: print("differs at %s " % (str(e))) def testGetRequestsExtFiltered(self): print("Testing GET requests with extended filters") print("-geospatial"), repl = self.api.getRequests(lat=12.13955, long=54.09138, radius=2000) #TODO calculate that point self.testEmptyRequestSet(repl) print("-update_after") past = datetime.datetime.utcnow() - datetime.timedelta(7) repl = self.api.getRequests(updated_after=past.isoformat()) self.testEmptyRequestSet(repl) print("-update_after") repl = self.api.getRequests(updated_before=past.isoformat()) self.testEmptyRequestSet(repl)