| | 82 | |
| | 83 | '''A walk-through example:'''[[BR]] |
| | 84 | We want to make an automated test script to test the Create Organization module. |
| | 85 | Create Organization falls under Human Resources Management (HRM) feature, therefore we must add this test script module file in the subfolder /hrm (eden/modules/tests/hrm/) |
| | 86 | |
| | 87 | Steps of automated the test for Create Organization:[[BR]][[BR]] |
| | 88 | |
| | 89 | 1) Let's call this test file: create_organization.py and save it in the subfolder /hrm. [[BR]][[BR]] |
| | 90 | |
| | 91 | 2) We must now make sure we add the file name in the __init__.py |
| | 92 | Open file __init__.py in the subfolder /hrm and add: |
| | 93 | {{{ |
| | 94 | from create_organisation import * |
| | 95 | }}} |
| | 96 | 3) create_organisation.py |
| | 97 | {{{ |
| | 98 | import os |
| | 99 | import time |
| | 100 | from selenium.common.exceptions import NoSuchElementException |
| | 101 | from gluon import current |
| | 102 | from s3 import s3_debug |
| | 103 | from tests.web2unittest import SeleniumUnitTest |
| | 104 | |
| | 105 | class CreateOrganization(SeleniumUnitTest): |
| | 106 | |
| | 107 | # ------------------------------------------------------------------------- |
| | 108 | def test_org001_create_organisation(self, items=[0]): |
| | 109 | """ |
| | 110 | Create an Organisation |
| | 111 | |
| | 112 | @param items: Organisation(s) to create from the data |
| | 113 | |
| | 114 | @ToDo: currently optimised for a single record |
| | 115 | """ |
| | 116 | print "\n" |
| | 117 | # Configuration |
| | 118 | self.login(account="normal", nexturl="org/organisation/create") |
| | 119 | tablename = "org_organisation" |
| | 120 | #data = current.data["organisation"] |
| | 121 | # Data for the Organisation resource |
| | 122 | self.create("org_organisation", |
| | 123 | [( "name", "Romanian Food Assistance Association (Test)"), ( "acronym", "RFAAT"), ("website", "http://www.rfaat.com"), ("comments", "This is a Test Organization")] |
| | 124 | ) |
| | 125 | for item in items: |
| | 126 | _data = data[item] |
| | 127 | # Check whether the data already exists |
| | 128 | s3db = current.s3db |
| | 129 | db = current.db |
| | 130 | table = s3db[tablename] |
| | 131 | fieldname = _data[0][0] |
| | 132 | value = _data[0][1] |
| | 133 | query = (table[fieldname] == value) & (table.deleted == "F") |
| | 134 | record = db(query).select(table.id, |
| | 135 | limitby=(0, 1)).first() |
| | 136 | if record: |
| | 137 | print "org_create_organisation skipped as %s already exists in the db\n" % value |
| | 138 | return False |
| | 139 | |
| | 140 | # Login, if not-already done so |
| | 141 | self.login(account=account, nexturl=url) |
| | 142 | }}} |
| | 143 | |
| | 144 | 4) To run this automated test script. |
| | 145 | Open suite.py (modules/tests/suite.py) and add at the bottom of suite.py script so it can be executed. (NOTE: We add the class name, not the function name). |
| | 146 | {{{ |
| | 147 | addTests(loadTests(CreateOrganization)) |
| | 148 | }}} |
| | 149 | |
| | 150 | 5) Run your test script. (Refer above on how to run/execute test scripts from the Test Suite). |
| | 151 | |
| | 152 | '''Other information on the Test System framework:'''[[BR]] |