Best Python code snippet using websmith_python
warehouseTest.py
Source:warehouseTest.py  
1from sahanaTest import SahanaTest2import unittest, re, time3class WarehouseTest(SahanaTest):4    """ Test the Warehouse component of the Inventory Management System """5    _sortList = ("addWarehouses",6                 "stockWarehouse",7                 #"removeWarehouses",8                )9    10    def firstRun(self):11        WarehouseTest.warehouses = []12        WarehouseTest.orgs = []13        # Setup the template for the Warehouse From14        WarehouseTest.warehouseCreateTemplate = self.action.getFormTemplate()15        WarehouseTest.warehouseCreateTemplate.addInput(labelID="org_office_name__label",16                                                       inputID="org_office_name")17    def createWarehouse(self, name, organisation,18                        country, state=None, district=None,19                        lat=None, lon=None, address=None,20                        phone=None, email=None, comment=None):21        sel = self.selenium22        name = name.strip()23        organisation = organisation.strip()24        country = country.strip()25        state = state.strip()26        district = district.strip()27        lat = lat.strip()28        lon = lon.strip()29        address = address.strip()30        phone = phone.strip()31        email = email.strip()32        comment = comment.strip()33        if organisation not in self.orgs:34            self.action.openPage("org/organisation")35            matches = self.action.searchMatchesFound(organisation)36            if matches == 0:37                self.createOrganisation(organisation)38            self.orgs.append(organisation)39        40        self.action.openPage("inv/warehouse/create")41        self.assertEqual("Add Warehouse", sel.get_text("//h2"))42        self.action.fillForm("org_office_name", name)43        self.action.fillAutoComplete("dummy_org_office_organisation_id", organisation)44        self.action.fillForm("gis_location_L0", country, "select")45        self.action.fillForm("gis_location_L1", state)46        self.action.fillForm("gis_location_L2", district)47        self.action.fillForm("gis_location_lat", lat)48        self.action.fillForm("gis_location_street", address)49        self.action.fillForm("gis_location_lon", lon)50        self.action.fillForm("org_office_phone1", phone)51        self.action.fillForm("org_office_email", email)52        self.action.fillForm("org_office_comments", comment)53        # Now save the form54        self.assertTrue(self.action.saveForm("Save", "Warehouse added"))55        print "Warehouse %s created" % name56    def createOrganisation(self, name):57        sel = self.selenium58        name = name.strip()59        self.action.openPage("org/organisation/create")60        self.assertEqual("Add Organization", sel.get_text("//h2"))61        self.action.fillForm("org_organisation_name", name)62        # Now save the form63        self.assertTrue(self.action.saveForm("Save", "Organization added"))64        print "Organization %s created" % name65    def addWarehouses(self):66        # Log in as admin an then move to the add warehouse page67        self.useSahanaAdminAccount()68        self.action.login(self._user, self._password)69        # Add the test warehouses70        source = open("../data/warehouse.txt", "r")71        values = source.readlines()72        source.close()73        self.action.openPage("inv/warehouse")74        for warehouse in values:75            details = warehouse.split(",")76            if len(details) == 11:77                name = details[0].strip()78                matches = self.action.searchMatchesFound(name)79                if matches == 0:80                    self.createWarehouse(name,81                                         details[1].strip(),82                                         details[2].strip(),83                                         details[3].strip(),84                                         details[4].strip(),85                                         details[5].strip(),86                                         details[6].strip(),87                                         details[7].strip(),88                                         details[8].strip(),89                                         details[9].strip(),90                                         details[10].strip(),91                                         )92                self.warehouses.append(name)93    94    def addItem(self, warehouse, item, size, quantity, expireDate, comments):95        """96            Add an Item to a Warehouse97            @ToDo: Currently this does it by going to a URL without a menu entry98                   This should eb changed to doing it via the Warehouse's Inventory Items tab99        """100        sel = self.selenium101        self.action.openPage("inv/inv_item")102        sel.click("show-add-btn")103        self.assertEqual("List Items in Inventory", sel.get_text("//h2"))104        self.action.fillForm("inv_inv_item_site_id", warehouse, "select")105        self.action.fillForm("inv_inv_item_item_id", item, "select")106        # Pause to let the select box be filled up107        for i in range(30):108            if size in sel.get_text("inv_inv_item_item_pack_id"):109                break110            time.sleep(1)111        self.action.fillForm("inv_inv_item_item_pack_id", size, "select")112        self.action.fillForm("inv_inv_item_quantity", quantity)113        self.action.fillForm("inv_inv_item_expiry_date", expireDate)114        self.action.fillForm("inv_inv_item_comments", comments)115        # Now save the form116        self.assertTrue(self.action.saveForm("Save", "Item added to Inventory"))117        118    def stockWarehouse(self):119        # Log in as admin an then move read the inventory item file120        self.useSahanaAdminAccount()121        self.action.login(self._user, self._password)122        # Add the test warehouses123        source = open("../data/inventoryItems.txt", "r")124        values = source.readlines()125        source.close()126        # For each item add it to the warehouse127        for items in values:128            details = items.split(",")129            if len(details) == 6:130                self.addItem(details[0].strip(),131                             details[1].strip(),132                             details[2].strip(),133                             details[3].strip(),134                             details[4].strip(),135                             details[5].strip(),136                            )137    # Fails to logout cleanly when not in lastRun138    #def removeWarehouses(self):139    def lastRun(self):140        """ Delete the test warehouses """141        142        if len(self.warehouses) == 0:143            return144        sel = self.selenium145        self.useSahanaAdminAccount()146        self.action.login(self._user, self._password)147        self.action.openPage("inv/warehouse")148        allPassed = True149        for warehouse in self.warehouses:150            self.action.searchUnique(warehouse)151            sel.click("link=Delete")152            self.action.confirmDelete()153            if self.action.successMsg("Warehouse deleted"):154                print "Warehouse %s deleted" % warehouse155            else:156                print "Failed to deleted warehouse %s" % warehouse157                allPassed = False158        self.assertTrue(allPassed)159if __name__ == "__main__":160    SahanaTest.setUpHierarchy()161    unittest.main()...app_mock.py
Source:app_mock.py  
1# coding: utf-82from mock import patch3from bin.app import app4import unittest5import web6from tests.tools import assert_response7render = web.template.render('templates/', base="layout")8class MyTestCase(unittest.TestCase):9    @patch("bin.app.index.GET")10    def test_indexGET(self, mock_indexGET):11        mock_indexGET.return_value = render.index(greeting="112358")12        resp = app.request("/")13        mock_indexGET.assert_called_once_with()14        assert_response(resp, contains="112358")15    @patch("bin.app.caoPH.GET")16    def test_caoPHGET(self, mock_caoPHGET):17        mock_caoPHGET.return_value = "aabbcc"18        resp = app.request("/cph")19        mock_caoPHGET.assert_called_once_with()20        assert_response(resp, status="200")21    @patch("bin.app.hello.GET")22    def test_helloGET(self,mock_helloGET):23        mock_helloGET.return_value = render.hello(greeting="helloââGET", another="Another line")24        resp = app.request("/hello")25        mock_helloGET.assert_called_once_with()26        assert_response(resp, status="200")27        assert_response(resp, contains="Another line")28    @patch("bin.app.fillform.GET")29    def test_fillformGET(self, mock_fillformGET):30        mock_fillformGET.return_value = render.fform()31        resp = app.request("/fillform")32        mock_fillformGET.assert_called_once_with()33        assert_response(resp, status="200")34    @patch("bin.app.fillform.POST")35    def test_fillformPOST(self, mock_fillformPOST):36        mock_fillformPOST.return_value = render.hello(greeting="Hi, Grocer", another="Another line")37        # appçrequestæ¹æ³æåæ°methodå¯ä»¥è®¾ç½®ä¸ºPOST,è¿æ ·å°ä¼è®¿é®å°fillformçPOSTæ¹æ³38        # ç±äºåé¢å·²ç»mockäºfillformçè¿åå¼,æä»¥è¿éä¸ç¨æå®è¾å
¥çdata,å³ä½¿æå®äºä¹æ²¡æç¨,å®å°ä¼æmockä¸è§å®çå¼è¿åã39        resp = app.request(localpart="/fillform",method='POST')40        mock_fillformPOST.assert_called_once_with()41        assert_response(resp, status="200")42        assert_response(resp, contains="Hi, Grocer")43    @patch("bin.app.upload.GET")44    def test_uploadGET(self, mock_uploadGET):45        mock_uploadGET.return_value = render.uform()46        resp = app.request("/image")47        mock_uploadGET.assert_called_once_with()48        assert_response(resp, status="200")49    @patch("bin.app.upload.POST")50    def test_uploadPOST(self, mock_uploadPOST):51        mock_uploadPOST.return_value = render.show(filename="/static/nethack.png")52        resp = app.request(localpart="/image",method='POST')53        mock_uploadPOST.assert_called_once_with()54        assert_response(resp, status="200")55        assert_response(resp, contains="/static/nethack.png")56if __name__ == '__main__':...urls.py
Source:urls.py  
1from django.urls import path2from . import views3urlpatterns = [4    path('',views.home),5    path('fillform',views.fillform),6    path('createform',views.createform),7    path('savedetails',views.savedetails),8    path('fillform/<slug:formid>',views.fillform),9    path('saveresponse/<slug:formid>',views.saveresponse),10    path('getformbyid',views.getformbyid),11    path('fillformuser',views.fillformuser),12    path('showresponses/<slug:formid>/filter',views.showresponsepage),13    path('manageforms',views.creatorpageview),14    path('updateformperm',views.set_form_res_visibility_Api),15    path('deleteform',views.delete_form_api),16    path('delformresponse',views.delete_form_response_api),17    path('setacpformrespapi',views.set_form_acpres_Api),18    path('manageformresponses/<form_id>',views.ExpendResponseForm),19    path('getresform/<form_id>',views.SendFormResData),...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
