def test_invalid_login(email="fakeemail", pw="INVALIDPASSWORD"): """ Invalid credentials should not allow a user to log in. """ resp = login(email=email, pw=pw) check_status(resp, code=401, fields=['status']) print (SUCCESS("Invalid login test", user=email, passwd=pw))
def test_logout(token): """ An authenticated token should be able to log itself out, removing it from the database. """ resp = logout(token) check_status(resp, fields=['status']) assert resp.json()['status'] == 'success', \ FAILURE("Logout did not return success!") print (SUCCESS("Logout test", token=token))
def test_post_results(token, result_id, **overrides): params = {'user_token': token} params.update(get_example_data(overrides)) for key, val in params.items(): if isinstance(val, list): params[key] = json.dumps(params[key]) resp = do_post('/api/test_result/%s/edit' % str(result_id), params) check_status(resp, fields=[]) print (SUCCESS("Post Test Results data"))
def test_new_set(token): params = {'user_token':token, } resp = do_post('/api/test_set/create', params) check_status(resp, fields=['set_id']) set_id = resp.json()['set_id'] print (SUCCESS("Create new Test Set", set_id=set_id, )) return set_id
def test_authenticated(token): """ An authenticated token should be able to call methods that require authentication. """ resp = testfunc(token) check_status(resp, fields=['status', 'your_email']) json = resp.json() assert json['status'] == 'success', \ FAILURE("testfunc did not return status:success!", token=token) assert json['your_email'] == Context.email, \ FAILURE("testfunc returned wrong email!", token=token) print (SUCCESS("Authenticated method", token=token))
def test_authenticated(token): """ An authenticated token should be able to call methods that require authentication. """ resp = testfunc(token) check_status(resp, fields=['status', 'your_email']) json = resp.json() assert json['status'] == 'success', \ FAILURE("testfunc did not return status:success!", token=token) assert json['your_email'] == Context.email, \ FAILURE("testfunc returned wrong email!", token=token) print(SUCCESS("Authenticated method", token=token))
def test_start_mobile(token, set_id): print token params = {'user_token':token, 'set_id':set_id, } resp = do_post('/api/start_test/mobile', params) check_status(resp, fields=['result_id', 'config']) js = resp.json() assert_valid_config(js['config']) print (SUCCESS("Start mobile test", conf=truncate_repr(js['config']), result_id=js['result_id'] )) return js['result_id'] #, js['config']
def test_valid_login(): """ Accounts with valid user/pass should be able to login and get an user_token. """ ensure_default_account() resp = login() check_status(resp, fields=['user_token']) json = resp.json() token = json['user_token'] assert token != None and token != '', FAILURE("Login returned empty user_token!") assert len(token) > 64, FAILURE("user_token too small?") print (SUCCESS("Valid login test", user=Context.email, passwd=Context.passwd)) return token
def test_get_results(token, result_id, **overrides): params = {'user_token':token, } extra_columns = [ 'download_throughputs_avg', 'download_latencies_avg', 'upload_throughputs_avg', 'upload_latencies_avg', ] resp = do_post('/api/test_result/%s' % str(result_id), params) check_status(resp, fields=TestResult.get_public_columns().keys() + extra_columns) data = get_example_data(overrides) json_resp = resp.json() for col in data: validate_col(col, data[col], json_resp[col]) print (SUCCESS("Retrieve Test Results data", data=truncate_repr(data, priority=overrides), )) return resp.json()
def get_token(): resp = login() check_status(resp, fields=['user_token']) return resp.json()['user_token']
def test_unauthenticated(token="asdfdsasdf"): """ An invalid token should not be able to call authenticated methods. """ resp = testfunc(token) check_status(resp, code=401, fields=['status']) print(SUCCESS("Unauthenticated method", token=token))