Commits

sammyrulez committed b061702

delete support.. 99% coverage

  • Participants
  • Parent commits 7d5a246

Comments (0)

Files changed (5)

File uiforms/tmanager/fixtures/test_data_fixtures.json

 [
-  {
-    "pk": 1, 
-    "model": "tmanager.formtemplate", 
-    "fields": {
-      "owner": 1, 
-      "name": "TestForm"
-    }
-  }, 
-  {
-    "pk": 1, 
-    "model": "tmanager.templatefield", 
-    "fields": {
-      "filed_type": "BOOLEAN", 
-      "template": 1, 
-      "label": "is_it_cool?"
-    }
-  }, 
-  {
-    "pk": 2, 
-    "model": "tmanager.templatefield", 
-    "fields": {
-      "filed_type": "INTEGER", 
-      "template": 1, 
-      "label": "How_old_are_U?"
-    }
-  }, 
-  {
-    "pk": 1, 
-    "model": "tmanager.templatedata", 
-    "fields": {
-      "submitted_by": 1, 
-      "template_ref": 1, 
-      "modified": "2011-12-22 08:22:05", 
-      "created": "2011-12-22 08:22:05"
-    }
-  }, 
-  {
-    "pk": 1, 
-    "model": "tmanager.templatedatarow", 
-    "fields": {
-      "template_data": 1, 
-      "template_field": 1, 
-      "payload": "True"
-    }
-  }, 
-  {
-    "pk": 2, 
-    "model": "tmanager.templatedatarow", 
-    "fields": {
-      "template_data": 1, 
-      "template_field": 2, 
-      "payload": "19"
-    }
+ {
+  "pk": 1, 
+  "model": "tmanager.formtemplate", 
+  "fields": {
+   "owner": 1, 
+   "name": "TestForm"
   }
+ }, 
+ {
+  "pk": 1, 
+  "model": "tmanager.templatefield", 
+  "fields": {
+   "filed_type": "BOOLEAN", 
+   "template": 1, 
+   "label": "is_it_cool?"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "tmanager.templatefield", 
+  "fields": {
+   "filed_type": "INTEGER", 
+   "template": 1, 
+   "label": "How_old_are_U?"
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "tmanager.templatedata", 
+  "fields": {
+   "submitted_by": 1, 
+   "template_ref": 1, 
+   "modified": "2011-12-22 08:22:05", 
+   "created": "2011-12-22 08:22:05"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "tmanager.templatedata", 
+  "fields": {
+   "submitted_by": 2, 
+   "template_ref": 1, 
+   "modified": "2011-12-29 04:42:50", 
+   "created": "2011-12-29 04:42:50"
+  }
+ }, 
+ {
+  "pk": 1, 
+  "model": "tmanager.templatedatarow", 
+  "fields": {
+   "template_data": 1, 
+   "template_field": 1, 
+   "payload": "True"
+  }
+ }, 
+ {
+  "pk": 2, 
+  "model": "tmanager.templatedatarow", 
+  "fields": {
+   "template_data": 1, 
+   "template_field": 2, 
+   "payload": "19"
+  }
+ }, 
+ {
+  "pk": 3, 
+  "model": "tmanager.templatedatarow", 
+  "fields": {
+   "template_data": 2, 
+   "template_field": 1, 
+   "payload": "True"
+  }
+ }, 
+ {
+  "pk": 4, 
+  "model": "tmanager.templatedatarow", 
+  "fields": {
+   "template_data": 2, 
+   "template_field": 2, 
+   "payload": "12"
+  }
+ }
 ]

File uiforms/tmanager/fixtures/user_fixtures.json

    "groups": [], 
    "user_permissions": [], 
    "password": "sha1$6f3a4$06b85772223419ccb3e1e72a300a394e7c700c39", 
-   "email": "", 
+   "email": "b@li.it", 
    "date_joined": "2011-12-20 07:35:20"
   }
  }

File uiforms/tmanager/tests.py

             else:
                 ok_params[f.label] = 1
         return ok_params
+		
 
     def check_fieds_in_output(self, ft, content):
         for f in ft.templatefield_set.all():
             self.assertTrue(content.count(f.label) > 0)
+			
+    def test_home_r(self):
+        response = self.client.get(urlresolvers.reverse('home'))
+        self.assertEquals(302, response.status_code)
 
 
     def test_uiform(self):
         response = self.client.get(urlresolvers.reverse('detail', args=[1]))
         self.assertEquals(200, response.status_code)
         response = self.client.get(urlresolvers.reverse('detail', args=[2])) # not ownig
-        self.assertEquals(404, response.status_code)
+        self.assertEquals(200, response.status_code)
         response = self.client.get(urlresolvers.reverse('detail', args=[1989])) #non existing
         self.assertEquals(404, response.status_code)
 
         self.assertEquals(200, response.status_code)
 
     #TODO Check not owned
+	
+    def test_delete_data(self):
+		td = TemplateData()
+		ft = FormTemplate.objects.get(pk=1)
+		td.template_ref = ft
+		td.submitted_by = User.objects.get(pk=2)
+		td.save()
+		response = self.client.post(urlresolvers.reverse('delete_data',args=[td.id]))
+		self.assertEquals(302, response.status_code)
 		
 		
 	

File uiforms/tmanager/views.py

             context['back_url'] = urlresolvers.reverse('submitted_data')
         else:
             context['title'] = 'Owned Data'
-            context['back_url'] = urlresolvers.resolve('owned_data')
+            context['back_url'] = urlresolvers.reverse('owned_data')
 
         return context
 
     template_name = "admin/tmanager/confirm_delete.html"
     model = TemplateData
 
-    def get_success_url(self, obj):
-        if obj.submitted_by == self.request.user:
-            return urlresolvers.resolve('submitted_data')
+    def get_success_url(self):
+        if self.object.submitted_by == self.request.user:
+            return urlresolvers.reverse('submitted_data')
         else:
-            return urlresolvers.resolve('owned_data')
+            return urlresolvers.reverse('owned_data')
 
     @method_decorator(login_required)
     def dispatch(self, *args, **kwargs):
-        return super(SubmittedDataView, self).dispatch(*args, **kwargs)
+        return super(DeleteDataView, self).dispatch(*args, **kwargs)
 		
 	
 	

File uiforms/urls.py

 from django.conf.urls.defaults import patterns, include, url
-from uiforms.tmanager.views import DataDetailView ,OwnedDataView , SubmittedDataView
+from uiforms.tmanager.views import DataDetailView ,OwnedDataView , SubmittedDataView , DeleteDataView
 
 from django.views.generic import DetailView , ListView
 from uiforms.tmanager.models import FormTemplate , TemplateField ,TemplateData 
 	url(r'^data_owned/$',OwnedDataView.as_view(),name='owned_data'),
 	url(r'^data_submitted/$',SubmittedDataView.as_view(),name='submitted_data'),
 	url(r'^data_detail/(?P<pk>\d+)/$',DataDetailView.as_view(),name='detail'),
+	url(r'^data_delete/(?P<pk>\d+)/$',DeleteDataView.as_view(),name='delete_data'),