def test_03_delete_product(): user_token = login_user("*****@*****.**", "Qwerty11")["session"]["accessToken"] headers = {"Authorization": f"Bearer {user_token}"} add_product = requests.post(url=absolute_url("/products"), json=product_model, headers=headers) response = add_product.json() product_id = response["data"][0]["id"] r = requests.delete(url=absolute_url(f"/products/{product_id}"), headers=headers) assert r.status_code == 204 product_details = requests.get(url=absolute_url(f"/products/{product_id}"), headers=headers) assert product_details.status_code == 404
def test_01_add_product(): user_token = login_user("*****@*****.**", "Qwerty11")["session"]["accessToken"] headers = {"Authorization": f"Bearer {user_token}"} r = requests.post(url=absolute_url("/products"), json=product_model, headers=headers) assert r.status_code == 201
def test_03_invalid_email(self): data = { "email": "*****@*****.**", "password": "******" } error = "Incorrect email or password" r = requests.post(url=absolute_url("/sessions"), json=data) response = r.json() assert r.status_code == 400 assert response['error']['message'] == error
def test_02_empty_password(self): data = { "email": "*****@*****.**", "password": "" } error = "\"password\" is not allowed to be empty" r = requests.post(url=absolute_url("/sessions"), json=data) response = r.json() assert r.status_code == 400 assert response['error']['message'] == error
def test_01_empty_email(self): data = { "email": "", "password": "******" } error = "\"email\" is not allowed to be empty" r = requests.post(url=absolute_url("/sessions"), json=data) response = r.json() assert r.status_code == 400 assert response['error']['message'] == error
def test_02_edit_product(): user_token = login_user("*****@*****.**", "Qwerty11")["session"]["accessToken"] headers = {"Authorization": f"Bearer {user_token}"} add_product = requests.post(url=absolute_url("/products"), json=product_model, headers=headers) response = add_product.json() product_id = response["data"][0]["id"] r = requests.put(url=absolute_url(f"/products/{product_id}"), json=product_model_edited, headers=headers) response = r.json() assert r.status_code == 200 assert response['data']['size'] == 15 assert response['data']['stockAvail'] == 15 assert response['data']['thc'] == 15 assert response['data']['cbd'] == 21
def test_01_positive_login(self): data = { "email": "*****@*****.**", "password": "******" } r = requests.post(url=absolute_url("/sessions"), json=data) response = r.json() assert r.status_code == 200 assert response['data']['user']['email'] == data['email'] assert response['data']['session']['accessToken']
def login_user(email: str, password: str): data = {"email": email, "password": password} r = requests.post(url=absolute_url('/sessions'), json=data) if r.status_code == 200: return r.json()['data'] raise Exception(f"Login attempt was not success. Data: {data}")