コード例 #1
0
 def test_saveProfileForm_whenEgnContainsOnlyDigitsBut11_shouldBeInvalid(self):
     name = 'Doncho'
     age = 19
     egn = '12345678011'
     form = ProfileForm(data={
         'name': name,
         'age': age,
         'egn': egn,
     })
     self.assertFalse(form.is_valid())
コード例 #2
0
ファイル: test_profile.py プロジェクト: marioyankov/django101
    def test_saveProfileForm_whenValidEgn_shouldBeValid(self):
        name = 'Doncho'
        age = 19
        egn = '1234567890'
        form = ProfileForm(data={
            'name': name,
            'age': age,
            'egn': egn,
        })

        self.assertTrue(form.is_valid())
コード例 #3
0
    def test_saveProfileForm_whenValidEgn(self):
        name='Georgi'
        age= 21
        egn = '1234567890'
        form = ProfileForm(data={
            'name': name,
            'age': age,
            'egn': egn,
        })

        self.assertTrue(form.is_valid())
コード例 #4
0
    def test_saveProfileForm_when_egn_contains_11_digits_should_be_invalid(self):
        name='Georgi'
        age= 21
        egn = '12345678901'
        form = ProfileForm(data={
            'name':name,
            'age':age,
            'egn':egn,
        })

        self.assertFalse(form.is_valid())
コード例 #5
0
def index(request):
    if request.method == 'GET':
        profiles = Profile.objects.all()
        form = ProfileForm()

        context = {'profiles': profiles, 'form': form}
        return render(request, 'testing/index.html', context)
    else:
        form = ProfileForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('profiles')

        profiles = Profile.objects.all()
        context = {'profiles': profiles, 'form': form}

        return render(request, 'testing/index.html', context)