Last active
February 27, 2016 18:57
-
-
Save mekhami/f6b99e9e7f3e96349f42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class ServiceTypeForm(forms.ModelForm): | |
| class Meta: | |
| model = Service | |
| fields = ['name', 'service_type'] | |
| def __init__(self, *args, **kwargs): | |
| self.project = kwargs.pop('project') | |
| super(ServiceTypeForm, self).__init__(*args, **kwargs) | |
| def save(self): | |
| service = super(ServiceTypeForm, self).save(commit=False) | |
| service.project = self.project | |
| service.save() | |
| return service |
This file contains hidden or 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
| {'service_type': [ValidationError([u'Select a valid choice. That choice is not one of the available choices.'])]} |
This file contains hidden or 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
| class ServiceTypeFormTest(TestCase): | |
| def setUp(self): | |
| self.project = Project.objects.create(name='google') | |
| self.service_type = ServiceType.objects.create(name='database', slug='database', template='{{ template }}') | |
| def test_form_save(self): | |
| form = ServiceTypeForm({ | |
| 'name': 'googledb', | |
| 'service_type': self.service_type, | |
| }, project=self.project) | |
| self.assertTrue(form.is_valid()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment