-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
F/#87 create assignment form
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from vmc_backend.core.base_model_form import BaseModelForm | ||
from vmc_backend.models import Assignment | ||
|
||
|
||
class AssignmentForm(BaseModelForm): | ||
class Meta: | ||
model = Assignment | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.forms.models import model_to_dict | ||
|
||
from vmc_backend.forms.assignment_form import AssignmentForm | ||
from vmc_backend.tests.base_model_form_test_case import BaseModelFormTestCase | ||
from vmc_backend.factories import (AssignmentFactory, SubjectFactory) | ||
|
||
|
||
class TestAssignmentForm(BaseModelFormTestCase): | ||
def test_subject_exists(self): | ||
subject = SubjectFactory() | ||
assignment = AssignmentFactory.build(subject=subject) | ||
subject.delete() | ||
form = AssignmentForm(model_to_dict(assignment)) | ||
self.assertFalse(form.is_valid()) | ||
self.assertTrue(('subject') in form.errors.keys()) | ||
|
||
def test_working_for_correct_data(self): | ||
subject = SubjectFactory() | ||
assignment = AssignmentFactory.build(subject=subject) | ||
form = AssignmentForm(model_to_dict(assignment)) | ||
form.full_clean() | ||
self.assertTrue(form.is_valid()) |