def test_skip_sns_int(): with open('fixtures/etl_orgs.txt', 'r') as myfile: data = myfile.read() # Expect that pointing at non-existent SNS endpoint will cause an exception os.environ['RIALTO_SNS_ENDPOINT'] = 'http://xxxlocalhost:4575' caught_exception = False try: assert handler.main( { 'body': data, 'headers': { 'Content-Type': 'application/sparql-update' } }, "blank_context") except botocore.exceptions.EndpointConnectionError: caught_exception = True assert caught_exception # However, setting to skip SNS should mean that an exception isn't raised. os.environ['RIALTO_SNS_SKIP'] = 'true' assert handler.main( { 'body': data, 'headers': { 'Content-Type': 'application/sparql-update' } }, "blank_context")['statusCode'] == 200 del os.environ['RIALTO_SNS_ENDPOINT'] del os.environ['RIALTO_SNS_SKIP']
def build(lhost, lport, username, password, directory, filename, qcompile, qhandler): print colors.status.OK + " Editing payload source code.." sourcecode = source(username, password, directory, lhost, lport) print colors.status.OK + " Writing payload file.." write(sourcecode, filename) if qcompile in ('y', 'Y'): compile(filename) else: pass if qhandler in ("y", "Y"): print colors.color.YELLOW + "\nHandler : " + colors.color.ENDC print "---------" rhost = raw_input("rhost : ") print "" handler.main(rhost, int(lport), username, password) print colors.status.SUCCESS + " Operation finished check the output folder."
def test_main(monkeypatch): monkeypatch.setenv( 'email_bucket', 'gb-shovel-dev-serverlessdeploymentbucket-cljc3nttf1nd') monkeypatch.setenv('email_bucket_prefix', 'ses-email') monkeypatch.setenv('log_level', 'DEBUG') monkeypatch.setenv('region', 'eu-west-1') monkeypatch.setenv('email_forward_rules', '{"*****@*****.**": "*****@*****.**"}') monkeypatch.setenv('email_encryption_kms_key_arn', 'arn:aws:kms:eu-west-1:737354003986:alias/aws/ses') monkeypatch.setenv('aws_account_id', '737354003986') monkeypatch.setenv('ses_receipt_rule', 'gb-shovel-dev') context = {} event = {'Records': [{'eventSource': 'aws:ses', 'eventVersion': '1.0', 'ses': {'mail': {'timestamp': '2020-04-08T13:45:10.346Z', 'source': '*****@*****.**', 'messageId': 'bvg8eer9lr8mp5u7id62bjtofufd61m48f65oog1', 'destination': ['*****@*****.**'], 'headersTruncated': False, 'headers': [{'name': 'Return-Path', 'value': '<*****@*****.**>'}, {'name': 'Received', 'value': 'from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) by inbound-smtp.eu-west-1.amazonaws.com with SMTP id bvg8eer9lr8mp5u7id62bjtofufd61m48f65oog1 for [email protected]; Wed, 08 Apr 2020 13:45:10 +0000 (UTC)'}, {'name': 'Received-SPF', 'value': 'none (spfCheck: 209.85.160.169 is neither permitted nor denied by domain of glockenbach.se) client-ip=209.85.160.169; [email protected]; helo=mail-qt1-f169.google.com;'}, {'name': 'Authentication-Results', 'value': 'amazonses.com; spf=none (spfCheck: 209.85.160.169 is neither permitted nor denied by domain of glockenbach.se) client-ip=209.85.160.169; [email protected]; helo=mail-qt1-f169.google.com; dkim=pass [email protected]; dmarc=none header.from=glockenbach.se;'}, {'name': 'X-SES-RECEIPT', 'value': 'AEFBQUFBQUFBQUFHQXhBWm54RlFVZzZzQnROU0pHMHV4SDVRNlJjL2Z1RWhDaUs5Qk5pSVpwT1dmbUhrZ0tzTGNGdW9pc2EyMmJHL293RUhrMjY5SUVxS1RRSDYrTXdtVFFSMUJkOXlsamxjMzBSdnNreDFySUs5aVhZTms4T2hXMkNhY1pyTEVRaVYvaU0rcWpCNVJqeEJNN3FLSko4TWNGS0ZEb1hENzlkeUE2blQwTzZXaGdQanFPZVQxam54Q1czT2RaVDFudmM4eXZydzVvSHg5MHFETGFUeks3bUF2RjBpa2NlQWIyVTlSQjM1OWd0cWVHMi8wbDFKcHFVMUxkOE9xbkF6dkZiZUJyeHJ4eHFwRHdsRWtCNnphWXBGNEF0U1pFM0o0c1B1Uit4UUVCMVpWTUE9PQ=='}, {'name': 'X-SES-DKIM-SIGNATURE', 'value': 'a=rsa-sha256; q=dns/txt; b=qp3Rhc//LV5fSpsBxvHO17CTl/leZ74HQcMltkfLQ8OhFnr2Rb4Zxz/JitKD3L5i2AsRhlQ7zeHTizNoYmk/uT/RBIcxUBC5aT8BlIbPmvku+SIFYdpxF2rXKDM8x+iXT8reE3z9HUnYmAQgiCOxg/gGrwNyqkPzZqZghITvJSw=; c=relaxed/simple; s=shh3fegwg5fppqsuzphvschd53n6ihuv; d=amazonses.com; t=1586353510; v=1; bh=afGpZCmxB1t+YmjD7mTWufEZ4MjYKI8rwq3aqaGAyIg=; h=From:To:Cc:Bcc:Subject:Date:Message-ID:MIME-Version:Content-Type:X-SES-RECEIPT;'}, {'name': 'Received', 'value': 'by mail-qt1-f169.google.com with SMTP id 14so5596018qtp.1 for <*****@*****.**>; Wed, 08 Apr 2020 06:45:10 -0700 (PDT)'}, {'name': 'DKIM-Signature', 'value': 'v=1; a=rsa-sha256; c=relaxed/relaxed; d=glockenbach-se.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=afGpZCmxB1t+YmjD7mTWufEZ4MjYKI8rwq3aqaGAyIg=; b=YW3JmFSTeZlKSjAj0djHTIHhQwiFHQTeOLKF2NoXhy5IWMJy3P0m4B30CjbfIEB/oLs6P8FpRmAUO1h42NBXxHwwsV8kGor+LLsD78K0rDCz6loEnxEtu12ZQBrIoGF1lxskKlq9s5wxycKxn6H1IRuHi+a7G3xY6HW9fyJiXzw8aCGgCGTr5wlm7/evZ7vRLAL3K8BRU2e8GvjGENd+I60+5YUD6jIB0xr3082skfHUdf5QhortDXsPlNo41BFihPuF3Bj1z/ueaPOwJvRo68OvC5IP94WYTJnxGQr0fSmGCezuZl9/fte7tcxAzEZd6wcjhkHijXD8xkT/rFZAlA=='}, { 'name': 'X-Google-DKIM-Signature', 'value': 'v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=afGpZCmxB1t+YmjD7mTWufEZ4MjYKI8rwq3aqaGAyIg=; b=aFzP+V7NL5tDkbXhARkCKUaRp42rtGZt/9vP7rcyr2FvkoTp17g2VXE0nMsoSnPGu1 yrhKAio0MtnBfolQbhB4wkgSxzjjqOIZPsXdmkLvY050Uc1NgyvRoP3PPL4S3tC1qMUe 37YgLObVqVJq3cQuoywMmoee1+dADNHoUaoEdfAlykf7BGsSPuXR83amOQatbwbg7s/h ILsOu0RyGQ1h8xdrC9Yt2Be1UBvd7RQj5RF69+cnkwvPn8GwdqOysKK8H6z6mVYwo4F5 iEAyGAlrNsI9B4hjAwHUsPZeYsW11FKOtAFe2vw7iGaLKds0/2ZU9d66HO7oZRj2iLKG S8vQ=='}, {'name': 'X-Gm-Message-State', 'value': 'AGi0PuaMnPfOBKcQ1vDGs2fAmTvHM7nwLP3wYZoa3fhz1UzkOnRNHEAo hsWe2N/PAvc6FqBwfpprXLTM6n7GN1Lcga8Eu6/xP5YMFtBZJw=='}, {'name': 'X-Google-Smtp-Source', 'value': 'APiQypIPJl6C5dynu2EveW48Zvo9N+c9PAjnZ4G5bpzfegWFsn/2/OAwhegzcXhz7lGvXo+jpa6Piq+In9YyfN8lph8='}, {'name': 'X-Received', 'value': 'by 2002:ac8:4a98:: with SMTP id l24mr7578587qtq.223.1586353508681; Wed, 08 Apr 2020 06:45:08 -0700 (PDT)'}, {'name': 'MIME-Version', 'value': '1.0'}, {'name': 'From', 'value': 'Love Lundin <*****@*****.**>'}, {'name': 'Date', 'value': 'Wed, 8 Apr 2020 15:44:57 +0200'}, {'name': 'Message-ID', 'value': '<CAE18HTY=fptccQUWbqEqAQsfpXfdDV0bSih_RcBa1wAKn-TBEw@mail.gmail.com>'}, {'name': 'Subject', 'value': '2020-04-08 - TEST 1'}, {'name': 'To', 'value': 'Almen Bostäder <*****@*****.**>'}, {'name': 'Content-Type', 'value': 'multipart/alternative; boundary="0000000000005fcc6b05a2c7b599"'}], 'commonHeaders': {'returnPath': '*****@*****.**', 'from': ['Love Lundin <*****@*****.**>'], 'date': 'Wed, 8 Apr 2020 15:44:57 +0200', 'to': ['"Almen Bostäder" <*****@*****.**>'], 'messageId': '<CAE18HTY=fptccQUWbqEqAQsfpXfdDV0bSih_RcBa1wAKn-TBEw@mail.gmail.com>', 'subject': '2020-04-08 - TEST 1'}}, 'receipt': {'timestamp': '2020-04-08T13:45:10.346Z', 'processingTimeMillis': 647, 'recipients': ['*****@*****.**'], 'spamVerdict': {'status': 'DISABLED'}, 'virusVerdict': {'status': 'DISABLED'}, 'spfVerdict': {'status': 'GRAY'}, 'dkimVerdict': {'status': 'GRAY'}, 'dmarcVerdict': {'status': 'GRAY'}, 'action': {'type': 'Lambda', 'functionArn': 'arn:aws:lambda:eu-west-1:737354003986:function:gb-shovel-dev-main', 'invocationType': 'RequestResponse'}}}}]} handler.main(event, context)
def run(): drive_time_polygons = DriveTimePolygon.objects.all() drive_time_ids = [dtq.id for dtq in drive_time_polygons] does_not_exist = [] error_ids = [] exceptions = [] for drive_time_id in drive_time_ids: try: dtq = DriveTimeQuery.objects.get(pk=drive_time_id) except DriveTimeQuery.DoesNotExist: does_not_exist.append(drive_time_id) print(f'Skipping Drive Time ID {drive_time_id}') continue try: print(f'Working on Drive Time ID {drive_time_id}') bridges = NewYorkBridge.objects.filter(drive_time_queries__contains=[drive_time_id]) for bridge in bridges: ids_set = set(bridge.drive_time_queries) ids_set.remove(drive_time_id) bridge.drive_time_queries = list(ids_set) bridge.save() existing_polygons = DriveTimePolygon.objects.filter(drive_time_query=drive_time_id) delete_ = existing_polygons.delete() print(delete_) event = { 'drive_time_query': drive_time_id } handler.main(event, '') print(f'Complete {drive_time_id}!') except Exception as exc: print(f'Error on {drive_time_id}') print(f'Exception: {traceback.format_exc()}') error_ids.append(drive_time_id) exceptions.append(exc) for exc, drive_time_id in zip(error_ids, exceptions): print(f'{drive_time_id} | {exc}') print(f'Drive Time does not exist: {does_not_exist}') print(f'Failed IDs: {error_ids}')
def test_main_unhappy_path_int(): with open('fixtures/bad_insert.txt', 'r') as myfile: data = myfile.read() assert handler.main( { 'body': data, 'headers': { 'Content-Type': 'application/sparql-update' } }, "blank_context")['statusCode'] == 400
def test_main_int(): for test_case in test_cases: with open('fixtures/' + test_case['file'], 'r') as myfile: data = myfile.read() assert handler.main( { 'body': data, 'headers': { 'Content-Type': 'application/sparql-update' } }, "blank_context")['statusCode'] == 200
def assert_response(request, next_state, backend): response = handler.main(request, None) assert response["response"] assert backend["JOKES_STATE"] == next_state expected_response_wrapper = STATE_TO_RESPONSE_WRAPPER[next_state] assert sorted(response["response"].keys()) == sorted(expected_response_wrapper.keys) assert response["response"]["shouldEndSession"] == expected_response_wrapper.ends_session return response
def test_main_unhappy_path_unit(): with open('fixtures/decoded_query.txt', 'r') as myfile: data = myfile.read() assert handler.main( { 'body': data, 'headers': { 'Content-Type': 'application/x-www-form-urlencoded' } }, "blank_context") == { 'body': '[MalformedRequest] query string not properly escaped', # noqa 'statusCode': 422 }
def test_main_unknown_content_type_unit(): with open('fixtures/encoded_query.txt', 'r') as myfile: data = myfile.read() assert handler.main( { 'body': data, 'headers': { 'Content-Type': 'application/unknown' } }, "blank_contenxt" ) == { 'body': "[MalformedRequest] Invalid Content-Type: 'application/unknown'", # noqa 'statusCode': 422 }
def do_POST(self): log.info("Handling post") # Read the body. try: log.debug("Reading request") content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length).decode('utf-8') finally: self.rfile.close() log.debug("Processing request") response = handler.main( { 'body': body, 'headers': { 'Content-Type': self.headers['Content-Type'] } }, None) log.info("Response status code is %s", response['statusCode']) self.send_response(response['statusCode']) self.end_headers() if response['body']: self.wfile.write(bytes(response['body'], "utf8"))
#!/usr/bin/env python ''' author:Nianhz data:2012/2/3 ''' from handler import main if __name__ == "__main__": main()
def test_pipeline_failed_msg(self): msg = handler.main(pipeline_failed_event, {}) self.assertEqual(msg['title'], 'Pipeline action "Build" failed')
sys.path.insert( 0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) ) def generate_event(detail=None): """Generate a mock EventBridge event with the given detail.""" detail = {} if detail is None else detail return { 'Records': [ { 'source': 'testing.local', 'detail-type': 'Local Testing', 'detail': json.dumps(detail), } ] } if __name__ == '__main__': from handler import main with open('loandata.json') as file: event = generate_event(json.load(file)) response = main(event) logger.info('Reports: %s', json.dumps(response, indent=2)) with open('reports.json', 'w') as reports: json.dump(response, reports, indent=2)
(r"/hlinesP", HoughlinesPHandler), (r"/hcircles", HoughCirclesHandler), ] settings = dict( blog_title=u"Tornado Blog", template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), xsrf_cookies=False, cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__", debug=True, ) tornado.web.Application.__init__(self, handlers, **settings) self.db = torndb.Connection(host=options.mysql_host, database=options.mysql_database, user=options.mysql_user, password=options.mysql_password, charset='utf8') def main(): tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start() if __name__ == "__main__": main()
def main(): content = request.get_json(force=True) print('Json: ', content) return handler.main(content)