def testHistoryGetByUser(self, client): """test get all data from reward history by user""" token = createTokenUser() res = client.get('/v1/reward_history/user', headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 200
def testTrashCategoriesGetByUser(self, client): """Test getting all data from trash category table using token from an user account""" token = createTokenUser() res = client.get('/v1/trash_category', headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 200
def testGetUserInformation(self, client): """test get user's jwt claims""" token = createTokenUser() res = client.get('/v1/auth', headers={'Authorization': 'Bearer ' + token}) res_json = json.loads(res.data) assert res.status_code == 200
def testGetAllByUser(self, client): """Test get all users data from users table using user token Only admin can see data from all users, hence request will get 403 respond""" token = createTokenUser() res = client.get('/v1/users/all', headers={'Authorization': 'Bearer ' + token}) assert res.status_code == 403
def testRefreshToken(self, client): """ test refreshing user's token""" token = createTokenUser() res = client.post('/v1/auth/refresh', headers={'Authorization': 'Bearer ' + token}) res_json = json.loads(res.data) assert res.status_code == 200
def testUserOrderGet(self, client): """test get all order data for corresponding user from orders table""" token = createTokenUser() res = client.get( 'v1/orders/user', headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 200
def testGetOneUserNotFound(self, client): """Test get a specific user data using another user's token. User with id 100 has not been created, hence will get a 404(Not Found) error""" token = createTokenUser() res = client.get('/v1/users/100', headers={'Authorization': 'Bearer ' + token}) assert res.status_code == 404
def testGetOneByUserInvalid(self, client): """Test get a specific user data, using another user's token. User in createTokenUser is user with id 1, hence will not be able to access user 2 profile, and raise a 403(forbidden) error""" token = createTokenUser() res = client.get('/v1/users/2', headers={'Authorization': 'Bearer ' + token}) assert res.status_code == 403
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 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 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
def testHistoryPost(self, client): """Test posting a new record to reward history table""" token = createTokenUser() history = {"reward_id": 1, "reward_name": "dummy_reward"} res = client.post('/v1/reward_history/user', data=json.dumps(history), headers={'Authorization': "Bearer " + token}, content_type='application/json') res_json = json.loads(res.data) TestRewardHistories.temp_history_id = res_json['id'] assert res.status_code == 200
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 testOrderPostInvalidAdress(self, client): """test posting a new order to table with invalid data (missing address) """ token = createTokenUser() order = { "photo": "args" } res = client.post('/v1/orders', data=json.dumps(order), headers={ 'Authorization': "Bearer " + token}, content_type='application/json') res_json = json.loads(res.data) assert res.status_code == 400
def testEditRewardUser(self, client): """test put a record in rewards table using user token""" token = createTokenUser() data = {"stock": 1} res = client.put('/v1/rewards/3', data=json.dumps(data), headers={'Authorization': 'Bearer ' + token}, content_type='application/json') res_json = json.loads(res.data) assert res.status_code == 200
def testUserPutOwnerEmail(self, client): """test put user data to table with email that is the same with the old email""" token = createTokenUser() data = {"email": "*****@*****.**"} 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 testOrderPutNotFound(self, client): """Test to put an order record with id=123456787, which is not in the table hence will raise 404(Not Found) error""" token = createTokenUser() order_status = { "status": "cancelled" } res = client.put('/v1/orders/123456787', data=json.dumps(order_status), headers={ 'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 404
def testUserPutEmailAlreadyListed2(self, client): """test put user data to table with mobile number that is already exist in database, hence will raise 400(bad request) error""" token = createTokenUser() data = {"email": "*****@*****.**"} 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 testUserPutInvalidEmail(self, client): """test put user data to table with invalid email format, hence will raise 400(bad request) error""" token = createTokenUser() data = { "email": "dadang@conello", } 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 testTrashCategoriesPutInvalidAdmin(self, client): """test put a record in tras category table with invalid token Token used is a non-admin token, hence will raise 403(forbidden) error """ token = createTokenUser() new_name = {"category_name": "newdummy"} 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 == 403
def testOrderPost(self, client): """test posting a new order to table with valid data an header""" token = createTokenUser() order = { "adress": "args", "time": "2018-03-29T13:34:00.000", "photo": "args" } res = client.post('/v1/orders', data=json.dumps(order), headers={ 'Authorization': "Bearer " + token}, content_type='application/json') res_json = json.loads(res.data) TestOrderManagement.temp_order_id = res_json['id'] assert res.status_code == 200
def testUserPut(self, client): """test put a record in users table with valid data""" token = createTokenUser() data = { "name": "dadang", "email": "*****@*****.**", "mobile_number": "08812121212", "password": "******" } 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 testTrashPutByUser(self, client): """test put a record in trashes table with invalid token Token used is a non-admin token, hence will raise 403(forbidden) error """ token = createTokenUser() new_details = { "trash_category_id": 1, "trash_name": "test", "photo": "test", "price": 100, "point": 1 } res = client.put('/v1/trash/{}'.format( TestTrashManagement.temp_trash_id), data=json.dumps(new_details), headers={'Authorization': "Bearer " + token}, content_type='application/json') assert res.status_code == 403
def testOrderPutDoneByUser(self, client): """Test put an order record using admin's token and status='done' User is not permitted to change status to done, hence will raise 403(forbidden) error""" token = createTokenUser() order_status = { "status": "done", "details": [ {"trash_id": 1, "qty": 2.9 }, {"trash_id": 2, "qty": 1.2 } ] } 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 testPutAttribute(self, client): """test put user attributes in user_attributes table""" token = createTokenUser() res = client.put('/v1/user_attributes', headers={'Authorization': 'Bearer ' + token}) assert res.status_code == 200
def testGetOneByUser(self, client): """test get user's data using token""" token = createTokenUser() res = client.get('/v1/users/1', headers={'Authorization': 'Bearer ' + token}) assert res.status_code == 200