Esempio n. 1
0
class ConversionTestCase(unittest.TestCase):
    """
    Ensure we can reliably convert native python data types to strings.
    """

    def setUp(self):
        self.task = MysqlSelectTask(
            credentials=sentinel.ignored,
            destination=sentinel.ignored
        )

    def test_convert_datetime(self):
        self.assert_converted_string_equals(
            datetime.datetime.strptime('2014-01-02', '%Y-%m-%d').date(), '2014-01-02'
        )

    def assert_converted_string_equals(self, obj, expected_string):
        """
        Args:
            obj (mixed): Any object.
            expected_string (str): The expected string representation of `obj`.

        Raises:
            AssertionError: iff the string resulting from converting `obj` to a string does not match the
                expected string.
        """
        self.assertEquals(self.task.convert(obj), expected_string)

    def test_convert_integer(self):
        self.assert_converted_string_equals(
            10, '10'
        )

    def test_convert_none(self):
        self.assert_converted_string_equals(
            None, '-'
        )

    def test_convert_unicode(self):
        self.assert_converted_string_equals(
            u'\u0669(\u0361\u0e4f\u032f\u0361\u0e4f)\u06f6',
            u'\u0669(\u0361\u0e4f\u032f\u0361\u0e4f)\u06f6'.encode('utf-8')
        )
Esempio n. 2
0
 def setUp(self):
     self.task = MysqlSelectTask(
         credentials=sentinel.ignored,
         destination=sentinel.ignored
     )
Esempio n. 3
0
 def test_parameters_from_config(self):
     t = MysqlSelectTask(credentials=sentinel.credentials, destination=sentinel.destination)
     self.assertEquals(t.database, 'foobar')