def test_allocationrequest_create(self): with ContentFile(b'content', name='plain.txt') as fp: request = RequestFactory().post( '/projects/{}/allocationrequests/create'.format(self.proj.pk), data={ 'abstract': 'test abstract', 'funding': 'test funding', 'proposal': fp, 'time_requested': '1234', 'disk_space': '1234', 'software_request': 'none', } ) request.user = self.user view = AllocationRequestCreateView.as_view() response = view(request) self.assertTrue(response.url.startswith('/projects/list/{}/allocationrequests/'.format(self.proj.pk))) ar = AllocationRequest.objects.get() self.assertEquals(ar.project.project_id,self.proj.project_id) self.assertEquals(ar.abstract,'test abstract') self.assertEquals(ar.funding,'test funding') path_cmps = ar.proposal.name.split('/') self.assertEquals(len(path_cmps),5) self.assertEquals(path_cmps[-1][-3:],'txt') self.assertEquals(ar.time_requested,1234) self.assertEquals(ar.disk_space,1234) self.assertEquals(ar.software_request,'none')
def test_allocationrequest_create_missing_fields(self): request = RequestFactory().post( '/projects/list/{}/allocationrequests/create'.format(self.proj.pk), data={} ) request.user = self.user view = AllocationRequestCreateView.as_view() response = view(request) self.assertEquals( response.context_data['form'].errors['abstract'], [u'This field is required.'] ) self.assertEquals( response.context_data['form'].errors['funding'], [u'This field is required.'] ) self.assertEquals( response.context_data['form'].errors['proposal'], [u'This field is required.'] ) self.assertEquals( response.context_data['form'].errors['time_requested'], [u'This field is required.'] )
from django.conf.urls import include, url from django.contrib.auth.decorators import login_required from projects.views import ProjectListView from projects.views import ProjectDetailView from projects.views import ProjectEditView from projects.views import ProjectCreateView from projects.views import ReferenceDetailView from projects.views import ReferenceEditView from projects.views import ReferenceCreateView from projects.views import AllocationRequestDetailView from projects.views import AllocationRequestCreateView urlpatterns = [ url(r'^list$', login_required(ProjectListView.as_view()), name='project-list'), url(r'^list/(?P<pk>[-\w]+)/$', login_required(ProjectDetailView.as_view()), name='project-detail'), url(r'^list/(?P<pk>[-\w]+)/edit$', login_required(ProjectEditView.as_view()), name='project-edit'), url(r'^create$', login_required(ProjectCreateView.as_view()), name='project-create'), url(r'^list/(?P<project_pk>[-\w]+)/references/(?P<pk>[-\w]+)/$', login_required(ReferenceDetailView.as_view()), name='reference-detail'), url(r'^list/(?P<project_pk>[-\w]+)/references/(?P<pk>[-\w]+)/edit$', login_required(ReferenceEditView.as_view()), name='reference-edit'), url(r'^list/(?P<project_pk>[-\w]+)/references/create$', login_required(ReferenceCreateView.as_view()), name='reference-create'), url(r'^list/(?P<project_pk>[-\w]+)/allocationrequests/(?P<pk>[-\w]+)/$', login_required(AllocationRequestDetailView.as_view()), name='allocation-request-detail'), url(r'^list/(?P<project_pk>[-\w]+)/allocationrequests/create$', login_required(AllocationRequestCreateView.as_view()), name='allocation-request-create'), ]