Beispiel #1
0
    def test_list_orders_with_superuser(self, payload_new_order,
                                        superuser_token_headers):
        # Create user_1 and add order
        cpf_1 = "123.422.566-88"
        user_1, _ = create_random_user(cpf=cpf_1)
        payload_new_order["cpf"] = user_1.cpf

        client.post(
            f"/orders/",
            headers=superuser_token_headers,
            json=payload_new_order,
        )

        # Create user_2 and add order
        cpf_2 = "345.767.877-22"
        user_2, _ = create_random_user(cpf=cpf_2)
        payload_new_order["cpf"] = user_2.cpf

        client.post(
            f"/orders/",
            headers=superuser_token_headers,
            json=payload_new_order,
        )

        response = client.get(f"/orders/", headers=superuser_token_headers)
        orders = response.json()

        assert len(orders) >= 2

        reseller_cpf_list = []
        for order in orders:
            reseller_cpf_list.append(order["reseller_cpf"])

        assert "12342256688" in reseller_cpf_list
        assert "34576787722" in reseller_cpf_list
Beispiel #2
0
    def test_list_orders_with_superuser_and_cpf_query(self, payload_new_order,
                                                      superuser_token_headers):
        # Create user_1 and add order
        cpf_1 = "874.343.545-12"
        user_1, _ = create_random_user(cpf=cpf_1)
        payload_new_order["cpf"] = user_1.cpf

        client.post(
            f"/orders/",
            headers=superuser_token_headers,
            json=payload_new_order,
        )

        # Create user_2 and add order
        cpf_2 = "433.656.343-11"
        user_2, _ = create_random_user(cpf=cpf_2)
        payload_new_order["cpf"] = user_2.cpf

        client.post(
            f"/orders/",
            headers=superuser_token_headers,
            json=payload_new_order,
        )

        response = client.get(
            f"/orders/?cpf=43365634311",
            headers=superuser_token_headers,
        )
        orders = response.json()

        assert len(orders) == 1
        assert orders[0]["reseller_cpf"] == "43365634311"
    def test_create_order_and_validate_status_with_approved(self):
        code = random_lower_string()
        date = datetime.date.today()
        value = 254.65
        cpf = config.CPFS_WITH_AUTO_APPROVE[0]

        user, _ = create_random_user(cpf=cpf)

        order_in = OrderCreate(code=code, date=date, value=value, cpf=cpf)
        order = crud.order.create_with_reseller(db_session, obj_in=order_in)

        assert user.cpf == order.reseller_cpf
        assert order.status.name == "APPROVED"
Beispiel #4
0
    def test_create_order_with_success(self, payload_new_order,
                                       normal_user_token_headers):
        cpf = "123.456.678-99"
        user, _ = create_random_user(cpf=cpf)
        payload_new_order["cpf"] = user.cpf

        response = client.post(
            f"/orders/",
            headers=normal_user_token_headers,
            json=payload_new_order,
        )

        assert response.status_code == 201
        assert response.json()["order_status"] == "IN_VALIDATION"
Beispiel #5
0
    def test_get_cashback_with_normal_user(self, payload_new_order):
        # Create user
        cpf = "343.655.878-33"
        user, user_pass = create_random_user(cpf=cpf)
        payload_new_order["cpf"] = user.cpf

        headers = user_authentication_headers(user.email, user_pass)

        # Add order
        payload_new_order["cpf"] = user.cpf
        client.post(
            f"/orders/", headers=headers, json=payload_new_order,
        )

        # Get total cashback
        response = client.get(f"/cashback/{user.cpf}/", headers=headers,)
        assert response.status_code == 200
        assert response.json() == {"cpf": "34365587833", "credit": 2825}
Beispiel #6
0
    def test_list_orders_with_normal_user(self, payload_new_order):
        cpf = "001.456.678-33"
        user, user_pass = create_random_user(cpf=cpf)
        payload_new_order["cpf"] = user.cpf

        headers = user_authentication_headers(user.email, user_pass)

        client.post(
            f"/orders/",
            headers=headers,
            json=payload_new_order,
        )

        response = client.get(f"/orders/", headers=headers)
        orders = response.json()

        assert len(orders) == 1
        assert orders[0]["reseller_cpf"] == "00145667833"
Beispiel #7
0
    def test_get_cashback_with_superuser(
        self, payload_new_order, superuser_token_headers
    ):
        # Create user
        cpf = "345.123.434-55"
        user, _ = create_random_user(cpf=cpf)

        # Add order
        payload_new_order["cpf"] = user.cpf
        client.post(
            f"/orders/",
            headers=superuser_token_headers,
            json=payload_new_order,
        )

        # Get total cashback
        response = client.get(
            f"/cashback/{user.cpf}/", headers=superuser_token_headers,
        )
        assert response.status_code == 200
        assert response.json() == {"cpf": "34512343455", "credit": 1586}
Beispiel #8
0
    def test_api_get_cashback_with_superuser(self, payload_new_order,
                                             superuser_token_headers):
        # Create user
        cpf = "341.343.000-12"
        user, _ = create_random_user(cpf=cpf)

        # Add order
        payload_new_order["cpf"] = user.cpf
        client.post(
            f"/orders/",
            headers=superuser_token_headers,
            json=payload_new_order,
        )

        # Get total cashback
        response = client.get(
            f"/cashback/{user.cpf}/",
            headers=superuser_token_headers,
        )
        assert response.status_code == 200
        assert response.json()["credit"] >= 0
Beispiel #9
0
def normal_user():
    user, _ = create_random_user()
    return user
Beispiel #10
0
def normal_user_token_headers():
    user, password = create_random_user()
    headers = user_authentication_headers(user.email, password)
    return headers