def test_update_context_variables(self): variable_binds = {'foo': 'correct', 'test': 'value'} context = Context() test = TestCase('', None, variable_binds, context=context) context.bind_variable('foo', 'broken') test.pre_update(context) self.assertEqual('correct', context.get_value('foo')) self.assertEqual('value', context.get_value('test'))
def test_update_context_generators(self): """ Test updating context variables using generator """ variable_binds = {'foo': 'initial_value'} generator_binds = {'foo': 'gen'} context = Context() test = TestCase('', None, variable_binds, context=context) test.generator_binds = generator_binds context.bind_variable('foo', 'broken') context.add_generator('gen', generators.generator_basic_ids()) context.bind_generator_next('foo', 'gen') self.assertEqual(1, context.get_value('foo')) context.bind_generator_next('foo', 'gen') self.assertEqual(2, context.get_value('foo'))
def test_variables(self): """ Test bind/return of variables """ context = Context() context.variables = {} self.assertTrue(context.get_value('foo') is None) self.assertEqual(0, context.mod_count) context.bind_variable('foo', 'bar') self.assertEqual('bar', context.get_value('foo')) self.assertEqual('bar', context.get_values()['foo']) self.assertEqual(1, context.mod_count) context.bind_variable('foo', 'bar2') self.assertEqual('bar2', context.get_value('foo')) self.assertEqual(2, context.mod_count)
def test_variable_binding(self): """ Test that tests successfully bind variables """ element = 3 test_config = [{ "url": "/ping" }, { "name": "cheese" }, { "expected_status": ["200", 204, "202"] }, { "variable_binds": { 'var': 'value' } }] context = Context() test = TestCase('', None, context) test.parse(test_config) binds = test.variable_binds self.assertEqual(1, len(binds)) self.assertEqual('value', binds['var']) # Test that updates context correctly test.pre_update(context) self.assertEqual('value', context.get_value('var'))
def test_mixing_binds(self): """ Ensure that variables are set correctly when mixing explicit declaration and variables """ context = Context() context.add_generator('gen', count_gen()) context.bind_variable('foo', '100') self.assertEqual(1, context.mod_count) context.bind_generator_next('foo', 'gen') self.assertEqual(1, context.get_value('foo')) self.assertEqual(2, context.mod_count)
def test_generator_bind(self): """ Test generator setting to variables """ context = Context() self.assertEqual(0, len(context.get_generators())) my_gen = count_gen() context.add_generator('gen', my_gen) context.bind_generator_next('foo', 'gen') self.assertEqual(1, context.mod_count) self.assertEqual(1, context.get_value('foo')) self.assertTrue(2, next(context.get_generator('gen'))) self.assertTrue(3, next(my_gen))
def test_basic_ids(self): """ Test starting ids """ ids1 = generators.generator_basic_ids() ids2 = generators.generator_basic_ids() self.generator_repeat_test(ids1) self.generator_repeat_test(ids2) self.assertEqual(next(ids1), next(ids2)) c = Context() c.variables = {'x': '$x'} x = generators.factory_generate_ids(1, increment=0)() c.add_generator('x', x) self.assertEqual(c.bind_generator_next('x', 'x'), c.bind_generator_next('x', 'x')) c.bind_variable('x', 1) var1 = c.get_value('x') c.bind_variable('x', 1) var2 = c.get_value('x') self.assertEqual(var1, var2)