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())
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())
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())
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())
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)