def test_submodule_list(self): state = State(configuration3, state_name='state') sub_state_list_item_1 = State(configuration3['sub_module_list'][0], state_name=0, parent_states=['state']) self.assertEqual(sub_state_list_item_1, state.sub_module_list[0]) self.assertEqual(['attr1', 'attr2'], state.attribute_list)
def test_need_noname_generation(self): state1 = State({'attribute': 'first_state'}) state2 = State({'attribute': 'second_state'}) result = state1.determine_needs(state2) expected = Need('attribute', StateOperations.SET, value='first_state', old_value='second_state') self.assertEqual(expected, result[0])
def test_need_generation_absent_cstate(self): state1 = State({'attribute': 'first_state'}, state_name='statetest') state2 = State({}, state_name='statetest') result = state1.determine_needs(state2) expected = Need('attribute', StateOperations.SET, value='first_state', parent_states=['statetest']) self.assertEqual(expected, result[0])
def test_strict_need_generation(self): state1 = State({}, state_name='statetest') state2 = State({'deleteme': False}, state_name='statetest') result = state1.determine_needs(state2, strict=True) expected = Need( 'deleteme', StateOperations.DELETE, old_value=False, parent_states=['statetest'], ) self.assertEqual(expected, result[0])
def test_need_basic_generation_str_with_metadata(self): state1 = State({'attribute': 'first_state'}, state_name='statetest', metadata={'attr': 'key'}) state2 = State({'attribute': 'second_state'}, state_name='statetest') result = state1.determine_needs(state2) expected = Need('attribute', StateOperations.SET, value='first_state', old_value='second_state', parent_states=['statetest'], metadata={'attr': 'key'}) self.assertEqual(expected, result[0])
def test_need_address_path_generation(self): state1 = State({'attribute': 'first_state'}, state_name='statetest', address_path=['module1']) state2 = State({'attribute': 'second_state'}, state_name='statetest', address_path=['module1']) result = state1.determine_needs(state2) expected = Need('attribute', StateOperations.SET, value='first_state', old_value='second_state', parent_states=['statetest'], address_path=['module1']) self.assertEqual(expected, result[0])
def test_nested_need_generation_str(self): state1 = State({'sub_state': { 'attribute': 'newval' }}, state_name='statetest') state2 = State( { 'irrelevant_attribute': False, 'sub_state': { 'attribute': 'oldval' } }, state_name='statetest') result = state1.determine_needs(state2) expected = Need( 'attribute', StateOperations.SET, value='newval', old_value='oldval', parent_states=['statetest', 'sub_state'], ) self.assertEqual(expected, result[0])
def test_deseralize_config3(self): state = State(configuration3, state_name='state') self.assertEqual(configuration3, state.render_dict())
def test_submodule(self): state = State(configuration2, state_name='state') sub_state = State(configuration2['sub_module'], state_name='sub_module', parent_states=['state']) self.assertEqual(sub_state, state.sub_module)
def test_attributes(self): state = State(configuration1, state_name='state') self.assertEqual(1, state.attribute1) self.assertEqual('hello', state.attribute2)