How to use setuptest method in Molotov

Best Python code snippet using molotov_python

test_recipe.py

Source:test_recipe.py Github

copy

Full Screen

1import sys2import os3import json4sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'app')))5sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))6from app import app7import unittest8from flask import request, jsonify9class SetUpTest(unittest.TestCase):10 """This class uses the Flask tests app to run an integration test against a11 local instance of the server."""12 def setUp(self):13 self.app = app.test_client()14 def test_get_myrecipe_folder_normal(self):15 with open('local.json', 'r') as f:16 data = json.load(f)17 rv = self.app.post('/myrecipe/folder', data=json.dumps(dict(18 tag='dessert',19 userId=38,20 token=data['token'])),21 content_type='application/json')22 self.assertTrue(rv.status_code is 200)23 def test_get_myrecipe_folder_without_token(self):24 with open('local.json', 'r') as f:25 data = json.load(f)26 rv = self.app.post('/myrecipe/folder', data=json.dumps(dict(27 tag='dessert',28 userId=38,29 token='')),30 content_type='application/json')31 self.assertFalse(rv.status_code is 200)32 def test_get_myrecipe_folder_without_id(self):33 with open('local.json', 'r') as f:34 data = json.load(f)35 rv = self.app.post('/myrecipe/folder', data=json.dumps(dict(36 tag='dessert',37 userId=None,38 token=data['token'])),39 content_type='application/json')40 self.assertFalse(rv.status_code is 200)41 def test_get_myrecipe_folder_with_no_tag(self):42 with open('local.json', 'r') as f:43 data = json.load(f)44 rv = self.app.post('/myrecipe/folder', data=json.dumps(dict(45 tag='',46 userId=38,47 token=data['token'])),48 content_type='application/json')49 self.assertTrue(rv.status_code is 200)50 def test_get_myrecipe_tag_normal(self):51 with open('local.json', 'r') as f:52 data = json.load(f)53 rv = self.app.post('/myrecipe/tags', data=json.dumps(dict(54 userId=38,55 token=data['token'])),56 content_type='application/json')57 self.assertTrue(rv.status_code is 200)58 def test_get_myrecipe_tag_without_token(self):59 with open('local.json', 'r') as f:60 data = json.load(f)61 rv = self.app.post('/myrecipe/tags', data=json.dumps(dict(62 userId=38,63 token='')),64 content_type='application/json')65 self.assertFalse(rv.status_code is 200)66 def test_get_myrecipe_tag_without_id(self):67 with open('local.json', 'r') as f:68 data = json.load(f)69 rv = self.app.post('/myrecipe/tags', data=json.dumps(dict(70 userId=None,71 token=data['token'])),72 content_type='application/json')73 self.assertFalse(rv.status_code is 200)74 def test_get_recipe_normal(self):75 with open('local.json', 'r') as f:76 data = json.load(f)77 rv = self.app.post('/getRecipe', data=json.dumps(dict(78 uid=38,79 rid=10,80 token=data['token'])),81 content_type='application/json')82 self.assertTrue(rv.status_code is 200)83 def test_get_recipe_with_no_uid(self):84 with open('local.json', 'r') as f:85 data = json.load(f)86 rv = self.app.post('/getRecipe', data=json.dumps(dict(87 uid=None,88 rid=10,89 token=data['token'])),90 content_type='application/json')91 self.assertTrue(rv.status_code is 200)92 def test_get_recipe_with_no_rid(self):93 with open('local.json', 'r') as f:94 data = json.load(f)95 rv = self.app.post('/getRecipe', data=json.dumps(dict(96 uid=38,97 rid=None,98 token=data['token'])),99 content_type='application/json')100 self.assertFalse(rv.status_code is 200)101 def test_get_recipe_with_no_token(self):102 with open('local.json', 'r') as f:103 data = json.load(f)104 rv = self.app.post('/getRecipe', data=json.dumps(dict(105 uid=38,106 rid=10,107 token='')),108 content_type='application/json')109 self.assertTrue(rv.status_code is 200)110if __name__ == '__main__':111 suite = unittest.TestSuite()112 tests = [SetUpTest("test_get_myrecipe_folder_normal"),113 SetUpTest("test_get_myrecipe_folder_without_token"),114 SetUpTest("test_get_myrecipe_folder_without_id"),115 SetUpTest("test_get_myrecipe_folder_with_no_tag"),116 SetUpTest("test_get_myrecipe_tag_normal"),117 SetUpTest("test_get_myrecipe_tag_without_token"),118 SetUpTest("test_get_myrecipe_tag_without_id"),119 SetUpTest("test_get_recipe_normal"),120 SetUpTest("test_get_recipe_with_no_uid"),121 SetUpTest("test_get_recipe_with_no_rid"),122 SetUpTest("test_get_recipe_with_no_token")123 ]124 suite.addTests(tests)125 runner = unittest.TextTestRunner(verbosity=2)...

