Beispiel #1
0
    def post(self, request):
        project_form = ProjectCreationForm(request.user, data=request.POST)
        allocation_form = SystemAllocationRequestCreationForm(
            request.user,
            include_project=False,
            data=request.POST,
            files=request.FILES)

        if project_form.is_valid() and allocation_form.is_valid():
            project = project_form.save()

            allocation = allocation_form.save(commit=False)
            allocation.project = project

            allocation.save()
            institution = project.tech_lead.profile.institution
            if institution.needs_supervisor_approval:
                supervisor_project_created_notification.delay(project)

            messages.success(self.request, self.success_message)
            return HttpResponseRedirect(reverse('project-membership-list'))

        return self.render_to_response(
            self.get_context_data(project_form=project_form,
                                  allocation_form=allocation_form))
Beispiel #2
0
 def test_project_allocation_form_other_project(self):
     self.project = Project.objects.get(code='scw0001')
     self.data['project'] = self.project.id
     self.form = SystemAllocationRequestCreationForm(
         self.user, project=self.project, data=self.data
     )
     self.assertFalse(self.form.is_valid())
Beispiel #3
0
class AllocationRequestFormTests(TestCase):

    fixtures = [
        'institution/fixtures/tests/institutions.json',
        'users/fixtures/tests/users.json',
        'funding/fixtures/tests/funding_bodies.json',
        'funding/fixtures/tests/attributions.json',
        'project/fixtures/tests/categories.json',
        'project/fixtures/tests/projects.json',
        'project/fixtures/tests/memberships.json',
    ]

    def setUp(self):
        self.title = "Example project title"
        # Create users for each institution
        self.institution_names, self.institution_users = CustomUserTests.create_institutional_users()

        self.project_code = 'scw0000'
        self.project = Project.objects.get(code=self.project_code)
        self.user = self.project.tech_lead
        self.data = {
            'information': 'A test allocation',
            'start_date': '01/09/1985',
            'end_date': '01/09/1985',
            'allocation_cputime': '5',
            'allocation_memory': '1',
            'allocation_storage_home': '23',
            'allocation_storage_scratch': '65',
            'requirements_software': '',
            'requirements_training': '',
            'requirements_onboarding': '',
            'document': None,
            'attributions': [],
            'project': self.project.id,
        }

    def test_project_allocation_form_arcca_field(self):
        for i in self.institution_names:
            user = self.institution_users[i]
            form = SystemAllocationRequestCreationForm(user)
            if user.profile.institution.base_domain == 'cardiff.ac.uk':
                self.assertTrue('legacy_arcca_id' in form.fields)
            else:
                self.assertFalse('legacy_arcca_id' in form.fields)

    def test_project_allocation_form_validation(self):
        self.form = SystemAllocationRequestCreationForm(self.user, data=self.data)
        self.assertTrue( self.form.is_valid() )

    def test_project_allocation_form_without_project(self):
        self.form = SystemAllocationRequestCreationForm(self.user, include_project=False, data=self.data)
        self.assertFalse( 'project' in self.form.fields )

    def test_project_allocation_form_other_project(self):
        self.project = Project.objects.get(code='scw0001')
        self.data['project'] = self.project.id
        self.form = SystemAllocationRequestCreationForm(self.user, project=self.project, data=self.data)
        self.assertFalse( self.form.is_valid() )
Beispiel #4
0
 def test_project_allocation_form_arcca_field(self):
     for i in self.institution_names:
         user = self.institution_users[i]
         form = SystemAllocationRequestCreationForm(user)
         if user.profile.institution.base_domain == 'cardiff.ac.uk':
             self.assertTrue('legacy_arcca_id' in form.fields)
         else:
             self.assertFalse('legacy_arcca_id' in form.fields)
Beispiel #5
0
 def test_form_with_unauthorized_project(self):
     """
     Ensure it is not possible to create a project user membership whilst the project is
     currently awaiting approval.
     """
     form = SystemAllocationRequestCreationForm(
         self.project_applicant,
         data={
             'project': 1,
             'information': '',
             'start_date': datetime.datetime.now(),
             'end_date': datetime.datetime.now(),
             'allocation_cputime': 1,
             'allocation_memory': 1,
             'allocation_storage_home': 1,
             'allocation_storage_scratch': 1,
             'requirements_software': '',
             'requirements_training': '',
             'requirements_onboarding': '',
             'document': '',
         },
     )
     self.assertFalse(form.is_valid())
Beispiel #6
0
    def get_context_data(self, **kwargs):
        context = super(ProjectAndAllocationCreateView,
                        self).get_context_data(**kwargs)

        if 'project_form' in kwargs:
            context['project_form'] = kwargs['project_form']
        else:
            context['project_form'] = ProjectCreationForm(self.request.user)
        if 'allocation_form' in kwargs:
            context['allocation_form'] = kwargs['allocation_form']
        else:
            context['allocation_form'] = SystemAllocationRequestCreationForm(
                self.request.user)
            # These two fields are unnecessary in the combined view
            del context['allocation_form'].fields['information']
            del context['allocation_form'].fields['project']

        return context
Beispiel #7
0
 def test_project_allocation_form_without_project(self):
     self.form = SystemAllocationRequestCreationForm(
         self.user, include_project=False, data=self.data
     )
     self.assertFalse('project' in self.form.fields)
Beispiel #8
0
 def test_project_allocation_form_validation(self):
     self.form = SystemAllocationRequestCreationForm(
         self.user, data=self.data
     )
     self.assertTrue(self.form.is_valid())