Example #1
0
    def test_get_wrong_url(self):
        rvs_params = [
            {"url": "/model/user/", "param": "abc", "payload": purchase_data_example.copy()},
            {"url": "/models/", "param": "-12", "payload": purchase_data_example.copy()},
            {"url": "/model/user/", "param": "", "payload": purchase_data_example.copy()},
        ]

        for rv_params in rvs_params:
            rv = self.client.get(rv_params["url"] + rv_params["param"], json=rv_params["payload"])
            self.assertEqual(404, rv.status_code)
Example #2
0
    def test_price(self):
        test_example_list = [purchase_data_example.copy() for _ in range(2)]
        test_example_list[0]["price"] = "tak"
        test_example_list[1]["price"] = ""

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_price"], check_data(test_example))
Example #3
0
    def test_columns(self):
        test_example = purchase_data_example.copy()
        test_example.pop("price")

        self.assertEqual(errors["wrong_columns"], check_data(test_example))
        self.assertEqual(errors["wrong_columns"], check_data({}))
        self.assertNotEqual(errors["wrong_columns"], check_data(purchase_data_example))
Example #4
0
    def test_offered_discount(self):
        test_example_list = [purchase_data_example.copy() for _ in range(3)]
        test_example_list[0]["offered_discount"] = "tak"
        test_example_list[1]["offered_discount"] = ""
        test_example_list[2]["offered_discount"] = "2.0"

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_offered_discount"], check_data(test_example))
Example #5
0
    def test_product_id(self):
        test_example_list = [purchase_data_example.copy() for _ in range(3)]
        test_example_list[0]["product_id"] = "tak"
        test_example_list[1]["product_id"] = ""
        test_example_list[2]["product_id"] = "2.0"

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_product_id"], check_data(test_example))
Example #6
0
    def test_delivery_company(self):
        test_example_list = [purchase_data_example.copy() for _ in range(3)]
        test_example_list[0]["delivery_company"] = "tak"
        test_example_list[1]["delivery_company"] = ""
        test_example_list[2]["delivery_company"] = "2.0"

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_delivery_company"], check_data(test_example))
Example #7
0
    def test_purchase_timestamp(self):
        test_example_list = [purchase_data_example.copy() for _ in range(3)]
        test_example_list[0]["purchase_timestamp"] = "2021-04-01T15:52:47:12"
        test_example_list[1]["purchase_timestamp"] = ""
        test_example_list[2]["purchase_timestamp"] = "2021-04-73T15:52:47"

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_purchase_timestamp"], check_data(test_example))
Example #8
0
    def test_street_number(self):
        test_example_list = [purchase_data_example.copy() for _ in range(3)]
        test_example_list[0]["street"] = "pl. Brzoskwiniowa 11-2"
        test_example_list[1]["street"] = "pl. Brzoskwiniowa 11.53"
        test_example_list[2]["street"] = "pl. Brzoskwiniowa 11+53"
        test_example_list[2]["street"] = "pl. Brzoskwiniowa 11/5."

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_street_number"], check_data(test_example))
Example #9
0
    def test_street(self):
        test_example_list = [purchase_data_example.copy() for _ in range(3)]
        test_example_list[0]["street"] = "tak"
        test_example_list[1]["street"] = "ulica ulica"
        test_example_list[2]["street"] = "ulica 23"
        test_example_list[2]["street"] = ""

        for test_example in test_example_list:
            self.assertEqual(errors["wrong_street"], check_data(test_example))
Example #10
0
    def test_get_wrong_data(self):
        changes = [
            ("purchase_timestamp", "2021-04-01T15:52:47:242515", "wrong_purchase_timestamp"),
            ("delivery_company", "UPS", "wrong_delivery_company"),
            ("product_id", "tak", "wrong_product_id"),
            ("price", -14, "wrong_price"),
            ("offered_discount", "nie", "wrong_offered_discount"),
            ("street", "pl. Brzoskwiniowa", "wrong_street"),
            ("street", "pl. Brzoskwiniowa 11.53", "wrong_street_number")
        ]
        payloads = []

        for change in changes:
            temp_data = purchase_data_example.copy()
            temp_data[change[0]] = change[1]
            payloads.append(temp_data)

        for i, payload in enumerate(payloads):
            rv = self.client.get("/model", json=payload)
            self.assertEqual(errors[changes[i][2]]["message"], rv.get_json()["message"])
            self.assertEqual(errors[changes[i][2]]["code"], rv.status_code)
Example #11
0
 def test_get_wrong_columns(self):
     temp_data = purchase_data_example.copy()
     temp_data.pop("street")
     rv = self.client.get("/model", json=temp_data)
     self.assertEqual(errors["wrong_columns"]["message"], rv.get_json()["message"])
     self.assertEqual(422, rv.status_code)