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])