def tearDown(self): id = getId('Example') if id != None: removeUser(id) id = getId('Example2') if id != None: removeUser(id)
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 testReplay(self): id = getId('Example') outcome = getReplayList(id) id = outcome[0][0] outcome = app.test_client().post('/login', data={ 'name': 'Example', 'password': '******' }) token = json.loads(outcome.data)['access_token'] # unauthorized outcome = app.test_client().get('/replays/' + str(id)) self.assertEqual(outcome.status_code, 401) # bad token outcome = app.test_client().get('/replays/' + str(id), headers={'Authorization': 'Non-token'}) self.assertEqual(outcome.status_code, 401) #bad id outcome = app.test_client().get( '/replays/bad_id', headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 404) # good one outcome = app.test_client().get( '/replays/' + str(id), headers={'Authorization': 'Bearer ' + token}) self.assertEqual(outcome.status_code, 200) print(json.loads(outcome.data)['replay'])
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 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)
def tearDown(self): id = getId('Example') if id != None: removeUser(id) offers.ids = 0 offers.offerList = []