def test_unicode(self): i = DataBag() i.data['key'] = 'è' i.save() i.data['key'] = u'è' i.save()
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_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')
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_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_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_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))
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)