def test_raise_exception_on_S3_error(): # GIVEN we're running in lambda # mock the queue, but we won't examine it u.setup_aws_mocks() u.create_bucket() # WHEN a non existant file is processed # (S3 only guarantees eventual consistancy) bucket_name, key_name = 'bogus_bucket', 'firefox-bogus.exe' event = u.build_event(bucket_name, key_name) # THEN we raise an error (so AWS will retry) with pytest.raises(IOError): results = lambda_handler(event, u.dummy_context) # and function should not have returned assert 'results' not in locals().keys()
def test_pass_no_message_when_no_verbose(setter, fname): queue = u.setup_aws_mocks() bucket = u.create_bucket() # given that verbose is not set setter() # when a good file is processed bucket_name, key_name = u.upload_file(bucket, fname) event = u.build_event(bucket_name, key_name) response = lambda_handler(event, u.dummy_context) # THEN there should be no message count, msg_json = u.get_one_message(queue) try: msg_dict = json.loads(msg_json) msg = msg_dict['Message'] except ValueError: msg = "" # print things that will be useful to debug print("response:", response) print("message:", msg) print("count:", count) # actual criteria to pass assert "pass" in response['results'][0]['status'] assert count is 0 and msg is ""
def test_exclude_message_when_production(set_production_true, fname, key): u.setup_aws_mocks() bucket = u.create_bucket() # Given that PRODUCTION is missing or true set_production_true() # WHEN a bad file is processed: u.upload_file(bucket, fname, key) event = u.build_event(bucket.name, key) response = lambda_handler(event, u.dummy_context) print("response:", response) # THEN it should pass & be marked as excluded assert "pass" in response['results'][0]['status'] assert u.is_in("Excluded from validation", response['results'], 'results')
def test_always_log_output_issue_17(setter, fname, capsys): # mock the queue, but we won't examine it u.setup_aws_mocks() bucket = u.create_bucket() # Given that VERBOSE is in any state setter() # WHEN any file is processed bucket_name, key_name = u.upload_file(bucket, fname) event = u.build_event(bucket_name, key_name) results = lambda_handler(event, u.dummy_context) # THEN there should always be a message on stdout out, err = capsys.readouterr() # put useful information in failure output print("response: '{}'".format(results)) assert out != '' assert err == ''
def test_pass_message_when_verbose(setter, fname): queue = u.setup_aws_mocks() bucket = u.create_bucket() # Given that VERBOSE is set setter() # WHEN a good file is processed bucket_name, key_name = u.upload_file(bucket, fname) event = u.build_event(bucket_name, key_name) response = lambda_handler(event, u.dummy_context) print("response:", response) # THEN there should be no message count, msg_json = u.get_one_message(queue) msg_dict = json.loads(msg_json) msg = msg_dict['Message'] print("message:", msg) assert "pass" in response['results'][0]['status'] assert count is 1 and msg.startswith('pass for')
def test_no_exclude_message_when_not_production(set_production_false, fname): u.setup_aws_mocks() bucket = u.create_bucket() # Given that PRODUCTION is set to False set_production_false() # WHEN any file is processed u.upload_file(bucket, fname) event = u.build_event(bucket.name, fname) response = lambda_handler(event, u.dummy_context) # THEN there should be no mentions of skipping # count, msg = get_one_message(queue) # print things that will be useful to debug print("response:", response) # actual criteria to pass assert u.not_in("Excluded from validation", response['results'][0]['results'])
def test_fail_message_when_not_verbose(set_verbose_false, fname): queue = u.setup_aws_mocks() bucket = u.create_bucket() # Given that VERBOSE is not set set_verbose_false() # WHEN a bad file is processed u.upload_file(bucket, fname) event = u.build_event(bucket.name, fname) response = lambda_handler(event, u.dummy_context) # THEN there should be a message count, msg_json = u.get_one_message(queue) msg_dict = json.loads(msg_json) msg = msg_dict['Message'] # print things that will be useful to debug print("response:", response) print("message:", msg) print("count:", count) # actual criteria to pass assert "fail" in response['results'][0]['status'] assert count is 1 and msg.startswith('fail for')