Exemplo n.º 1
0
 def test_valid_operators_return_value(self):
     value = [
         1,
         2,
         3,
     ]
     f = ArrayField()
     for op in ArrayField._allowed_operators:
         self.assertEqual(value, f.get_prep_lookup(op, value))
Exemplo n.º 2
0
class PythonValueTestCase(unittest.TestCase):
    """Tests for converting the database value to Python type."""
    def setUp(self):
        self.f = ArrayField()

    def test_none_returns_none(self):
        self.assertIsNone(self.f.to_python(None))

    def test_empty_list_returns_empty_list(self):
        self.assertEqual(self.f.to_python([]), [])

    def test_list_returns_list(self):
        self.assertEqual(self.f.to_python([1, 2]), [1, 2])
class PythonValueTestCase(unittest.TestCase):
    """Tests for converting the database value to Python type."""

    def setUp(self):
        self.f = ArrayField()

    def test_none_returns_none(self):
        self.assertIsNone(self.f.to_python(None))

    def test_empty_list_returns_empty_list(self):
        self.assertEqual(self.f.to_python([]), [])

    def test_list_returns_list(self):
        self.assertEqual(self.f.to_python([1, 2]), [1, 2])
class DbValueTestCase(unittest.TestCase):
    """Tests for converting the Python value to database type."""

    def setUp(self):
        self.f = ArrayField()

    def test_none_returns_none(self):
        # psycopg2 will convert None to NULL
        self.assertIsNone(self.f.get_prep_value(None))

    def test_empty_list_returns_empty_list(self):
        # psycopg2 will convert [] to {}
        self.assertEqual(self.f.get_prep_value([]), [])

    def test_list_returns_list(self):
        value = [1, 2, 3, ]
        self.assertEqual(self.f.get_prep_value(value), value)
Exemplo n.º 5
0
class DbValueTestCase(unittest.TestCase):
    """Tests for converting the Python value to database type."""
    def setUp(self):
        self.f = ArrayField()

    def test_none_returns_none(self):
        # psycopg2 will convert None to NULL
        self.assertIsNone(self.f.get_prep_value(None))

    def test_empty_list_returns_empty_list(self):
        # psycopg2 will convert [] to {}
        self.assertEqual(self.f.get_prep_value([]), [])

    def test_list_returns_list(self):
        value = [
            1,
            2,
            3,
        ]
        self.assertEqual(self.f.get_prep_value(value), value)
Exemplo n.º 6
0
 def test_type_is_always_array(self):
     f = ArrayField()
     setattr(f, '_type', 'int')
     self.assertIn('[]', f.db_type(None))
Exemplo n.º 7
0
 def setUp(self):
     self.f = ArrayField()
Exemplo n.º 8
0
 def test_invalid_operator_raises_type_error(self):
     f = ArrayField()
     self.assertRaises(TypeError, f.get_prep_lookup, 'contains', 'str')
Exemplo n.º 9
0
 def test_respects_type_of_class(self):
     custom_type = 'int'
     f = ArrayField()
     setattr(f, '_type', custom_type)
     self.assertIn(custom_type, f.db_type(None))
 def test_type_is_always_array(self):
     f = ArrayField()
     setattr(f, '_type', 'int')
     self.assertIn('[]', f.db_type(None))
 def setUp(self):
     self.f = ArrayField()
 def test_valid_operators_return_value(self):
     value = [1, 2, 3, ]
     f = ArrayField()
     for op in ArrayField._allowed_operators:
         self.assertEqual(value, f.get_prep_lookup(op, value))
 def test_respects_type_of_class(self):
     custom_type = 'int'
     f = ArrayField()
     setattr(f, '_type', custom_type)
     self.assertIn(custom_type, f.db_type(None))