def test_advancedtest_fields(self): xl = excelDataFileLib(testInputDataFile = self.inputCsvFile) xl.loadTestData() e = xl.testDataInputs[0] response = requestsLib(url = e.url, payload = e.input).response() self.assertEqual(e.url, response.url) self.assertEqual(response.status_code, e.expectedHttpStatus) self.assertEqual(response.json(),ast.literal_eval(e.expectedOutput))
def test_results_count(self): xl = excelDataFileLib(testInputDataFile = self.inputCsvFile) xl.loadTestData() inputs = xl.testDataInputs results = [] for e in inputs: response = requestsLib(url = e.url, payload = e.input).response() testResult = TestDataOutput(e, actualOutput = json.dumps(response.json()), actualHttpStatus = response.status_code, actualError = None) results.append(testResult) wb = openpyxl.load_workbook(self.inputCsvFile) sheet = wb.get_active_sheet() self.assertEqual(results.__len__(),sheet.get_highest_row()-1)
def test_compare_jsons_type(self): xl = excelDataFileLib(testInputDataFile = self.inputCsvFile) xl.loadTestData() inputs = xl.testDataInputs results = [] for e in inputs: response = requestsLib(url = e.url, payload = e.input).response() testResult = TestDataOutput(e, actualOutput = json.dumps(response.json()), actualHttpStatus = response.status_code, actualError = None) results.append(testResult) dict1 = json.loads(results[0].actualOutput) dict2 = json.loads(results[0].expectedOutput) self.assertEqual(cmp(dict1, dict2), 0)
def test_requestslib_no_header_response_code(self): url = "http://10.135.0.65:8085/api/effectiveapr" headers = {"HTTP-CORRELATION-ID" :'337fb81b-ef9a-4c1d-8f7e-e5f3ea2f6cb5', "Content-Type" : 'application/json'} e = { "contract_date":"2015-07-01", "first_payment_date":"2015-08-01", "number_of_payments":36, "amount_financed":79384.80, "estimated_apr":0.0349, "lender_fees":0, "monthly_payment":2325.79, "last_payment":2325.79 } r = requestsLib(url = url, headers = headers, payload = e) self.assertEqual(r.response().status_code, 486)
def test_requestslib_no_header_response_message(self): url = "http://10.135.0.65:8085/api/effectiveapr" e = { "contract_date":"2015-07-01", "first_payment_date":"2015-08-01", "number_of_payments":36, "amount_financed":79384.80, "estimated_apr":0.0349, "lender_fees":0, "monthly_payment":2325.79, "last_payment":2325.79 } headers = {"HTTP-CORRELATION-ID" :'337fb81b-ef9a-4c1d-8f7e-e5f3ea2f6cb5', "Content-Type" : 'application/json'} r = requestsLib(url = url, headers = headers, payload = e) response = r.response().json() print response self.assertEqual(response['error']['message'], 'Invalid date order - First Payment Date must be greater than Contract Date')
def test_write_excel_body(self): xl = excelDataFileLib(testInputDataFile = self.inputCsvFile) xl.loadTestData() inputs = xl.testDataInputs results = [] for e in inputs: response = requestsLib(url = e.url, payload = e.input).response() testResult = TestDataOutput(e, actualOutput = json.dumps(response.json()), actualHttpStatus = response.status_code, actualError = None) results.append(testResult) xl.writeTestDataResults(testDataResults = results) outfile = xl.getResultsFilePath() wb = openpyxl.load_workbook(outfile) sheet = wb.get_active_sheet() self.assertEqual(sheet.cell(row = 2, column = 1).value, results[0].url) self.assertEqual(sheet.cell(row = 2, column = 4).value, results[0].expectedHttpStatus) self.assertEqual(sheet.cell(row = 2, column = 5).value, results[0].expectedError) self.assertEqual(sheet.cell(row = 2, column = 7).value, results[0].actualHttpStatus) self.assertEqual(sheet.cell(row = 2, column = 8).value, results[0].actualError)