Ejemplo n.º 1
0
class AdminFormFieldTestCase(unittest.TestCase):
    def setUp(self):
        self.admin_model = DocumentAdmin(SimpleDocument,
                                         admin.site,
                                         schema=SimpleDocument)
        self.schema_model = SchemaAdmin(SimpleDocument,
                                        admin.site,
                                        schema=SimpleSchema,
                                        documentadmin=self.admin_model)
        self.factory = RequestFactory()
        User.objects.all().delete()  #why?
        self.super_user = User.objects.create(is_staff=True,
                                              is_active=True,
                                              is_superuser=True,
                                              username='******')

    def test_formfield_for_field_with_complex_list_field(self):
        request = self.factory.get('/')
        prop = SimpleDocument._meta.fields['complex_list']
        field = prop.get_form_field_class()
        kwargs = prop.formfield_kwargs()
        kwargs['request'] = request

        view = MockView(request)
        admin_field = self.admin_model.formfield_for_field(
            prop, field, view, **kwargs)
        field_html = admin_field.widget.render('complex_list', [])
        self.assertTrue('value="add"' in field_html)

    def test_inline_form_field_for_field_with_complex_list_field(self):
        request = self.factory.get('/')
        instances = self.admin_model.get_default_inline_instances()
        self.assertEqual(len(instances), 1)

        inline_admin = instances[0]
        prop = inline_admin.schema._meta.fields['gallery']
        field = prop.get_form_field_class()
        kwargs = prop.formfield_kwargs()
        kwargs['request'] = request
        view = MockView(request)
        admin_field = inline_admin.formfield_for_field(prop, field, view,
                                                       **kwargs)
        assert admin_field.dotpath, str(admin_field.dotpath)
        field_html = admin_field.widget.render('complex_list', [])
        self.assertTrue('value="add"' in field_html)

    def test_inline_get_formset(self):
        request = self.factory.get('/')
        instances = self.admin_model.get_default_inline_instances()
        self.assertEqual(len(instances), 1)
        view = MockView(request)

        inline_admin = instances[0]
        formset = inline_admin.get_formset(request, view=view)
        html = list()
        for form in formset(instance=SimpleDocument()):
            assert form._meta.formfield_callback
            html.append(form.as_table())
        html = '\n'.join(html)
        self.assertTrue('value="add"' in html, html)
Ejemplo n.º 2
0
class AdminViewsTestCase(unittest.TestCase):
    def setUp(self):
        self.admin_model = DocumentAdmin(SimpleDocument, admin.site)
        self.schema_model = SchemaAdmin(SimpleDocument, admin.site, schema=SimpleSchema, documentadmin=self.admin_model)
        self.factory = RequestFactory()
        User.objects.all().delete() #why?
        self.super_user = User.objects.create(is_staff=True, is_active=True, is_superuser=True, username='******')
    
    def test_changelist_view(self):
        kwargs = self.admin_model.get_view_kwargs()
        view = IndexView.as_view(**kwargs)
        request = self.factory.get('/')
        request.user = self.super_user
        response = view(request)
        self.assertEqual(response.status_code, 200)
    
    def test_create_view(self):
        kwargs = self.admin_model.get_view_kwargs()
        view = DocumentProxyView.as_view(**kwargs)
        request = self.factory.get('/add/')
        request.user = self.super_user
        response = view(request)
        self.assertEqual(response.status_code, 200)
    
    def test_list_field_index_view(self):
        kwargs = self.schema_model.get_view_kwargs()
        #kwargs['schema'] = SimpleSchema #TODO why does this break things?
        #assert False, str(dir(ListFieldIndexView))
        view = ListFieldIndexView.as_view(**kwargs)
        view.schema = SimpleSchema
        params = {'_dotpath': 'complex_list'}
        request = self.factory.get('/add/?%s' % urlencode(params))
        request.user = self.super_user
        response = view(request)
        self.assertEqual(response.status_code, 200)
    
    def test_delete_view(self):
        kwargs = self.admin_model.get_view_kwargs()
        kwargs['object'] = SimpleDocument()
        view = TestableDeleteView.as_view(**kwargs)
        
        request = self.factory.get('/1/delete/')
        request.user = self.super_user
        response = view(request)
        self.assertEqual(response.status_code, 200)
        
        request = self.factory.post('/1/delete/')
        request.user = self.super_user
        response = view(request)
        self.assertEqual(response.status_code, 302)
Ejemplo n.º 3
0
 def setUp(self):
     self.admin_model = DocumentAdmin(SimpleDocument,
                                      admin.site,
                                      schema=SimpleDocument)
     self.schema_model = SchemaAdmin(SimpleDocument,
                                     admin.site,
                                     schema=SimpleSchema,
                                     documentadmin=self.admin_model)
     self.factory = RequestFactory()
     User.objects.all().delete()  #why?
     self.super_user = User.objects.create(is_staff=True,
                                           is_active=True,
                                           is_superuser=True,
                                           username='******')
Ejemplo n.º 4
0
class AdminFormFieldTestCase(unittest.TestCase):
    def setUp(self):
        self.admin_model = DocumentAdmin(SimpleDocument, admin.site, schema=SimpleDocument)
        self.schema_model = SchemaAdmin(SimpleDocument, admin.site, schema=SimpleSchema, documentadmin=self.admin_model)
        self.factory = RequestFactory()
        User.objects.all().delete() #why?
        self.super_user = User.objects.create(is_staff=True, is_active=True, is_superuser=True, username='******')
    
    def test_formfield_for_field_with_complex_list_field(self):
        request = self.factory.get('/')
        prop = SimpleDocument._meta.fields['complex_list']
        field = prop.get_form_field_class()
        kwargs = prop.formfield_kwargs()
        kwargs['request'] = request
        
        view = MockView(request)
        admin_field = self.admin_model.formfield_for_field(prop, field, view, **kwargs)
        field_html = admin_field.widget.render('complex_list', [])
        self.assertTrue('value="add"' in field_html)
    
    def test_inline_form_field_for_field_with_complex_list_field(self):
        request = self.factory.get('/')
        instances = self.admin_model.get_default_inline_instances()
        self.assertEqual(len(instances), 1)
        
        inline_admin = instances[0]
        prop = inline_admin.schema._meta.fields['gallery']
        field = prop.get_form_field_class()
        kwargs = prop.formfield_kwargs()
        kwargs['request'] = request
        view = MockView(request)
        admin_field = inline_admin.formfield_for_field(prop, field, view, **kwargs)
        assert admin_field.dotpath, str(admin_field.dotpath)
        field_html = admin_field.widget.render('complex_list', [])
        self.assertTrue('value="add"' in field_html)
        
    def test_inline_get_formset(self):
        request = self.factory.get('/')
        instances = self.admin_model.get_default_inline_instances()
        self.assertEqual(len(instances), 1)
        view = MockView(request)
        
        inline_admin = instances[0]
        formset = inline_admin.get_formset(request, view=view)
        html = list()
        for form in formset(instance=SimpleDocument()):
            assert form._meta.formfield_callback
            html.append(form.as_table())
        html = '\n'.join(html)
        self.assertTrue('value="add"' in html, html)
Ejemplo n.º 5
0
 def setUp(self):
     self.admin_model = DocumentAdmin(SimpleDocument, admin.site)
     self.schema_model = SchemaAdmin(SimpleDocument, admin.site, schema=SimpleSchema, documentadmin=self.admin_model)
     self.factory = RequestFactory()
     User.objects.all().delete() #why?
     self.super_user = User.objects.create(is_staff=True, is_active=True, is_superuser=True, username='******')