def test_admin_view(client,session): #not loggedin users rest_login_check(client,'/admin/') client = loggin_as_client() #loggged in as client status = '401 UNAUTHORIZED' rest_check_status(client,'/admin/',status,1) #logged in as admin client = loggin_as_admin() #get self details and admin of another account check_json_status_ok(client,'/admin/1','get') status = '401 UNAUTHORIZED' rest_check_status(client,'/admin/',status,2,methods=['get','put','delete']) #get index check_index_datatable(client,'/admin/',num_rows=1) #create new admin and check check_json_status_ok(client,'/admin/','post',data={'email':'*****@*****.**', 'displayname':'Admin3'}) check_index_datatable(client,'/admin/',num_rows=2) #update admin and check check_json_status_ok(client,'/admin/1','put',data={'email':'*****@*****.**', 'displayname':'Admin3'}) check_json_status_ok(client,'/admin/5','delete') status = '405 METHOD NOT ALLOWED' rest_check_status(client,'/admin/',status,1,methods=['delete'])
def test_client_view(client,session): #not loggedin users rest_login_check(client,'/client/') client = loggin_as_client() #loggged in as client status = '401 UNAUTHORIZED' rest_check_status(client,'/client/',status,1) #logged in as admin client = loggin_as_admin() #get for same account client and another check_json_status_ok(client,'/client/3','get') status = '401 UNAUTHORIZED' rest_check_status(client,'/client/',status,4,methods=['get','put','delete']) #get index check_index_datatable(client,'/client/',num_rows=1) #create new client and check check_json_status_ok(client,'/client/','post',data={'email':'*****@*****.**', 'displayname':'Client3'}) check_index_datatable(client,'/client/',num_rows=2) #update client and check check_json_status_ok(client,'/client/3','put',data={'email':'*****@*****.**', 'displayname':'Admin3'}) check_json_status_ok(client,'/client/3','delete')
def test_post(session, register_testview): client = loggin_as_admin() #empty post resp = client.post("/test/", follow_redirects=True).json assert resp['status'] == 0 assert 'Error in the Column1 field - This field is required' in resp['msg'],\ 'Empty form submit is not producing correct error' resp = client.post("/test/",follow_redirects=True,\ data={'column1':'tests','column2':'123'}).json assert resp['status'] == 1 assert 1 == BaseTestModel.query.count( ), 'Post failed to create new entry in DB' assert '405 METHOD NOT ALLOWED' == client.post( "/test/2", follow_redirects=True).status, 'Post with id is not allowed'
def test_user_view(client,session): #not loggedin users rest_login_check(client,'/user/') client = loggin_as_admin() rest_allowed_methods_check(client,'/user/',methods=['index','post','delete']) #try to access id not owned by self status = '405 METHOD NOT ALLOWED' rest_check_status(client,'/user/',status,4,methods=['get','put']) check_json_status_ok(client,'/user/1','get') check_json_status_nok(client,'/user/1','put') check_json_status_ok(client,'/user/1','put',data={'email':'*****@*****.**', 'displayname':'Hellow'})
def test_guest_portal(session, client): #test unifi entry point site1 = Wifisite.query.get(1) #with emptry MAC/APMAC res = client.get(get_guestentry_url(site1)).status assert '404 NOT FOUND' == res, 'Getting :%s instead 404 for\ with empty MAC/APMAC' % res #with invalid MAC/APMAC res = client.get( get_guestentry_url(site1, mac='11:22:33:44', apmac='22:44:55')).status assert '404 NOT FOUND' == res, 'Getting :%s instead 404 for\ with empty MAC/APMAC' % res #with invalid sitekey site2 = Wifisite(sitekey='test', backend_type='unifi') res = client.get( get_guestentry_url(site2, mac=randomMAC(), apmac=randomMAC())).status assert '404 NOT FOUND' == res, 'Getting :%s instead 404 for\ with invalid sitekey' % res #with everything valid res = client.get( get_guestentry_url(site1, mac=randomMAC(), apmac=randomMAC())).status assert '302 FOUND' == res, 'Getting :%s instead 302 FOUND for\ with valid data' % res assert 1 == Guesttrack.query.count(), 'More than one guesttrack ' #check demo is not set with no-auth visit mac = randomMAC() res = client.get( get_guestentry_url(site1, mac=mac, apmac=randomMAC(), demo=1)).status assert '302 FOUND' == res, 'Getting :%s instead 302 FOUND for\ with valid data' % res assert 0 == Guesttrack.query.filter_by(devicemac=mac).first().demo,\ 'Demo is not rejected for non auth visits ' #check demo is not set with auth visit mac = randomMAC() admin = loggin_as_admin() res = admin.get( get_guestentry_url(site1, mac=mac, apmac=randomMAC(), demo=1)).status assert '302 FOUND' == res, 'Getting :%s instead 302 FOUND for\ with valid data' % res assert 1 == Guesttrack.query.filter_by(devicemac=mac).first().demo,\ 'Demo is rejected for auth visits '
def test_index(session, register_testview): client = loggin_as_admin() resp = client.get("/test/", follow_redirects=True).json assert resp[ 'recordsTotal'] == '0', 'Index view not returning proper datatble resp' testmodel = BaseTestModel(column1='test1', column2='test2', column3='test3', column4='test4') testmodel.save() resp = client.get("/test/", follow_redirects=True).json assert resp[ 'recordsTotal'] == '1', 'Index view not returning proper datatble resp'
def test_get(session, register_testview): client = loggin_as_admin() resp = client.get("/test/1", follow_redirects=True).json assert 'Unknown :TestView ID specified' == resp['msg'], 'Unknown ID not \ giving expected error' assert resp['status'] == 0 testmodel = BaseTestModel(column1='test1', column2='test2', column3='test3', column4='test4') testmodel.save() resp = client.get("/test/1", follow_redirects=True).json assert resp['status'] == 1 assert resp['data'] == testmodel.to_dict()
def test_delete(session, register_testview): client = loggin_as_admin() assert '405 METHOD NOT ALLOWED' == client.delete( "/test/", follow_redirects=True).status testmodel = BaseTestModel(column1='test1', column2='test2', column3='test3', column4='test4') testmodel.save() resp = client.delete( "/test/1", follow_redirects=True, ).json assert resp['status'] == 1 assert 0 == BaseTestModel.query.count(), 'Delete failed to delete entry'
def test_put(session, register_testview): client = loggin_as_admin() #invalid put resp = client.put("/test/3", follow_redirects=True).json resp['status'] == 0 assert '405 METHOD NOT ALLOWED' == client.put("/test/", follow_redirects=True).status testmodel = BaseTestModel(column1='test1', column2='test2', column3='test3', column4='test4') testmodel.save() resp = client.put("/test/1",follow_redirects=True,\ data={'column1':'tests','column4':'123'}).json assert resp['status'] == 1 assert 1 == BaseTestModel.query.count(), 'Put failed to update entry' assert 'tests' == BaseTestModel.query.get( 1).column1, 'Put failed to update entry'