Full Screen

Full Screen

estacionamento_test.py

Source:estacionamento_test.py Github

copy

Full Screen

1import datetime2import pytest3from optparse import Values45from src.Estacionamento import Estacionamento678@pytest.fixture9def setupTest():10 return [11 Estacionamento(12 valorFracao=30,13 valorHoraCheia=15,14 valorDiariaNoturna=45,15 valorDiariaDiurna=120,16 mensalidade=600,17 valorEvento=50,18 horarios=[19 "06:00",20 "22:00",21 "19:00",22 "08:00",23 "19:00",24 "08:00",25 ],26 capacidade=300,27 retorno=50,28 ),29 Estacionamento(30 valorFracao=20,31 valorHoraCheia=10,32 valorDiariaNoturna=30,33 valorDiariaDiurna=70,34 mensalidade=455,35 valorEvento=60,36 horarios=[37 "00:00",38 "00:00",39 "21:00",40 "07:00",41 "21:00",42 "07:00",43 ],44 capacidade=120,45 retorno=60,46 ),47 Estacionamento(48 valorFracao=10,49 valorHoraCheia=0,50 valorDiariaNoturna=40,51 valorDiariaDiurna=50,52 mensalidade=350,53 valorEvento=40,54 horarios=[55 "06:00",56 "22:00",57 "20:00",58 "08:00",59 "20:00",60 "08:00"61 ],62 capacidade=600,63 retorno=70,64 ),65 ]666768@pytest.mark.funcional69def testaCadastroUmVeiculo(setupTest):70 setupTest[0].AddAcesso("HI139", "08:30", "08:56")71 setupTest[0].AddAcesso("G49NG", "Mensalista", "Mensalista")72 setupTest[0].AddAcesso("AC50M", "08:30", "18:00")73 setupTest[0].AddAcesso("RM3A9", "20:00", "07:00")74 setupTest[0].AddAcesso("AM31J", "Evento", "Evento")7576 assert (setupTest[0].getAcessos()) != 0777879@pytest.mark.funcional80@pytest.mark.parametrize(81 "expected, values",82 [83 ("Noturna", ["RM3A9", "20:00", "07:00"]),84 ("Mensalista", ["G49NG", "Mensalista", "Mensalista"]),85 ("0:26", ["HI139", "08:30", "08:56"]),86 ("Evento", ["AM31J", "Evento", "Evento"]),87 ],88)89def testaTipoAcessoPorPlaca1(expected, values, setupTest):90 setupTest[0].AddAcesso(values[0], values[1], values[2])91 assert setupTest[0].FindTipoAcesso(values[0]) == expected929394@pytest.mark.funcional95@pytest.mark.parametrize(96 "expected, values",97 [98 (50, ["AM31J", "Evento", "Evento"]),99 (54, ["RM3A9", "20:00", "07:00"]),100 (600, ["G49NG", "Mensalista", "Mensalista"]),101 (60, ["HI139", "08:30", "08:56"]),102 ],103)104def testaValorAcesso(expected, values, setupTest):105 setupTest[0].AddAcesso(values[0], values[1], values[2])106 assert setupTest[0].GetValorAcesso(values[0]) == expected107108109@pytest.mark.funcional110@pytest.mark.parametrize(111 "expected, values",112 [113 (25, ["AM31J", "Evento", "Evento"]),114 (27, ["RM3A9", "20:00", "07:00"]),115 (300, ["G49NG", "Mensalista", "Mensalista"]),116 (30, ["HI139", "08:30", "08:56"]),117 (45, ["AM321", "8:00", "8:45"]),118 ],119)120def testaValorContratante(expected, values, setupTest):121 setupTest[0].AddAcesso(values[0], values[1], values[2])122 assert setupTest[0].GetValorContratante(values[0]) == expected123124125@pytest.mark.funcional126@pytest.mark.parametrize(127 "index, expected, values",128 [129 (130 0,131 442.0,132 [133 ["HI139", "08:30", "08:56"],134 ["AM31J", "Mensalista", "Mensalista"],135 ["AC50M", "8:00", "18:00"],136 ["G49NG", "19:01", "07:50"],137 ["RM3A9", "Evento", "Evento"],138 ],139 ),140 (141 1,142 263.4,143 [144 ["HI139", "08:30", "09:30"],145 ["AM31J", "15:12", "16:00"],146 ["AC50M", "8:00", "18:00"],147 ["G49NG", "21:36", "06:12"],148 ["N4GN3", "08:00", "09:48"],149 ["RM3A9", "Evento", "Evento"],150 ],151 ),152 ],153)154def testaValorApuradoContratante(expected, values, index, setupTest):155 for i in values:156 setupTest[index].AddAcesso(i[0], i[1], i[2]) ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from selenium import webdriver2from selenium.webdriver.common.keys import Keys3import time4import os.path5from os import path6class SetupTest:7 def __init__(self):8 self.test_file = null #file location object9 self.logs_file = null #file location object10 self.test = null #array of test commands11 def createTestFile():12 print("SetupTest.createTestFile")13 if os.path.isfile('test.txt') == False:14 open('test.txt',"a")15 if os.path.isfile('logs.txt') == False:16 open('logs.txt',"a")17 def openScript():18 print("SetupTest.openScript")19 SetupTest.createTestFile()20 test_path = 'test.txt'21 SetupTest.test_file = open(test_path,'r')22 SetupTest.test = SetupTest.test_file.readlines()23 logs_path = 'logs.txt'24 SetupTest.logs_file = open(logs_path,'w')25 title = 'Steps:\n'26 SetupTest.logs_file.write(title)27 print(title)28 SetupTest.logs_file.writelines(SetupTest.test)29 print(SetupTest.test)30 logs = 'Logs:\n'31 SetupTest.logs_file.write(logs)32 print(logs)33 def closeScript():34 print("SetupTest.closeScript")35 SetupTest.test_file.close()36 SetupTest.logs_file.close()37class RunTest:38 def URL():39 URL = str(test.split("|")[1])40 URLassert = str(test.split("|")[2].replace("\n", ""))41 browser.get(URL)42 print(URLassert)43 assert URLassert in browser.title #check browser title = URLassert44 SetupTest.logs_file.write("Search for " + URL + " in Browser\n") #Logs45 def TEXTBOX():46 field = str(test.split("|")[1].replace("\n", ""))47 print(field)48 elem = browser.find_element_by_name(field) # Find the search box49 elem.send_keys('seleniumhq' + Keys.RETURN)50 SetupTest.logs_file.write("Search for textbox with name = " + field + "\n") #Logs51 def SLEEP():52 time.sleep(int(test.split("|")[1]))53 SetupTest.logs_file.write("wait for " + str(test.split("|")[1].replace("\n", "")) + " seconds\n") #Logs54if __name__ == "__main__":55 #read script and extract commands56 SetupTest.openScript()57 print(SetupTest.test_file.name, SetupTest.logs_file.name)58 testScript = SetupTest.test # grab the test script59 browser = webdriver.Firefox()60 i=061 for test in testScript: #Read commands in file and execute them62 SetupTest.logs_file.write(test)63 if "URL|" in test: #check for URL and search URL64 RunTest.URL()65 if "TEXTBOX|" in test:66 RunTest.TEXTBOX()67 if "SLEEP|" in test: #wait a set time in seconds before moving on68 RunTest.SLEEP()69 i+=170 browser.quit()...

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 Molotov 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