Commits

Melissa Garza committed d8a0487

Finished modelsetmixin test cases

Comments (0)

Files changed (5)

testsite/templates/model_form.html

     {% if form %}
     <form method="post" action="">{% csrf_token %}
         {{ form }}
+        {% for formset in formsets %}
+            {{ formset }}
+        {% endfor %}
         <input type="submit" value="Submit" />
     </form>
     {% endif %}

testsite/testapp/forms.py

 
     class Meta:
         model = Book
-        fields = ('author', 'title', 'published',)
+        fields = ('author', 'title',)
 
 
-BookFormSet = inlineformset_factory(Author, Book)
+BookFormSet = inlineformset_factory(Author, Book, extra=1, can_delete=False)

testsite/testapp/models.py

 
 
 class Author(models.Model):
-    user = models.ForeignKey(User)
+    user = models.ForeignKey(User, default=1)
     name = models.CharField(max_length=100, default='Name')
     created = models.DateTimeField(default=datetime.now())
     active = models.BooleanField(default=True)
     author = models.ForeignKey(Author)
     title = models.CharField(max_length=100, default='Title')
     created = models.DateTimeField(default=datetime.now())
-    published = models.BooleanField(default=True)
 
     def __unicode__(self):
         return self.title

testsite/testapp/tests.py

 class ModelFormSetMixinTestCase(TestCase):
 
     def setUp(self):
-        self.user = User.objects.create_user('john', 'john@foo.com', '123')
+        self.user = User.objects.create_user('john', 'john@foo.com', '123', pk=1)
+        self.author = Author.objects.create(user=self.user)
         self.client = Client()
 
     def test_model_form_set_get(self):
 
     def test_model_form_set_post(self):
         field_info = {
-            'name': 'john',
+            'name': 'John',
+            'book_set-TOTAL_FORMS': 1,
+            'book_set-INITIAL_FORMS': 0,
+            'book_set-MAX_NUM_FORMS': 1000,
+            'book_set-0-title': 'Title',
+            'book_set-0-created': datetime.now(),
         }
         url = reverse('model_form_set')
         response = self.client.post(url, field_info)
-        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.status_code, 302)
 
 
 class ObjectOwnerMixinTestCase(TestCase):

testsite/testapp/views.py

 from django.views.generic import CreateView, DeleteView, DetailView, ListView, TemplateView, UpdateView
 from forms import AuthorForm, BookForm, BookFormSet
 from models import Author, Book
-from viewclass_mixins.views import DeactivateMixin, FilteredListMixin, HttpCacheMixin, LoginMixin, ModelFormSetMixin,\
-    ObjectOwnerMixin, OwnershipMixin, StaffRequiredMixin, SuperuserRequiredMixin
+from viewclass_mixins.views import *
 
 
 class SuccessView(TemplateView):
 
 class DeactivateView(DeactivateMixin, DeleteView):
     model = Author
+    template_name = 'home.html'
     success_url = reverse_lazy('success')
-    template_name = 'home.html'
 
 
 class FilteredListView(FilteredListMixin, ListView):
     model = Author
-    template_name = "home.html"
+    template_name = 'home.html'
 
 
 class HttpCacheView(HttpCacheMixin, TemplateView):
-    template_name = "home.html"
+    template_name = 'home.html'
 
 
 class LoginView(LoginMixin, TemplateView):
-    template_name = "home.html"
+    template_name = 'home.html'
 
 
 class ModelFormSetView(ModelFormSetMixin, CreateView):
     model = Author
     form_class = AuthorForm
     formset_classes = [BookFormSet]
-    template_name = "model_form.html"
+    template_name = 'model_form.html'
+    success_url = reverse_lazy('success')
 
 
 class ObjectOwnerView(ObjectOwnerMixin, UpdateView):
     model = Author
     owner_model = Author
     owner_field = 'user'
-    template_name = "home.html"
+    template_name = 'home.html'
 
 
 class OwnershipView(OwnershipMixin, DetailView):
     model = Author
-    template_name = "home.html"
+    template_name = 'home.html'
 
 
 class StaffRequiredView(StaffRequiredMixin, TemplateView):
-    template_name = "home.html"
+    template_name = 'home.html'
 
 
 class SuperuserRequiredView(SuperuserRequiredMixin, TemplateView):
-    template_name = "home.html"
+    template_name = 'home.html'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.