'Verifies sort order and direction for multiple instances.'

def test_instance_get_all_by_filters_sort_keys(self, mock_get_regexp):

    test1_active = self.create_instance_with_args(display_name='test1', vm_state=vm_states.ACTIVE)
    test1_error = self.create_instance_with_args(display_name='test1', vm_state=vm_states.ERROR)
    test1_error2 = self.create_instance_with_args(display_name='test1', vm_state=vm_states.ERROR)
    test2_active = self.create_instance_with_args(display_name='test2', vm_state=vm_states.ACTIVE)
    test2_error = self.create_instance_with_args(display_name='test2', vm_state=vm_states.ERROR)
    test2_error2 = self.create_instance_with_args(display_name='test2', vm_state=vm_states.ERROR)
    other_error = self.create_instance_with_args(display_name='other', vm_state=vm_states.ERROR)
    other_active = self.create_instance_with_args(display_name='other', vm_state=vm_states.ACTIVE)
    filters = {'display_name': '%test%'}
    sort_keys = ['display_name', 'vm_state', 'created_at']
    sort_dirs = ['asc', 'asc', 'asc']
    correct_order = [test1_active, test1_error, test1_error2, test2_active, test2_error, test2_error2]
    self._assert_equals_inst_order(correct_order, filters, sort_keys=sort_keys, sort_dirs=sort_dirs)
    sort_dirs = ['asc', 'desc', 'asc']
    correct_order = [test1_error, test1_error2, test1_active, test2_error, test2_error2, test2_active]
    self._assert_equals_inst_order(correct_order, filters, sort_keys=sort_keys, sort_dirs=sort_dirs)
    sort_dirs = ['desc', 'desc', 'asc']
    correct_order = [test2_error, test2_error2, test2_active, test1_error, test1_error2, test1_active]
    self._assert_equals_inst_order(correct_order, filters, sort_keys=sort_keys, sort_dirs=sort_dirs)
    sort_keys = ['display_name', 'vm_state']
    sort_dirs = ['desc', 'desc']
    correct_order = [test2_error2, test2_error, test2_active, test1_error2, test1_error, test1_active]
    self._assert_equals_inst_order(correct_order, filters, sort_keys=sort_keys, sort_dirs=sort_dirs)
    sort_dirs = ['asc', 'asc']
    correct_order = [test1_active, test1_error, test1_error2, test2_active, test2_error, test2_error2]
    self._assert_equals_inst_order(correct_order, filters, sort_keys=sort_keys, sort_dirs=sort_dirs)
    correct_order = [other_active, other_error, test1_active, test1_error, test1_error2, test2_active, test2_error, test2_error2]
    self._assert_equals_inst_order(correct_order, {}, sort_keys=sort_keys, sort_dirs=sort_dirs)
    correct_order = [other_active, other_error, test2_error2, test2_error, test2_active, test1_error2, test1_error, test1_active]
    self._assert_equals_inst_order(correct_order, {})
