Example #1
0
 def test_single_field_no_template(self):
     """
     Test case for when a single source_filed is provided without a
     formatter.
     """
     parser = FieldParser(name='user.screen_name',
                          source_fields='user.screen_name')
     try:
         parser.clean()
     except ValidationError:
         self.fail('A ValidationError was raised unexpectedly')
Example #2
0
 def test_multi_fields_no_template(self):
     """
     Test case for when multiple source fields are provided but
     no formatter is given to format them.
     """
     parser = FieldParser(name='user.link',
                          source_fields='user.screen_name, id_str')
     with six.assertRaisesRegex(
             self, ValidationError, 'No template has been '
             'provided for formatting multiple fields'):
         parser.clean()
Example #3
0
 def test_no_regex_for_copy(self):
     """
     Tests that no validation error is raised when the COPY method is chosen
     witha regex.
     """
     parser = FieldParser(name='screen_name',
                          source_fields='user.screen_name',
                          method='COPY')
     try:
         parser.clean()
     except ValidationError:
         self.fail('A ValidationError was raised unexpectedly')
Example #4
0
 def test_no_regex_for_substring(self):
     """
     Tests that a validation error is raised when no regex is defined when
     the SUBSTRING method is chosen.
     """
     parser = FieldParser(name='user.link',
                          source_fields='user.screen_name',
                          method='SUBSTRING')
     with six.assertRaisesRegex(
             self, ValidationError, 'A regex must be provided '
             'to use the Substring method.'):
         parser.clean()
Example #5
0
 def test_no_regex_for_pres_abs(self):
     """
     Tests that a validation error is raised when no regex is defined when
     the P/A method is chosen.
     """
     parser = FieldParser(name='user.link',
                          source_fields='user.screen_name',
                          method='P/A')
     with six.assertRaisesRegex(
             self, ValidationError, 'A regex must be provided '
             'to use the Presence/Absence method.'):
         parser.clean()
Example #6
0
 def test_no_regex_for_count(self):
     """
     Tests that a validation error is raised when no regex is defined when
     the COUNT method is chosen.
     """
     parser = FieldParser(name='user.link',
                          source_fields='user.screen_name',
                          method='COUNT')
     with six.assertRaisesRegex(
             self, ValidationError, 'A regex must be provided '
             'to use the Number of Occurrences method.'):
         parser.clean()
Example #7
0
 def test_too_few_specifiers_single(self):
     """
     Test that a validation error is raised when one source field is
     defined and the formatter has no specifiers.
     """
     parser = FieldParser(name='user.link',
                          source_fields='user.screen_name',
                          formatter='https://twitter.com/statuses/')
     with six.assertRaisesRegex(
             self, ValidationError, 'The formatter should '
             'contain one "{}" specifier.'):
         parser.clean()
Example #8
0
 def test_too_few_specifiers_multi(self):
     """
     Test that a validation error is raised when the formatter has too few
     specifiers for the number of source fields.
     """
     parser = FieldParser(name='user.link',
                          source_fields='user.screen_name, id_str',
                          formatter='https://twitter.com/{}/statuses/')
     with six.assertRaisesRegex(
             self, ValidationError, 'The formatter contains '
             'too few "{}" specifiers for the number of '
             'source fields.'):
         parser.clean()
Example #9
0
 def test_too_many_specifiers_multi(self):
     """
     Test that a validation error is raised when multiple source fields are
     defined and the formatter has too many specifiers.
     """
     parser = FieldParser(name='user.screen_name',
                          source_fields='user.screen_name, id_str',
                          formatter='https://twitter.com/{}/statuses/{}/{}')
     with six.assertRaisesRegex(
             self, ValidationError, 'The number of "{}" '
             'specifiers in the formatter exceeds the '
             'number of source fields.'):
         parser.clean()
Example #10
0
 def test_too_many_specifiers_single(self):
     """
     Test that a validation error is raised when only one source field is
     defined and the formatter has multiple specifiers.
     """
     parser = FieldParser(name='user.screen_name',
                          source_fields='user.screen_name',
                          formatter='https://twitter.com/{}/statuses/{}')
     with six.assertRaisesRegex(
             self, ValidationError, 'The formatter should '
             'only contain one "{}" specifier for the '
             'source field.'):
         parser.clean()