def test_local_upload_view_registered_user_get_request(self): user = User.objects.create_user(username='******', password='******') request = RequestFactory().get('/localscan/') request.user = user response = LocalUploadView.as_view()(request) self.assertEqual(200, response.status_code)
def test_local_upload_view_registered_user_post_request_redirects(self): user = User.objects.create_user(username='******', password='******') request = RequestFactory().post( '/localscan/', {'upload_from_local': File(open('manage.py', 'r'))}) request.user = user response = LocalUploadView.as_view()(request) self.assertEqual(302, response.status_code)
from django.conf.urls import url from django.views.generic import TemplateView # import views from scanapp/views.py from scanapp.views import LocalUploadView from scanapp.views import URLFormViewCelery from scanapp.views import ScanResults urlpatterns = [ url(r'^index/', TemplateView.as_view(template_name="scanapp/index.html")), url(r'^localscan/', LocalUploadView.as_view(), name='localuploadview'), url(r'^urlscan/', URLFormViewCelery.as_view(), name='urlceleryformview'), url(r'^resultscan/(?P<pk>[0-9]+)', ScanResults.as_view(), name='resultview'), ]
def test_local_upload_view_anonymous_user_post_request_redirects(self): request = RequestFactory().post( '/localscan/', {'upload_from_local': File(open('manage.py', 'r'))}) request.user = AnonymousUser() response = LocalUploadView.as_view()(request) self.assertEqual(302, response.status_code)
def test_local_form_view_anonymous_user_get_request(self): request = RequestFactory().get('/localscan/') request.user = AnonymousUser() response = LocalUploadView.as_view()(request) self.assertEqual(200, response.status_code)
def test_local_upload_view_anonymous_user_blank_post_request(self): request = RequestFactory().post('/localscan/') request.user = AnonymousUser() response = LocalUploadView.as_view()(request) self.assertIsNone(response)