import unittest from test3 import test_request import json from util import test_json from util import test_excel from case import testconfig import requests class TestDjango(unittest.TestCase): @classmethod def setUpClass( cls ): cls .alldata = test_json.testjson() @classmethod def tearDownClass( cls ): url = "http://127.0.0.1:9090/web/login/" + "?username=" + "admin" + "&" + "password=" + "admin123." res = requests.get(url = url, headers = { "user-agent" : "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" }) url = "http://127.0.0.1:9090/web/delall/" requests.post(url = url, headers = { "user-agent" : "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" }, cookies = res.cookies ) def get_cookies( self ): url = "http://127.0.0.1:9090/web/login/" + "?username=" + "admin" + "&" + "password=" + "admin123." res = requests.get(url = url, headers = { "user-agent" : "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" }) # print(json.loads(res.text)) return res.cookies @unittest .skip( 'noexec' ) def test_login_ok( self ): row = 1 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row,configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "GET" : testobj = test_request.TestLogin(data[ "username" ],data[ "pwd" ],url) resobj = testobj.get() self .assertEqual( int (res),json.loads(resobj.text)[ "code" ]) @unittest .skip( 'noexec' ) def test_login_pwd_error( self ): row = 2 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row,configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "GET" : testobj = test_request.TestLogin(data[ "username" ],data[ "pwd" ],url) resobj = testobj.get() self .assertEqual( int (res),json.loads(resobj.text)[ "code" ]) @unittest .skip( 'noexec' ) def test_login_user_error( self ): row = 3 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row,configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "GET" : testobj = test_request.TestLogin(data[ "username" ],data[ "pwd" ],url) resobj = testobj.get() self .assertEqual( int (res),json.loads(resobj.text)[ "code" ]) @unittest .skip( 'noexec' ) def test_user_pwd_error( self ): row = 4 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row,configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "GET" : testobj = test_request.TestLogin(data[ "username" ],data[ "pwd" ],url) resobj = testobj.get() self .assertEqual( int (res),json.loads(resobj.text)[ "code" ]) @unittest .skip( 'noexec' ) def test_insert_ok( self ): row = 5 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data[ "username" ], data[ "age" ],data[ "sex" ], data[ "pwd" ],cookies,url) resobj = testobj.post() print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( 'noexec' ) def test_insert_nologin( self ): row = 6 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data[ "username" ], data[ "age" ],data[ "sex" ], data[ "pwd" ],cookies,url) resobj = testobj.post() print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( "noexec" ) def test_insert_user_error( self ): row = 7 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data.get( "username" , None ), data.get( "age" , None ), data.get( "sex" , None ), data.get( "pwd" , None ), cookies, url) resobj = testobj.post() print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( 'no exec' ) def test_insert_pwd_error( self ): row = 8 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) data = json.loads(data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data.get( "username" , None ), data.get( "age" , None ), data.get( "sex" , None ), data.get( "pwd" , None ), cookies, url) resobj = testobj.post() print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( "no exec" ) def test_insert_sex_error( self ): row = 9 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) print (data) data = json.loads(data) print (data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data.get( "username" , None ), data.get( "age" , None ), data.get( "sex" , None ), data.get( "pwd" , None ), cookies, url) resobj = testobj.post() print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( 'no exec' ) def test_insert_age_error( self ): row = 10 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) print (data) data = json.loads(data) print (data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data.get( "username" , None ), data.get( "age" , None ), data.get( "sex" , None ), data.get( "pwd" , None ), cookies, url) resobj = testobj.post() print (resobj.text) print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( 'no exec' ) def test_insert_user_exist( self ): row = 11 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) print (data) data = json.loads(data) print (data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.TestAdd(data.get( "username" , None ), data.get( "age" , None ), data.get( "sex" , None ), data.get( "pwd" , None ), cookies, url) resobj = testobj.post() print (resobj.text) print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) def test_get_user( self ): row = 12 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.Testscan(url) resobj = testobj.get() # print(resobj.text print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) @unittest .skip( 'no exec' ) def test_del_user( self ): row = 13 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) print (data) data = json.loads(data) print (data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.Testdel(data.get( "username" , None ),cookies, url) resobj = testobj.post() print (resobj.text) print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) def test_del_noexistuser( self ): row = 14 configobj = testconfig.TestConfig() excelobj = test_excel.testexcel() execstatus = excelobj.get_excel_data(row, configobj.getexec()) if execstatus = = "YES" : cookiesstatus = excelobj.get_excel_data(row, configobj.getcookies()) if cookiesstatus = = "YES" : cookies = self .get_cookies() else : cookies = None data = excelobj.get_excel_data(row, configobj.getdata()) print (data) data = json.loads(data) print (data) url = excelobj.get_excel_data(row, configobj.geturl()) res = excelobj.get_excel_data(row, configobj.getres()) method = excelobj.get_excel_data(row, configobj.getmethod()) if method = = "POST" : testobj = test_request.Testdel(data.get( "username" , None ),cookies, url) resobj = testobj.post() print (resobj.text) print (json.loads(resobj.text)) self .assertEqual( int (res), json.loads(resobj.text)[ "code" ]) |