def test_for_no_tenplate(self):
     """
     Tests method for assembling the value of a target_field that doesn't use
     a string template.
     """
     parser = FieldParser(source_fields='text')
     actual = parser.process(self.doc)
     expected = 'this is an example post'
     self.assertEqual(actual, expected)
 def test_for_string_tenplate(self):
     """
     Tests method for assembling the value of a target_field that uses
     a string template.
     """
     parser = FieldParser(source_fields='user.screen_name, id_str',
                          formatter='https://twitter.com/{}/statuses/{}')
     actual = parser.process(self.doc)
     expected = 'https://twitter.com/zebrafinch/statuses/0123456'
     self.assertEqual(actual, expected)
 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')
 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()
 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')
 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()
 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()
 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()
 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()
 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()
 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()
 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()