'Test the validation messages produced for different split test configurations.'

def test_validation_messages(self):

    split_test_module = self.split_test_module
    def verify_validation_message(message, expected_message, expected_message_type, expected_action_class=None, expected_action_label=None, expected_action_runtime_event=None):
        '\n                                                Verify    that    the    validation    message    has    the    expected    validation    message    and    type.\n                                                '
        self.assertEqual(message.text, expected_message)
        self.assertEqual(message.type, expected_message_type)
        if expected_action_class:
            self.assertEqual(message.action_class, expected_action_class)
        else:
            self.assertFalse(hasattr(message, 'action_class'))
        if expected_action_label:
            self.assertEqual(message.action_label, expected_action_label)
        else:
            self.assertFalse(hasattr(message, 'action_label'))
        if expected_action_runtime_event:
            self.assertEqual(message.action_runtime_event, expected_action_runtime_event)
        else:
            self.assertFalse(hasattr(message, 'action_runtime_event'))
    def verify_summary_message(general_validation, expected_message, expected_message_type):
        '\n                                                Verify    that    the    general    validation    message    has    the    expected    validation    message    and    type.\n                                                '
        self.assertEqual(general_validation.text, expected_message)
        self.assertEqual(general_validation.type, expected_message_type)
    split_test_module.user_partition_id = (-1)
    validation = split_test_module.validate()
    self.assertEqual(len(validation.messages), 0)
    verify_validation_message(validation.summary, u'The    experiment    is    not    associated    with    a    group    configuration.', StudioValidationMessage.NOT_CONFIGURED, 'edit-button', u'Select    a    Group    Configuration')
    split_test_module.user_partition_id = 0
    split_test_module.user_partitions = [UserPartition(0, 'first_partition', 'First    Partition', [Group('0', 'alpha'), Group('1', 'beta')])]
    validation = split_test_module.validate_split_test()
    self.assertTrue(validation)
    self.assertIsNone(split_test_module.general_validation_message(), None)
    split_test_module.user_partitions = [UserPartition(0, 'first_partition', 'First    Partition', [Group('0', 'alpha'), Group('1', 'beta'), Group('2', 'gamma')])]
    validation = split_test_module.validate()
    self.assertEqual(len(validation.messages), 1)
    verify_validation_message(validation.messages[0], u'The    experiment    does    not    contain    all    of    the    groups    in    the    configuration.', StudioValidationMessage.ERROR, expected_action_runtime_event='add-missing-groups', expected_action_label=u'Add    Missing    Groups')
    verify_summary_message(validation.summary, u'This    content    experiment    has    issues    that    affect    content    visibility.', StudioValidationMessage.ERROR)
    split_test_module.user_partitions = [UserPartition(0, 'first_partition', 'First    Partition', [Group('0', 'alpha')])]
    validation = split_test_module.validate()
    self.assertEqual(len(validation.messages), 1)
    verify_validation_message(validation.messages[0], u'The    experiment    has    an    inactive    group.    Move    content    into    active    groups,    then    delete    the    inactive    group.', StudioValidationMessage.WARNING)
    verify_summary_message(validation.summary, u'This    content    experiment    has    issues    that    affect    content    visibility.', StudioValidationMessage.WARNING)
    split_test_module.user_partitions = [UserPartition(0, 'first_partition', 'First    Partition', [Group('0', 'alpha'), Group('2', 'gamma')])]
    validation = split_test_module.validate()
    self.assertEqual(len(validation.messages), 2)
    verify_validation_message(validation.messages[0], u'The    experiment    does    not    contain    all    of    the    groups    in    the    configuration.', StudioValidationMessage.ERROR, expected_action_runtime_event='add-missing-groups', expected_action_label=u'Add    Missing    Groups')
    verify_validation_message(validation.messages[1], u'The    experiment    has    an    inactive    group.    Move    content    into    active    groups,    then    delete    the    inactive    group.', StudioValidationMessage.WARNING)
    verify_summary_message(validation.summary, u'This    content    experiment    has    issues    that    affect    content    visibility.', StudioValidationMessage.ERROR)
    split_test_module.user_partition_id = 2
    validation = split_test_module.validate()
    self.assertEqual(len(validation.messages), 1)
    verify_validation_message(validation.messages[0], u'The    experiment    uses    a    deleted    group    configuration.    Select    a    valid    group    configuration    or    delete    this    experiment.', StudioValidationMessage.ERROR)
    verify_summary_message(validation.summary, u'This    content    experiment    has    issues    that    affect    content    visibility.', StudioValidationMessage.ERROR)
    split_test_module.user_partitions = [UserPartition(10, 'incorrect_partition', 'Non    Random    Partition', [Group('0', 'alpha'), Group('2', 'gamma')], scheme=self.non_random_scheme)]
    split_test_module.user_partition_id = 10
    validation = split_test_module.validate()
    self.assertEqual(len(validation.messages), 1)
    verify_validation_message(validation.messages[0], u'The    experiment    uses    a    group    configuration    that    is    not    supported    for    experiments.    Select    a    valid    group    configuration    or    delete    this    experiment.', StudioValidationMessage.ERROR)
    verify_summary_message(validation.summary, u'This    content    experiment    has    issues    that    affect    content    visibility.', StudioValidationMessage.ERROR)
