def setUp(self): data.drop_data_base() self.customer1 = { "name": "Carlos Andrade", "email": "*****@*****.**", "password": "******", "nif": "242445678", "ccType": "Visa", "ccNumber": "4024007149497504", "ccValidity": "02/17" }
def test_validate_order(self): customer = requests.post("http://localhost:8080/api/customers", params=self.customer1).json() product1 = data.create_product("Cafe Expresso", "coffee", 2.3) product2 = data.create_product("Pipocas", "popcorn", 5.3) voucher1 = data.create_free_voucher(customer["id"]) voucher2 = data.create_discount_voucher(customer["id"]) payload = { "customerID": customer["id"], "pin": int(customer["pin"]), "vouchers": voucher1["id"]+","+voucher2["id"], "products": product1["id"]+","+product2["id"], "quantity": "3,2", "price": 23 } # Order with vouchers answer = requests.post("http://localhost:8080/api/orders", params=payload) self.assertEqual(answer.status_code, 200) orders = requests.get("http://localhost:8080/api/orders", params={"customerID": customer["id"]}).json() results = list(filter(lambda order: order["customerID"] == customer["id"] and len(order["vouchers"]) == 2 and len(order["products"]) == 2, orders)) self.assertTrue(len(results) == 1) # Order without vouchers payload["vouchers"] = "" answer = requests.post("http://localhost:8080/api/orders", params=payload) self.assertEqual(answer.status_code, 200) orders = requests.get("http://localhost:8080/api/orders", params={"customerID": customer["id"]}).json() results = list(filter(lambda order: order["customerID"] == customer["id"] and len(order["vouchers"]) == 0 and len(order["products"]) == 2, orders)) self.assertTrue(len(results) == 1) # Get transactions transactions = requests.get("http://localhost:8080/api/transactions", params={"customerID": customer["id"]}).json() results = list(filter(lambda transaction: transaction["customerID"] == customer["id"] and transaction["description"] == "Compra cafetaria", transactions)) self.assertTrue(len(results) == 2) data.drop_data_base()