def test_number(self):
        databag = DataBag(name='number')
        databag.data['num'] = 1
        self.assertEqual(databag.data['num'], '1')

        databag.save()
        databag = DataBag.objects.get(name='number')
        self.assertEqual(databag.data['num'], '1')

        databag = DataBag(name='number', data={'num': 1})
        self.assertEqual(databag.data['num'], '1')
예제 #2
0
    def test_array_with_decimal(self):
        instance = DataBag(name="decimal")
        array_decimal = [Decimal('1.01')]
        array_dumped = '[1.01]'
        instance.data['arr_dec'] = array_decimal

        self.assertEqual(instance.data['arr_dec'], array_dumped)
        instance.save()

        instance = DataBag.objects.get(pk=instance.pk)
        self.assertEqual(instance.data['arr_dec'], array_dumped)
 def test_native_icontains(self):
     d = DataBag()
     d.name = "A bag of data"
     d.data = {
         'd1': '1',
         'd2': '2'
     }
     d.save()
     result = DataBag.objects.filter(name__icontains='A bAg')
     self.assertEqual(result.count(), 1)
     self.assertEqual(result[0].pk, d.pk)
    def test_decimal(self):
        databag = DataBag(name='decimal')
        databag.data['dec'] = Decimal('1.01')
        self.assertEqual(databag.data['dec'], force_text(Decimal('1.01')))

        databag.save()
        databag = DataBag.objects.get(name='decimal')
        self.assertEqual(databag.data['dec'], force_text(Decimal('1.01')))

        databag = DataBag(name='decimal', data={'dec': Decimal('1.01')})
        self.assertEqual(databag.data['dec'], force_text(Decimal('1.01')))
    def test_array_with_decimal(self):
        instance = DataBag(name="decimal")
        array_decimal = [Decimal('1.01')]
        array_dumped = '[1.01]'
        instance.data['arr_dec'] = array_decimal

        self.assertEqual(instance.data['arr_dec'], array_dumped)
        instance.save()

        instance = DataBag.objects.get(pk=instance.pk)
        self.assertEqual(instance.data['arr_dec'], array_dumped)
    def test_long(self):
        if sys.version < '3':
            l = long(100000000000)
            databag = DataBag(name='long')
            databag.data['long'] = l
            self.assertEqual(databag.data['long'], force_text(l))

            databag.save()
            databag = DataBag.objects.get(name='long')
            self.assertEqual(databag.data['long'], force_text(l))

            databag = DataBag(name='long', data={'long': l})
            self.assertEqual(databag.data['long'], force_text(l))
예제 #7
0
    def test_unicode(self):
        i = DataBag()
        i.data['key'] = 'è'
        i.save()

        i.data['key'] = u'è'
        i.save()
    def test_unicode(self):
        i = DataBag()
        i.data['key'] = 'è'
        i.save()

        i.data['key'] = u'è'
        i.save()
    def test_properties_hstore(self):
        """
        Make sure the hstore field does what it is supposed to.
        """
        from django_hstore.fields import HStoreDict

        instance = DataBag()
        test_props = {'foo': 'bar', 'size': '3'}

        instance.name = 'foo'
        instance.data = test_props
        instance.save()

        self.assertEqual(type(instance.data), HStoreDict)
        self.assertEqual(instance.data, test_props)
        instance = DataBag.objects.get(pk=instance.pk)

        self.assertEqual(type(instance.data), HStoreDict)

        self.assertEqual(instance.data, test_props)
        self.assertEqual(instance.data['size'], '3')
        self.assertIn('foo', instance.data)
예제 #10
0
    def test_number(self):
        databag = DataBag(name='number')
        databag.data['num'] = 1
        self.assertEqual(databag.data['num'], '1')

        databag.save()
        databag = DataBag.objects.get(name='number')
        self.assertEqual(databag.data['num'], '1')

        databag = DataBag(name='number', data={'num': 1})
        self.assertEqual(databag.data['num'], '1')
예제 #11
0
    def test_decimal(self):
        databag = DataBag(name='decimal')
        databag.data['dec'] = Decimal('1.01')
        self.assertEqual(databag.data['dec'], force_text(Decimal('1.01')))

        databag.save()
        databag = DataBag.objects.get(name='decimal')
        self.assertEqual(databag.data['dec'], force_text(Decimal('1.01')))

        databag = DataBag(name='decimal', data={'dec': Decimal('1.01')})
        self.assertEqual(databag.data['dec'], force_text(Decimal('1.01')))
예제 #12
0
 def test_native_icontains(self):
     d = DataBag()
     d.name = "A bag of data"
     d.data = {'d1': '1', 'd2': '2'}
     d.save()
     result = DataBag.objects.filter(name__icontains='A bAg')
     self.assertEqual(result.count(), 1)
     self.assertEqual(result[0].pk, d.pk)
예제 #13
0
    def test_long(self):
        if sys.version < '3':
            l = long(100000000000)
            databag = DataBag(name='long')
            databag.data['long'] = l
            self.assertEqual(databag.data['long'], force_text(l))

            databag.save()
            databag = DataBag.objects.get(name='long')
            self.assertEqual(databag.data['long'], force_text(l))

            databag = DataBag(name='long', data={'long': l})
            self.assertEqual(databag.data['long'], force_text(l))
예제 #14
0
    def test_properties_hstore(self):
        """
        Make sure the hstore field does what it is supposed to.
        """
        from django_hstore.fields import HStoreDict

        instance = DataBag()
        test_props = {'foo': 'bar', 'size': '3'}

        instance.name = 'foo'
        instance.data = test_props
        instance.save()

        self.assertEqual(type(instance.data), HStoreDict)
        self.assertEqual(instance.data, test_props)
        instance = DataBag.objects.get(pk=instance.pk)

        self.assertEqual(type(instance.data), HStoreDict)

        self.assertEqual(instance.data, test_props)
        self.assertEqual(instance.data['size'], '3')
        self.assertIn('foo', instance.data)
예제 #15
0
    def test_hstore_model_field_validation(self):
        d = DataBag()

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = 'test'

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = '["test"]'

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = ["test"]

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = {
            'a': 1,
            'b': 2.2,
            'c': ['a', 'b'],
            'd': {'test': 'test'}
        }

        with self.assertRaises(ValidationError):
            d.full_clean()
예제 #16
0
 def test_str(self):
     d = DataBag()
     self.assertEqual(str(d.data), '{}')
예제 #17
0
    def test_hstore_model_field_validation(self):
        d = DataBag()

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = 'test'

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = '["test"]'

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = ["test"]

        with self.assertRaises(ValidationError):
            d.full_clean()

        d.data = {'a': 1, 'b': 2.2, 'c': ['a', 'b'], 'd': {'test': 'test'}}

        with self.assertRaises(ValidationError):
            d.full_clean()