extools.test¶
-
class
extools.test.
ExTestCase
(log_level=15)[source]¶ Bases:
object
A self running test case class for Extender scripts.
ExTestCase can be used to test code in the Extender environment. Test cases will run with access to the current company. Write your tests against the sample data in SAMINC, setup anything else you need on the fly, to make it easy to build a repeatable test environment.
Parameters: log_level (int) – level of the built-in logger. To create your own tests:
- subclass ExTestCase
- define the
.setup()
and.teardown
methods - create as many methods starting with
test_
as you’d like - run your test suite by creating an instance and calling
.run()
Run all the tests in a project using the included ExTestRunner module.
Let’s say you want to test your set order decription custom function, which sets the order decription to the customer number.
from extools.view import exview def set_description_to_customer_number(ordnumber): '''Set the order description to the customer number. :param ordnumber: the order number to update. :type ordnumber: str :rtype: None :raises: ExViewError ''' with exview("OE0500", seek_to={"ORDNUMBER": ordnumber}) as exv: exv.update(DESC=exv.get("CUSTOMER"))
Using the
extools.view.exview()
context manager makes opening, closing, and seeking the view easy. To test it, we will need a record in the SAMINC database that we can change the Description on. The first, ORD000000000001, seems to fit the bill.from extools.test import ExTestCase from mymodule import set_description_to_customer_number class MyTest(ExTestCase): # Make the order to work on a constant ORDER_NUMBER = "ORD000000000001" ORDER_VIEW = "OE0500" def setup(self): # Make sure the field isn't already set to the customer number with exview(ORDER_VIEW, seek_to={"ORDNUMBER": ORDER_NUMBER}) as exv: if exv.get("DESC") == exv.get("CUSTOMER"): exv.update(DESC="Description") # The test method must start with ``test_`` to be auto-detected. def test_set_description_to_customer_number(self): # Use the built-in assertions to check the pre- with exview(ORDER_VIEW, seek_to={"ORDNUMBER": ORDER_NUMBER}) as exv: self.assertTrue(not exv.get("CUSTOMER") == exv.get("DESC")) set_description_to_customer_number(ORDER_NUMBER) #and post conditions with exview(ORDER_VIEW, seek_to={"ORDNUMBER": ORDER_NUMBER}) as exv: self.assertTrue(exv.get("CUSTOMER") == exv.get("DESC")) def main(): # To run your tests, instantiate the class and run it! mt = MyTest() mt.run()
-
INDEX_MAX
= 99¶
-
exception
extools.test.
ExTestError
(trigger_exc=None)[source]¶ Bases:
extools.errors.ExToolsError
Raised by failed test cases.