def setUp(self): id = getId('Example') if id != None: removeUser(id) id = getId('Example2') if id != None: removeUser(id) register('Example', 'Password', '*****@*****.**')
def setUp(self): id = getId('Example') if id != None: removeUser(id) register('Example', 'Password', '*****@*****.**') id = getId('Example') offers.ids = 0 offers.offerList = [] offers.offerList.append(Offer(id, 300, None, 'white'))
def setUp(self): id = getId('Example') if id != None: removeUser(id) register('Example', 'Password', '*****@*****.**') id = getId('Example2') if id != None: removeUser(id) register('Example2', 'Password', '*****@*****.**') id = getId('Example') id2 = getId('Example2') day = datetime.date.today().day month = datetime.date.today().month year = datetime.date.today().year date = Date(day, month, year) pgnFile = open("example.pgn", 'r') pgn = pgnFile.read() pgnFile.close() postReplay(pgn, white_id=id, black_id=id2) postReplay(pgn, white_id=id + 10, black_id=id2)
def post(self): # parser = reqparse.RequestParser() # parser.add_argument('name', type=str,required=True, location='form',help='Invalid name') # parser.add_argument('password', type=str,required=True, location='form',help='Invalid password') # parser.add_argument('email', type=str,required=True, location='form',help='Invalid email') # args = parser.parse_args() args = request.form.to_dict() if isinstance(args['name'], str) == False: return {'message': "Invalid value!", 'where': "username"}, 400 if len(args['name']) < 6: return {'message': "Name too short!", 'where': "username"}, 400 if requests.checkForDuplicates("name", args['name']) == False: return {'message': "Name taken", 'where': "username"}, 400 if isinstance(args['password'], str) == False: return {'message': "Invalid value!", 'where': "password"}, 400 if len(args['password']) < 6: return {'message': "Password too short!", 'where': "password"}, 400 if isinstance(args['2ndpass'], str) == False: return {'message': "Invalid value!", 'where': "2ndpass"}, 400 if args['2ndpass'] != args['password']: return { 'message': "Passwords don't match!", 'where': "2ndpass" }, 400 if isinstance(args['email'], str) == False: return {'message': "Invalid value!", 'where': "email"}, 400 if args['email'].find('@') == -1 or args['email'].find('.') == -1: return {'message': "Incorrect E-mail!", 'where': "email"}, 400 if requests.checkForDuplicates("email", args['email']) == False: return {'message': "E-mail taken", 'where': "email"}, 400 id = requests.register(args['name'], args['password'], args['email']) access_token = create_access_token(identity=id) return { 'message': "Successfully registered", 'id': id, 'token': access_token }, 201
def testUser(self): #GET #bad id outcome = app.test_client().get('/users/bad_id') self.assertEqual(outcome.status_code, 404) #good one id = getId('Example') outcome = app.test_client().get('/users/' + str(id)) self.assertEqual(outcome.status_code, 200) self.assertEqual( json.loads(outcome.data)['userdata']['Name'], "Example") self.assertEqual( json.loads(outcome.data)['userdata']['E-Mail'], "*****@*****.**") self.assertEqual( json.loads(outcome.data)['userdata']['EloStandard'], 1200) #PUT #getting token needed for further tests outcome = app.test_client().post('/login', data={ 'name': 'Example', 'password': '******' }) token = json.loads(outcome.data)['access_token'] #good one outcome = app.test_client().put( '/users/' + str(id), headers={'Authorization': 'Bearer ' + token}, data={ 'name': 'Example2', 'password': '******' }) self.assertEqual(outcome.status_code, 201) self.assertEqual( json.loads(outcome.data)['userdata']['Name'], "Example2") #bad id outcome = app.test_client().put( '/users/bad_id', headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 404) register('Example', 'Password', '*****@*****.**') id2 = getId('Example') #not an owner outcome = app.test_client().put( '/users/' + str(id2), headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 403) #name taken outcome = app.test_client().put( '/users/' + str(id), headers={'Authorization': 'Bearer ' + token}, data={'name': 'Example'}) self.assertEqual(outcome.status_code, 400) #unauthorized outcome = app.test_client().put('/users/' + str(id)) self.assertEqual(outcome.status_code, 401) #bad token outcome = app.test_client().put('/users/' + str(id), headers={'Authorization': 'Non-token'}) self.assertEqual(outcome.status_code, 401) #login attempt with old data outcome = app.test_client().post('/login', data={ 'name': 'Example2', 'password': '******' }) self.assertEqual(outcome.status_code, 400) #login with new data outcome = app.test_client().post('/login', data={ 'name': 'Example2', 'password': '******' }) self.assertEqual(outcome.status_code, 201) #DELETE #bad id outcome = app.test_client().delete( '/users/bad_id', headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 404) #not an owner outcome = app.test_client().delete( '/users/' + str(id2), headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 403) #unauthorized outcome = app.test_client().delete('/users/' + str(id)) self.assertEqual(outcome.status_code, 401) #bad token outcome = app.test_client().delete( '/users/' + str(id), headers={'Authorization': 'Non-token'}) self.assertEqual(outcome.status_code, 401) #good one outcome = app.test_client().delete( '/users/' + str(id), headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 201)