ps.add('t0', 'abc') self.assertTrue(ps.contains('t0', 'abc')) self.assertTrue(ps.contains('t0', 'r0')) for i in range(0, self.MANY): res = "{}{}".format('n', i) ps.add('t0', res) self.assertTrue(ps.contains('t0', res)) @staticmethod def _fill_storage(ps, count, tgen_func=_tgen, rgen_func=_rgen): for i in range(0, count): ps.add(tgen_func(i), rgen_func(i)) class MemoryPermanentStorageTests(PermanentStorageTestsBase): def cls_instance(self): return MemoryPermanentStorage() class MemoryTemporalStorageTests(TemporalStorageTestsBase): def cls_instance(self): return MemoryTemporalStorage() kaylee_suite = load_tests([ MemoryTemporalStorageTests, MemoryPermanentStorageTests ])
self.assertEqual(sk, test_settings.SECRET_KEY) # test if default parameter works after previous call sk = get_secret_key('abc') self.assertEqual(sk, 'abc') # test for proper behaviour after releasing the object from proxy setup(None) self.assertRaises(KayleeError, get_secret_key) # and the final test :) sk = get_secret_key('abc') self.assertEqual(sk, 'abc') def test_dict_as_object_wrapper(self): #pylint: disable-msg=E1101 #E1101 Instance of 'DictAsObjectWrapper' has no 'A' member d = {'A' : 10, 'B' : 20} wo = DictAsObjectWrapper(**d) self.assertEqual(wo.A, 10) self.assertEqual(wo.B, 20) d = {'A' : 10, 'B' : {'C' : 30}} wo = DictAsObjectWrapper(**d) self.assertEqual(wo.B, {'C' : 30}) wo = RecursiveDictAsObjectWrapper(**d) self.assertEqual(wo.B.C, 30) kaylee_suite = load_tests([KayleeUtilTests, ])
#pylint: disable-msg=W0612 for i in range(0, self.MANY): task = ctr.get_task(node) self.assertTrue(task is None or isinstance(task, dict)) def test_accept_result(self): node, ctr = self.make_node_and_controller() task = ctr.get_task(node) res = { 'res' : task['id'] } ctr.accept_result(node, res) self.assertRaises(InvalidResultError, ctr.accept_result, node, {}) def make_node_and_controller(self): ctr = self.cls_instance() n = Node(NodeID()) n.subscribe(ctr) return n, ctr class SimpleControllerTests(ControllerTestsBase): def test_init(self): pass def cls_instance(self): return SimpleController('test_simple_controller_app', AutoTestProject(), TestPermanentStorage()) kaylee_suite = load_tests([SimpleControllerTests,])
self.assertTrue(node.dirty) node.dirty = False node.session_data = '123' self.assertTrue(node.dirty) node.dirty = False def test_get_set_properties(self): nid = NodeID.for_host('127.0.0.1') node = Node(nid) node.session_data = 'sd1' self.assertEqual(node.session_data, 'sd1') ctrl = TestController.new_test_instance() node.subscribe(ctrl) now = datetime.now() self.assertTrue(timedelta(seconds = 0) <= now - node.subscription_timestamp <= timedelta(seconds = 3)) self.assertEqual(node.controller, ctrl) node.task_id = 'tid789' now = datetime.now() self.assertTrue(timedelta(seconds = 0) <= now - node.task_timestamp <= timedelta(seconds = 3)) self.assertEqual(node.task_id, 'tid789') kaylee_suite = load_tests([NodeTests, NodeIDTests, ])
self.assertIn(nid, kl.registry) self.assertIn(node_config['node_id'], kl.registry) kl.unregister(nid) self.assertNotIn(nid, kl.registry) def test_subscribe_unsubscribe(self): kl = loader.load(self.settings) app = kl.applications['test.1'] node_json_config = kl.register('127.0.0.1') node_config = json.loads(node_json_config) node_id = node_config['node_id'] # test node.subscribe app_json_config = kl.subscribe(node_id, 'test.1') app_config = json.loads(app_json_config) self.assertEqual(app_config['test_key'], 'test_value') node = kl.registry[node_id] self.assertEqual(node.controller, app) self.assertTrue(0 <= (datetime.now() - node.subscription_timestamp).seconds < 1) # test node.unsubscribe kl.unsubscribe(node_id) self.assertIsNone(node.controller) self.assertIsNone(node.subscription_timestamp) self.assertIn(node, kl.registry) kaylee_suite = load_tests([KayleeTests])
self.assertIsInstance(reg, MemoryNodesRegistry) def test_load_session_data_manager(self): settings = dict(TestSettings.__dict__) ldr = Loader(settings) sdm = ldr.session_data_manager self.assertIsInstance(sdm, JSONSessionDataManager) def test_load_kaylee(self): kl = loader.load(TestSettingsWithApps) self.assertIsInstance(kl.registry, MemoryNodesRegistry) app = kl.applications['test.1'] self.assertEqual(app.__class__.__name__, 'TestController1') self.assertEqual(app.project.__class__.__name__, 'AutoTestProject') def test_kaylee_setup(self): from kaylee import setup, kl self.assertIsNone(kl._wrapped) setup(TestSettingsWithApps) self.assertIsNotNone(kl._wrapped) self.assertIsInstance(kl.registry, MemoryNodesRegistry) app = kl.applications['test.1'] self.assertEqual(app.__class__.__name__, 'TestController1') self.assertEqual(app.project.__class__.__name__, 'AutoTestProject') kaylee_suite = load_tests([KayleeLoaderTests])
task = { 'id' : 'i2' } orig_task = deepcopy(task) jsdm.store(node, task) self.assertEqual(task, orig_task) jsdm.restore(node, task) self.assertEqual(task, orig_task) def test_phony_session_data_manager(self): node = Node(NodeID.for_host('127.0.0.1')) task1 = { 'id' : 'i1', '#s1' : 10, '#s2' : [1, 2, 3], } psdm = PhonySessionDataManager() self.assertRaises(KayleeError, psdm.store, node, task1) task2 = { 'id' : 'i1', } # this should be executed without any errors self.assertIsNone(psdm.store(node, task2)) kaylee_suite = load_tests([KayleeSessionTests, ])
pass def test_project_mode(self): # test if initializing Project without a mode raises a ValueError class MyProjectNoMode(NonAbstractProject): def __init__(self): super(MyProjectNoMode, self).__init__("/script.js") self.assertRaises(TypeError, MyProjectNoMode) # -- test with invalid mode class MyProjectInvalidMode(NonAbstractProject): def __init__(self): super(MyProjectInvalidMode, self).__init__("/script.js", mode='abc') self.assertRaises(ValueError, MyProjectInvalidMode) # -- test with valid modes class MyProjectWithAutoMode(NonAbstractProject): def __init__(self): super(MyProjectWithAutoMode, self).__init__("/script.js", AUTO_PROJECT_MODE) MyProjectWithAutoMode() class MyProjectWithManualMode(NonAbstractProject): def __init__(self): super(MyProjectWithManualMode, self).__init__("/script.js", MANUAL_PROJECT_MODE) MyProjectWithManualMode() kaylee_suite = load_tests([ProjectTests, ])
self.assertRaises(OSError, lmanager.parse, ['run']) def _validate_content(self, gtdir, tmpdir, files_to_validate): for fpath in files_to_validate: with open(_pjoin(tmpdir, fpath)) as f: generated_file_contents = f.read() with open(_pjoin(gtdir, fpath)) as f: ground_truth_file_contents = f.read().rstrip('\n') self.assertEqual(generated_file_contents, ground_truth_file_contents) def _start_env(name='tenv'): amanager = AdminCommandsManager() tmpdir = tmp_chdir() env_path = os.path.abspath(_pjoin(tmpdir, name)) with nostdout(): amanager.parse(['startenv', 'tenv']) return env_path kaylee_suite = load_tests([KayleeCommandsManagerTests])