def test(self):
        '''
        Test the modelchoicefield schnipp translation
        '''
        for i in range(0, 3):
            c = models.Category(name='Cat-%s' % i)
            c.save()
        
        class BarForm(forms.Form):
            some_modelchoice = forms.ModelChoiceField(queryset=models.Category.objects.all())
        
        form = BarForm()
        schema = schnippforms.get_schema(form, 'mybarform')

        for f in schema['fields']:
            if f['name'] == 'some_modelchoice':
                self.assertEquals(
                    len(f['options']),
                    models.Category.objects.all().count()
                )
                for o in f['options']:
                    self.assertEquals(o['label'], str(models.Category.objects.get(id=o['value'])))
                break
                
        
        form = BarForm({'some_modelchoice': 1})
        form.is_valid()
        self.assertEquals(
            type(form.cleaned_data['some_modelchoice']),
            models.Category
        )
Beispiel #2
0
def testing(request):
    '''
    Required for selenium tests; 
    '''    
    
    cat = Category(name='Coding')
    cat.save()
    n = News(name='Djangoproductline', teaser='productivity', rating=1, somefloat=62.8, category=cat)
    n.save()
    
    if len(News.objects.all()) == 0:
        raise Exception('''
            This view is used for Liveserver/selenium tests. Please create at least one News object if you want to 
            access this views manually.
        ''')
    

    MyForm = modelform_factory(News)
    
    if request.method == 'POST':
        data = json.loads(request.POST['ajax_data'])
        form = MyForm(data)
        if form.is_valid():
            obj = form.save()
            return HttpResponse(json.dumps(schnippforms.get_context(obj)))
    else:
        form = MyForm()
                    
    return render(request, 'testing.html', {
        'schema': json.dumps(schnippforms.get_schema(form, name='myform')),
        'context': json.dumps(schnippforms.get_context(News.objects.all()[0]))
    })
 def test(self):        
     class BarForm(forms.ModelForm):
         class Meta:
             model = models.News
     
     form = BarForm()
     schema = schnippforms.get_schema(form, 'barform')
 def test_schema_generation_with_default_passed_as_context(self):
     schema = schnippforms.get_schema(
         FooForm(), 'hansi', dict(some_name='schnippjs', some_int=5))
     field = schnippforms.get_field_from_schema('some_name', schema)
     self.assertEquals(field['default_value'], 'schnippjs')
     field = schnippforms.get_field_from_schema('some_int', schema)
     self.assertEquals(field['default_value'], 5)
    def test(self):
        class BarForm(forms.ModelForm):
            class Meta:
                model = models.News

        form = BarForm()
        schema = schnippforms.get_schema(form, 'barform')
    def test(self):
        '''
        Test the modelchoicefield schnipp translation
        '''
        for i in range(0, 3):
            c = models.Category(name='Cat-%s' % i)
            c.save()

        class BarForm(forms.Form):
            some_modelchoice = forms.ModelChoiceField(
                queryset=models.Category.objects.all())

        form = BarForm()
        schema = schnippforms.get_schema(form, 'mybarform')

        for f in schema['fields']:
            if f['name'] == 'some_modelchoice':
                self.assertEquals(len(f['options']),
                                  models.Category.objects.all().count())
                for o in f['options']:
                    self.assertEquals(
                        o['label'],
                        str(models.Category.objects.get(id=o['value'])))
                break

        form = BarForm({'some_modelchoice': 1})
        form.is_valid()
        self.assertEquals(type(form.cleaned_data['some_modelchoice']),
                          models.Category)
 def test_get_schema(self):
     '''
     Test get_schema translator.
     '''
     form = FooForm()
     schema = schnippforms.get_schema(form, 'FooForm')
     self.assertTrue(schema.has_key('name'))
     for schnield in schema['fields']:
         self.check_attrs(schnield['name'], form.fields[schnield['name']], schnield)
 def test_get_schema(self):
     '''
     Test get_schema translator.
     '''
     form = FooForm()
     schema = schnippforms.get_schema(form, 'FooForm')
     self.assertTrue(schema.has_key('name'))
     for schnield in schema['fields']:
         self.check_attrs(schnield['name'], form.fields[schnield['name']],
                          schnield)
Beispiel #9
0
def testing(request):
    '''
    Required for selenium tests; 
    '''

    cat = Category(name='Coding')
    cat.save()
    n = News(name='Djangoproductline',
             teaser='productivity',
             rating=1,
             somefloat=62.8,
             category=cat)
    n.save()

    if len(News.objects.all()) == 0:
        raise Exception('''
            This view is used for Liveserver/selenium tests. Please create at least one News object if you want to 
            access this views manually.
        ''')

    MyForm = modelform_factory(News)

    if request.method == 'POST':
        data = json.loads(request.POST['ajax_data'])
        form = MyForm(data)
        if form.is_valid():
            obj = form.save()
            return HttpResponse(json.dumps(schnippforms.get_context(obj)))
    else:
        form = MyForm()

    return render(
        request, 'testing.html', {
            'schema': json.dumps(schnippforms.get_schema(form, name='myform')),
            'context': json.dumps(
                schnippforms.get_context(News.objects.all()[0]))
        })
Beispiel #10
0
 def test_get_field_from_schema(self):
     schema = schema = schnippforms.get_schema(FooForm(), 'hansi')
     field = schnippforms.get_field_from_schema('some_name', schema)
     self.assertEquals(field['name'], 'some_name')
Beispiel #11
0
 def test_schema_generation_with_default_passed_as_context(self):
     schema = schnippforms.get_schema(FooForm(), 'hansi', dict(some_name='schnippjs', some_int=5))
     field = schnippforms.get_field_from_schema('some_name', schema)
     self.assertEquals(field['default_value'], 'schnippjs')
     field = schnippforms.get_field_from_schema('some_int', schema)
     self.assertEquals(field['default_value'], 5)
Beispiel #12
0
 def test_get_field_from_schema(self):
     schema = schema = schnippforms.get_schema(FooForm(), 'hansi')
     field = schnippforms.get_field_from_schema('some_name', schema)
     self.assertEquals(field['name'], 'some_name')