Пример #1
0
  def testStr2Set(self):
    """Tests if symbol separated strings are cleaned.
    """
    string_field = 'test_string_field'
    clean_field = cleaning.str2set(string_field, separator=',')

    string_field_value = "a,b,c"
    cleaned_data_before = {string_field: string_field_value}
    self.form.cleaned_data = cleaned_data_before
    expected = string_field_value.split(',')
    self.assertEqual(clean_field(self.form), expected)

    string_field_value = "a"
    cleaned_data_before = {string_field: string_field_value}
    self.form.cleaned_data = cleaned_data_before
    expected = string_field_value.split()
    self.assertEqual(clean_field(self.form), expected)

    string_field_value = "a b c"
    clean_field = cleaning.str2set(string_field, separator=' ')
    cleaned_data_before = {string_field: string_field_value}
    self.form.cleaned_data = cleaned_data_before
    expected = string_field_value.split()
    self.assertEqual(clean_field(self.form), expected)

    string_field_value = "a, b, c, a"
    clean_field = cleaning.str2set(string_field, separator=',')
    cleaned_data_before = {string_field: string_field_value}
    self.form.cleaned_data = cleaned_data_before
    temp = string_field_value.split(',')
    expected = set([char.strip() for char in temp])
    actual = set(clean_field(self.form))
    self.assertEqual(expected, actual)
Пример #2
0
    def testStr2Set(self):
        """Tests if symbol separated strings are cleaned.
    """
        string_field = 'test_string_field'
        clean_field = cleaning.str2set(string_field, separator=',')

        string_field_value = "a,b,c"
        cleaned_data_before = {string_field: string_field_value}
        self.form.cleaned_data = cleaned_data_before
        expected = string_field_value.split(',')
        self.assertEqual(clean_field(self.form), expected)

        string_field_value = "a"
        cleaned_data_before = {string_field: string_field_value}
        self.form.cleaned_data = cleaned_data_before
        expected = string_field_value.split()
        self.assertEqual(clean_field(self.form), expected)

        string_field_value = "a b c"
        clean_field = cleaning.str2set(string_field, separator=' ')
        cleaned_data_before = {string_field: string_field_value}
        self.form.cleaned_data = cleaned_data_before
        expected = string_field_value.split()
        self.assertEqual(clean_field(self.form), expected)

        string_field_value = "a, b, c, a"
        clean_field = cleaning.str2set(string_field, separator=',')
        cleaned_data_before = {string_field: string_field_value}
        self.form.cleaned_data = cleaned_data_before
        temp = string_field_value.split(',')
        expected = set([char.strip() for char in temp])
        actual = set(clean_field(self.form))
        self.assertEqual(expected, actual)
Пример #3
0
    def wrapper(self):
        """Decorator wrapped method.
    """

        from soc.modules.gci.logic.models.mentor import logic as gci_mentor_logic

        mentors_list_str = cleaning.str2set(field_name)(self)

        fields = {"scope_path": self.cleaned_data.get("scope_path"), "status": "active"}

        mentors = []
        for link_id in mentors_list_str:

            if not validate.isLinkIdFormatValid(link_id):
                raise forms.ValidationError("%s is not a valid link ID." % link_id)

            fields["link_id"] = link_id

            mentor = gci_mentor_logic.getFromKeyFields(fields)
            if not mentor:
                raise forms.ValidationError('link_id "%s" is not a valid Mentor.' % link_id)

            mentors.append(mentor.key())

        return mentors
Пример #4
0
  def wrapper(self):
    """Decorator wrapped method.
    """

    from soc.modules.gci.logic.models.mentor import logic as gci_mentor_logic

    mentors_list_str = cleaning.str2set(field_name)(self)

    fields = {
        'scope_path': self.cleaned_data.get('scope_path'),
        'status': 'active'
        }

    mentors = []
    for link_id in mentors_list_str:

      if not validate.isLinkIdFormatValid(link_id):
        raise forms.ValidationError(
            "%s is not a valid link ID." % link_id)

      fields['link_id'] = link_id

      mentor = gci_mentor_logic.getFromKeyFields(fields)
      if not mentor:
        raise forms.ValidationError(
            'link_id "%s" is not a valid Mentor.' % link_id)

      mentors.append(mentor.key())

    return mentors
Пример #5
0
    def wrapper(self):
        """Decorator wrapped method.
    """

        tag_values = cleaning.str2set(field_name, separator)(self)

        for index, tag_value in enumerate(tag_values):

            if not re.search("\A[\w#+\-\.]*\Z", tag_value):
                raise forms.ValidationError(
                    ugettext(("%s is not a valid tag value. Please see help for more details." % tag_value))
                )

            tag_values[index] = tag_value.lower()

        return tag_values
Пример #6
0
    def wrapper(self):
        """Decorator wrapped method.
    """

        tag_values = cleaning.str2set(field_name, separator)(self)

        for index, tag_value in enumerate(tag_values):

            if not re.search('\A[\w#+\-\.]*\Z', tag_value):
                raise forms.ValidationError(
                    ugettext((
                        '%s is not a valid tag value. Please see help for more details.'
                        % tag_value)))

            tag_values[index] = tag_value.lower()

        return tag_values