def test_db_data(self, setup_db): params = {"name": "UPADTE_NAME"} client.put(f"/projects/{1}", json=params) project = setup_db.query(Project).filter(Project.id == 1).first() assert project.name == "UPADTE_NAME"
def test_invitations_reject_valid(self, client): token = create_token1() res = client.put('/api/invitations/reject/3', headers={'Authorization':'Bearer ' + token}, content_type='application/json') res_json = json.loads(res.data) if res.status_code != 200: raise ValueError('The res.status_code must be 200, please check your code')
def testPutConfirmed(self, client): """Test put an order record using admin's token and status='confirmed'""" token = createTokenAdmin() order_status = { "status": "confirmed" } res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps( order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 200
def test_response(self, setup_db): params = {"name": "UPADTE_NAME"} response = client.put(f"/projects/{1}", json=params) assert response.status_code == 200 assert response.json() == { "id": 1, "name": "UPADTE_NAME", }
def test_invitations_accept_invalid_no_token(self, client): """ test invalid accept without token """ res = client.put('/api/invitations/accept/1', content_type='application/json') res_json = json.loads(res.data) if res.status_code != 401: raise ValueError('The res.status_code must be 401, please check your code')
def testTrashCategoriesPutInvalidId(self, client): """test put a record in trash category table with invalid id. 'none' is an invalid id, hence will raise a 404(Not Found) error""" token = createTokenAdmin() new_name = {"category_name": "dummyname"} res = client.put('/v1/trash_category/none', data=json.dumps(new_name), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 404
def testPutConfirmedByUser(self, client): """Test put an order record using user's token and status='confirmed' User is not permitted to change status to confirmed, hence will raise 403(forbidden) error""" token = createTokenUser() order_status = { "status": "confirmed" } res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps( order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 403
def testUserPutMobileNumberAlreadyListed(self, client): """put user data to table with mobile number that is already in the table, hence will get 400 error code""" token = createTokenUser() data = {"mobile_number": "0811221122112"} res = client.put('/v1/users', data=json.dumps(data), headers={'Authorization': 'Bearer ' + token}, content_type='application/json') res_json = json.loads(res.data) assert res.status_code == 400
def testUserPutMobileNumberOwner(self, client): """put user data to table with mobile number that is as same as old number""" token = createTokenUser() data = {"mobile_number": "08812121212"} res = client.put('/v1/users', data=json.dumps(data), headers={'Authorization': 'Bearer ' + token}, content_type='application/json') res_json = json.loads(res.data) assert res.status_code == 200
def test_if_store_edit_returns_406_if_the_paylod_is_not_json(): response = client.put(url_for('store_bp.store_edit'), data="teste") expected_return = { "status": "Error", "status_code": 406, "message": "Payload is not a JSON" } assert response.status_code == 406 assert json.loads(response.data) == expected_return
def testOrderPutCancelled(self, client): """Test put order record with status 'cancelled' using valid token.""" token = createTokenUser() order_status = { "status": "cancelled" } res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps( order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 200
def test_if_store_edit_returns_400_if_the_json_is_invalid(create_store): response = client.put(url_for('store_bp.store_edit'), json={"name": "Fake store edited"}) expected_return = { "status": "Error", "status_code": 400, "message": "Fields missing in JSON", } assert response.status_code == 400 assert json.loads(response.data) == expected_return
def testTrashCategoriesPut(self, client): """test put a record in tras category table with valid token and data""" token = createTokenAdmin() new_name = {"category_name": "newdummy", "status": False} res = client.put('/v1/trash_category/{}'.format( TestTrashManagement.temp_category_id), data=json.dumps(new_name), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 200
def testOrderPutCancelledByAdmin(self, client): """Test put an order record using admin's token and status='cancelled' Admin permitted to reject, but not permitted to cancel hence will raise 403(forbidden) error""" token = createTokenAdmin() order_status = { "status": "cancelled" } res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps( order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 403
def testOrderPutInvalidStatus(self, client): """test put an order record using status 'cancelledmaybe' which is not a valid options for status""" token = createTokenUser() order_status = { "status": "cancelledmaybe" } res = client.put('/v1/orders/{}'.format(TestOrderManagement.temp_order_id), data=json.dumps( order_status), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 400
def testUserPutInvalidMobileNumber(self, client): """test put user data to table with invalid mobile number format, hence will raise 400(bad request) error""" token = createTokenUser() data = {"mobile_number": "812121212"} res = client.put('/v1/users', data=json.dumps(data), headers={'Authorization': 'Bearer ' + token}, content_type='application/json') res_json = json.loads(res.data) assert res.status_code == 400