def test_report(self): project_id_1 = gen_test_project() gen_report(project_id_1) project_id_2 = gen_test_project() gen_report(project_id_2) reports = get_reports() self.assertGreaterEqual(len(reports), 2)
def test_report(self): project_id = gen_test_project() report = gen_report(project_id) report_from_s3 = get_report(project_id) self.assertEqual(report["config"]["name"], "test") self.assertEqual(report_from_s3["config"]["name"], "test")
def test_request_get(self): # create project project_id_1 = gen_test_project() gen_report(project_id_1) project_id_2 = gen_test_project() gen_report(project_id_2) project_id_3 = gen_test_project() # get state event = { "httpMethod": "GET", "requestContext": { "domainName": "test.local" }, } result = lambda_handler(event, {}) print(result["body"]) self.assertEqual(result["statusCode"], 200) self.assertTrue(result["body"].startswith("<!doctype"))
def test_report(self): project_id = gen_test_project() report = gen_report(project_id) report_from_s3 = json.loads( read_key_or_default(f"{project_id}/report.json", "")) self.assertEqual(report["config"]["name"], "test") self.assertEqual(report_from_s3["config"]["name"], "test")
def test_request_get(self): # create project project_id = gen_test_project() # get state event = { "httpMethod": "GET", "pathParameters": { "projectId": project_id }, "requestContext": { "domainName": "test.local" }, } result = lambda_handler(event, {}) self.assertEqual(result["statusCode"], 200) self.assertTrue(result["body"].startswith("{"))
def test_request_post_invalid(self): # create project project_id = gen_test_project() # post state event = { "httpMethod": "POST", "body": "test", "pathParameters": { "projectId": project_id }, "requestContext": { "domainName": "test.local" }, } result = lambda_handler(event, {}) self.assertEqual(result["statusCode"], 500)
def test_request_get(self): # create project project_id = gen_test_project() tf_raw_state = read_file("test_data/terraform.teststate") write_key(f"{project_id}/terraform.tfstate", tf_raw_state) report = gen_report(project_id) print(report) # get state event = { "httpMethod": "GET", "pathParameters": {"projectId": project_id}, "requestContext": {"domainName": "test.local"}, } result = lambda_handler(event, {}) print(result["body"]) self.assertEqual(result["statusCode"], 200) self.assertTrue(result["body"].startswith("<!doctype"))
def test_request_post(self): # create project project_id = gen_test_project() # post state raw_tf = read_file("test_data/terraform.teststate") event = { "httpMethod": "POST", "body": raw_tf, "pathParameters": { "projectId": project_id }, "requestContext": { "domainName": "test.local" }, } result = lambda_handler(event, {}) self.assertEqual(result["statusCode"], 200) self.assertTrue(result["body"].startswith("{")) s3_data = read_key_or_default(f"{project_id}/terraform.tfstate", "NONE") tf_meta = get_tf_metadata(s3_data, True) self.assertNotEqual(tf_meta["terraform_version"], "invalid")
def test_generated(self): project_id = gen_test_project() config = get_config(project_id) self.assertEqual(config["name"], "test")