How to use test_valid method in avocado

Best Python code snippet using avocado_python

form_test.py

Source:form_test.py Github

copy

Full Screen

...51<p>Submit&nbsp;<span class="cppcms_form_input"><input type="submit" name="_13" value="Button" ></span></p>52</form>53"""54test("/test",body,ref_body)55def test_valid(name,params,ans,url='/non_empty'):56 h=httplib.HTTPConnection('localhost:8080');57 h.request('GET','/test' + url + '?' + params)58 r=h.getresponse()59 test(name,r.read()[:len(ans)],ans)60test_valid('non_empty1','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','valid')61test_valid('non_empty2','_1=&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')62test_valid('non_empty3','_1=1&_2=&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')63test_valid('non_empty4','_1=1&_2=1&_3=&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')64test_valid('non_empty5','_1=1&_2=1&_3=1&_4=1&_5=&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')65test_valid('non_empty6','_1=1&_2=1&_3=1&_4=1&_5=1&_6=&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')66test_valid('non_empty7','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')67test_valid('non_empty8','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=&_9=10&_10=1&_11=1&_12=1&_13=1','invalid')68test_valid('non_empty9','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=&_10=1&_11=1&_12=1&_13=1','valid') # checkbox ok69test_valid('non_empty10','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=&_11=1&_12=1&_13=1','invalid')70test_valid('non_empty11','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=&_12=1&_13=1','invalid')71test_valid('non_empty12','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=&_13=1','invalid')72test_valid('non_empty12','_1=1&_2=1&_3=1&_4=1&_5=1&_6=1&_7=yes&_8=a@a&_9=10&_10=1&_11=1&_12=1&_13=','valid') # Submit ok73test_valid('empty','_1=&_2=&_3=&_4=&_5=&_6=&_7=yes&_8=a@a&_9=&_10=&_11=&_12=&_13=','valid','') # Empty ok only regex, email fails74test_valid('empty1','_1=&_2=&_3=&_4=&_5=&_6=&_7=yes&_8=&_9=&_10=&_11=&_12=&_13=','invalid','') # Empty ok only regex, email fails75test_valid('empty2','_1=&_2=&_3=&_4=&_5=&_6=&_7=&_8=a@a&_9=&_10=&_11=&_12=&_13=','invalid','') # Empty ok only regex, email fails76h=httplib.HTTPConnection('localhost:8080');77h.request('GET','/test/sub')78r=h.getresponse()79body=r.read();80ref_body = \81"""\82<p>pass&nbsp;<span class="cppcms_form_input"><input type="password" name="_5" ></span></p>83<p>pass2&nbsp;<span class="cppcms_form_input"><input type="password" name="_6" ></span></p>84<p>yes or not&nbsp;<span class="cppcms_form_input"><input type="text" name="_7" ></span></p>85<p>E-Mail&nbsp;<span class="cppcms_form_input"><input type="text" name="_8" ></span></p>86<p>Checkbox&nbsp;<span class="cppcms_form_input"><input type="checkbox" name="_9" value="y" ></span></p>87<p>Select Multiple&nbsp;<span class="cppcms_form_input"><select multiple name="_10" >88<option value="0" selected >a</option>89<option value="1" selected >b</option>90<option value="2" >c</option>91<option value="id1" >tr1</option>92</select></span></p>93"""94test("subset",body,ref_body)95def test_valid(name,url,params,ans):96 def get():97 h=httplib.HTTPConnection('localhost:8080');98 h.request('GET','/test' + url + '?' + params)99 r=h.getresponse()100 test(name+' GET',r.read(),ans)101 def post():102 h=httplib.HTTPConnection('localhost:8080');103 headers = {"Content-type": "application/x-www-form-urlencoded"}104 h.request('POST','/test' + url,params,headers)105 r=h.getresponse()106 test(name+' POST',r.read(),ans)107 get()108 post()109test_valid('text','/text','_1=','invalid\n')110test_valid('text1','/text','_1=x','invalid\nx')111test_valid('text2','/text','_1=xx','valid\nxx')112test_valid('text3','/text','_1=xxxxx','valid\nxxxxx')113test_valid('text4','/text','_1=xxxxxx','invalid\nxxxxxx')114test_valid('text5','/text','_1=%d7%a9%d6%b8%d7%9c%d7%95%d7%9d','valid\nשָלום')115test_valid('text6','/text','_1=%d7%a9%d7%9c','valid\nשל')116test_valid('text7','/text','_1=%FF%FF','invalid\n\xFF\xFF')117test_valid('text8','/text','_1=%01%01','invalid\n\x01\x01')118test_valid('text9.1','/text','_1=xx%DF%7F','invalid\nxx\xDF\x7F')119test_valid('text9.2','/text','_1=xx%C2%7F','invalid\nxx\xC2\x7F')120test_valid('text9.3','/text','_1=xx%e0%7F%80','invalid\nxx\xe0\x7F\x80')121test_valid('text9.4','/text','_1=xx%f0%7F%80%80','invalid\nxx\xf0\x7F\x80\x80')122test_valid('number','/number','_1=','invalid\n')123test_valid('number1','/number','_1=10','valid\n10')124test_valid('number2','/number','_1=10.0','valid\n10')125test_valid('number3','/number','_1=10.0e+','invalid\n')126test_valid('number5','/number','_1=10.0e1','valid\n100')127test_valid('number6','/number','_1=10.0x','invalid\n')128test_valid('number7','/number','_1=A10.0','invalid\n')129test_valid('number8','/number','_1=0','invalid\n0')130test_valid('number9','/number','_1=1000','invalid\n1000')131test_valid('number10','/number','_1=10A','invalid\n')132test_valid('pass1','/pass','_1=&_2=','invalid\n')133test_valid('pass2','/pass','_1=x&_2=x','valid\n')134test_valid('pass3','/pass','_1=x1&_2=x2','invalid\n')135test_valid('checkbox1','/checkbox','_1=n','valid\n0')136test_valid('checkbox2','/checkbox','_1=y','valid\n1')137test_valid('sm1','/sm','foo=bar','invalid\n0 0 0 0 \n\n')138test_valid('sm2','/sm','_1=1&_1=0','valid\n1 1 0 0 \n0 1 \n')139test_valid('sm3','/sm','_1=1&_1=id1','valid\n0 1 0 1 \n1 id1 \n')140test_valid('sm4','/sm','_1=0&_1=1&_1=2','invalid\n1 1 1 0 \n0 1 2 \n')141test_valid('select1','/select','foo=bar','invalid\n-1 ')142test_valid('select2','/select','_1=0','valid\n0 0')143test_valid('select3','/select','_1=0&_1=1','invalid\n-1 ')144test_valid('select4','/select','_1=10','invalid\n-1 ')145test_valid('radio1','/radio','foo=bar','invalid\n-1 ')146test_valid('radio2','/radio','_1=0','valid\n0 0')147test_valid('radio3','/radio','_1=0&_1=1','invalid\n-1 ')148test_valid('radio4','/radio','_1=10','invalid\n-1 ')149test_valid('submit1','/submit','_1=1','valid\n1')150test_valid('submit2','/submit','_2=1','valid\n0')151body='<p><label for="submit_id">message</label>&nbsp;<span class="cppcms_form_error">error</span> <span class="cppcms_form_input"><input type="submit" id="submit_id" name="submit_name" value="test" ></span><span class="cppcms_form_help">help</span></p>\n'152test_valid('submit3','/submitl','',body)153def test_upload(name,url,content,ans):154 h=httplib.HTTPConnection('localhost:8080');155 headers = {"Content-type": "multipart/form-data; boundary=123456"}156 h.request('POST','/test' + url,content,headers)157 r=h.getresponse()158 test(name,r.read(),ans)159def make_multipart_form_data(content,mime,name='test.txt'):160 return \161 '--123456\r\n' + \162 'Content-Type: ' + mime + '\r\n' + \163 'Content-Disposition: form-data; name="file"; filename="' + name +'"\r\n' + \164 '\r\n' + \165 content + \166 '\r\n--123456--\r\n' ...

Full Screen

Full Screen

test_utility.py

Source:test_utility.py Github

copy

Full Screen

1""" File for test for the validation class."""2from app.utilities.validation import Valid3from app.utilities.validation import file_format4from .test_structures import TestStructure5test_valid = Valid()6class TestValidationClass(TestStructure):7 """ Test Class for validation used in utility."""8 def test_validate_check_incident(self):9 """ Test to validate check incident method."""10 self.assertEqual(11 test_valid.check_incident(1, 0), 1)12 self.assertEqual(13 test_valid.check_incident(0, 1), 1)14 self.assertEqual(15 test_valid.check_incident(0, 0), None)16 def test_validate_attributes(self):17 """ Test for the validation class method validate_attributes."""18 self.assertEqual(19 test_valid.validate_attributes(20 "",21 "just_testing"),22 "Location has to be a valid float.")23 self.assertEqual(24 test_valid.validate_attributes(25 0.245, 4), "Comment has to be a valid String.")26 def test_validate_list(self):27 """ Test to check if item is not None."""28 my_test_list = []29 self.assertFalse(test_valid.check_list(my_test_list))30 def test_valid_patch_location(self):31 """ Test to check if data from patch location is valid."""32 self.assertEqual(33 test_valid.update_location({"location": "d"}),34 "New location has to be a float.")35 def test_comment_update(self):36 """ Test method to validate comment data from patch."""37 self.assertEqual(38 test_valid.validate_comment_update({"comment": 54}),39 "New Comment ought to be a valid sentence.")40 def test_mime_format(self):41 """ Method to check for valid python strings."""42 self.assertFalse(test_valid.check_format("jd"))43 self.assertFalse(test_valid.check_format("jddfddmp4"))44 self.assertFalse(test_valid.verify_string(0))45 self.assertFalse(test_valid.verify_string(" "))46 def test_file_format(self):47 """ Test for helper method in validation file."""48 self.assertTrue(file_format("crime.mp4"))49 self.assertTrue(file_format("crime.jpeg"))50 def test_check_user_base(self):51 """ validation method check user base."""52 self.assertEqual(53 test_valid.check_user_base(54 "", "w2", "w22", "sdsdsd"),55 "First/Last/Other Name all have to be strings of two letters or more.")56 self.assertEqual(57 test_valid.check_user_base(58 "Derek", "Derrick", "Kidrice", " "),59 "User Name has to be a string.")60 def test_check_credential(self):61 """ user credentials method test."""62 self.assertEqual(63 test_valid.check_credential(64 "@$$$", "asd@hdd.gob", "sdsdsds", False),65 "Phone number must be only digits and no white spaces.")66 self.assertEqual(67 test_valid.check_credential(68 "45786", "asdgob", "sdsdsds", False),69 "Enter a valid email address.")70 self.assertEqual(71 test_valid.check_credential(72 "45786", "asd@hdd.gob", "sd", False),73 "Password has to be a string and longer than 6 characters.")74 self.assertEqual(75 test_valid.check_credential(76 "45786", "asd@hdd.gob", "sdsdsds", "asasas"),77 "is_admin muust be a boolean.")78 def test_valid_mime(self):79 """ Test for validation method valida mime80 and the check_image_video method."""81 self.assertFalse(test_valid.valid_mime(0))82 self.assertEqual(83 test_valid.check_image_video(84 0, "video.mp4"),85 "Image has to be of jpg or jpeg format and a valid String.")86 self.assertEqual(87 test_valid.check_image_video(88 "image.jpeg", 0),89 "Video has to be a valid String of either mov or mp4.")90 def test_validate_login(self):91 """ validating entered login credentials."""...

Full Screen

Full Screen

jsonrpc_test.py

Source:jsonrpc_test.py Github

copy

Full Screen

...15def test_status(h,stat):16 if h.status != stat:17 print "Status mistmatch:",h.status,"!=",stat18 sys.exit(1)19def test_valid(name,params,ans,method='POST'):20 h=httplib.HTTPConnection('localhost:8080');21 headers = {"Content-type": "application/json"}22 h.request(method,'/test',params,headers)23 r=h.getresponse()24 test(name,r.read(),ans)25test_valid('sum','{"method" : "sum" , "params" : [ 1, 2 ], "id" : 1}','{"id":1,"error":null,"result":3}')26test_valid('sum wrong','{"method" : "sum" , "params" : [ 1, 10 ], "id" : null}','')27test_valid('sum wrong 1','{"method" : "sum" , "params" : [ 1 ], "id" : 1}',\28 '{"id":1,"error":"Invalid parametres number","result":null}')29test_valid('sum wrong 2','{"method" : "sum" , "params" : [ 1 ,"x" ], "id" : 1}',\30 '{"id":1,"error":"Invalid parameters","result":null}')31test_valid('div1','{"method" : "div" , "params" : [ 5, 2 ], "id" : "x"}','{"id":"x","error":null,"result":2}')32test_valid('div2','{"method" : "div" , "params" : [ 5, 0 ], "id" : 0}','{"id":0,"error":"Division by zero","result":null}')33test_valid('notify1','{"method" : "notify" , "params" : [ "notify" ], "id" : null}','')34test_valid('not notify','{"method" : "notify" , "params" : [ "notcalled" ], "id" : "x"}',\35 '{"id":"x","error":"The request should be notification","result":null}')36test_valid('both','{"method" : "both" , "params" : [ "notification" ], "id" : null}','')37test_valid('both','{"method" : "both" , "params" : [ "foo" ], "id" : 1}','{"id":1,"error":null,"result":"call:foo"}')...

Full Screen

Full Screen

gzip_test.py

Source:gzip_test.py Github

copy

Full Screen

...19 zstream = gzip.GzipFile(mode='r', fileobj=virt)20 result = zstream.read()21 return result22 23def test_valid(url,accepts,compressed,expected):24 h=httplib.HTTPConnection('localhost:8080');25 headers = {}26 if accepts:27 headers = { 'Accept-Encoding' : 'gzip' }28 h.request('GET','/test' + url,'',headers)29 r=h.getresponse().read()30 if compressed:31 r=decompress(r)32 test(url,r,expected)33test_valid('/ca',True,True,'test a')34test_valid('/ca',False,False,'test a')35test_valid('/cb',True,True,'test b')36test_valid('/cb',False,False,'test b')37test_valid('/bin',True,False,'binary')38test_valid('/bin',False,False,'binary')39test_valid('/not',True,False,'not compressed')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful