def test_list(): class Person(models.Model): name = models.CharField(max_length=255) age = models.IntegerField() def __unicode__(self): return self.name # Create tables in the database if they don't exists try: install_models(Person) except DatabaseError, e: if 'already exists' not in e.message: raise
def test_list(): class Person(models.Model): name = models.CharField(max_length=255) age = models.IntegerField() def __unicode__(self): return self.name # Create tables in the database if they don't exists try: install_models(Person) except DatabaseError as e: if 'already exists' not in e.message: raise Person.objects.all().delete() view = CustomModelView(Person) admin.add_view(view) eq_(view.model, Person) eq_(view.name, 'Person') eq_(view.endpoint, 'person') eq_(view.url, '/admin/person') # Verify form with app.test_request_context(): Form = view.get_form() ok_(isinstance(Form()._fields['name'], wtf.TextField)) ok_(isinstance(Form()._fields['age'], wtf.IntegerField)) # Make some test clients client = app.test_client() resp = client.get('/admin/person/') eq_(resp.status_code, 200) resp = client.get('/admin/person/add/') eq_(resp.status_code, 200) resp = client.post('/admin/person/add/', data=dict(name='name', age='18')) eq_(resp.status_code, 302) person = Person.objects.all()[0] eq_(person.name, 'name') eq_(person.age, 18) resp = client.get('/admin/person/') eq_(resp.status_code, 200) ok_(person.name in resp.data) resp = client.get('/admin/person/%s/' % person.pk) eq_(resp.status_code, 200) resp = client.post('/admin/person/%s/' % person.pk, data=dict(name='changed')) eq_(resp.status_code, 302) person = Person.objects.all()[0] eq_(person.name, 'changed') eq_(person.age, 18) resp = client.post('/admin/person/%s/delete/' % person.pk) eq_(resp.status_code, 200) eq_(Person.objects.count(), 1) resp = client.post('/admin/person/%s/delete/' % person.pk, data={'confirm_delete': True}) eq_(resp.status_code, 302) eq_(Person.objects.count(), 0)