def test_schemadatabag_assignment(self):
     d = SchemaDataBag()
     d.number = 4
     self.assertEqual(d.data['number'], 4)
     d.float = 2.5
     self.assertEqual(d.data['float'], 2.5)
     d.data['number'] = 5
     self.assertEqual(d.number, 5)
 def test_schemadatabag_save(self):
     d = SchemaDataBag()
     d.name = 'test'
     d.number = 4
     d.float = 2.0
     d.save()
     d = SchemaDataBag.objects.get(pk=d.id)
     self.assertEqual(d.number, 4)
     self.assertEqual(d.data['number'], 4)
    def test_schemadatabag_validation_error(self):
        d = SchemaDataBag()
        d.name = 'test'
        d.number = 'WRONG'
        d.float = 2.0

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

        d.number = 9
        d.float = 'WRONG'
        with self.assertRaises(ValidationError):
            d.full_clean()

        d.float = 2.0
        d.char = 'test'
        d.choice = 'choice1'
        d.full_clean()
        d.save()
    def test_utf8(self):
        d = SchemaDataBag()
        d.name = 'test'
        d.number = 4
        d.float = 2.0
        d.char = 'è'
        d.full_clean()
        d.save()

        d = SchemaDataBag.objects.get(pk=d.id)
        self.assertEqual(d.char, u'è')

        d.char = u'è'
        d.full_clean()
        d.save()

        d = SchemaDataBag.objects.get(pk=d.id)
        self.assertEqual(d.char, u'è')
    def test_admin_change(self):
        self._login_as_admin()
        d = SchemaDataBag()
        d.name = 'test1'
        d.number = 1
        d.float = 2.5
        d.save()
        url = reverse('admin:django_hstore_tests_schemadatabag_change', args=[d.id])
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        response = self.client.post(url, {'name': 'test_change', 'number': 6, 'float': 2.6})
        d = SchemaDataBag.objects.get(pk=d.id)
        self.assertEqual(d.name, 'test_change')
        self.assertEqual(d.number, 6)
        self.assertEqual(d.data['number'], 6)
        self.assertEqual(d.float, 2.6)
        self.assertEqual(d.data['float'], 2.6)