TIPS¶
Generate scenario with an other class than unittest.TestCase¶
You can define the base class of generated TestCase using base_class attribute. By default the used class is unittest.TestCase but you can use any unittest.TestCase subclass.
class BaseTest(TestState):
base_class = MyCustomTestCase
Create a custom client for TestServer class¶
-
classmethod
MetaServerTestState.
bind_class_client
(class_client)¶ You can use the bind_class_client̀ method to allow each TestServer subclass to manage a new Client.
To crete a new Client, you should subclass cricri.inet.Client and define the validator static method and the close method.
from urllib.request import urlopen from cricri import MetaServerTestState from cricri.inet import Client class MyCustomClient(Client): attr_name = 'my_custom_clients' def __init__(self, host): self.host = host self.response = None @staticmethod def validator(): return { 'host': str } def close(self): if self.response is not None: self.response.close() def url_open(self, page): self.response = self.urlopen(self.host + '/' + page) self.content = self.response.read() def assert_page_content(self, text): if text not in self.content: raise AssertionError( '{} in not {}'.format(text, self.content)) MetaServerTestState.bind_class_client(MyCustomClient)