Ejemplo n.º 1
0
 def test_valid_file_upload(self):
     filename = self.get_random_string()
     f = self.create_file(filename=filename)
     request = self.request_factory.post('/', {'file': f})
     request.is_ajax = True
     form = ProjectImageForm(request.POST, request.FILES)
     if form.is_valid():
         instance = form.save()
         self.assertEqual(instance.get_filename(), filename)
     else:
         self.fail('Form should be valid')
Ejemplo n.º 2
0
 def test_valid_file_upload(self):
     filename = self.get_random_string()
     f = self.create_file(filename=filename)
     request = self.request_factory.post('/', {'file': f})
     request.is_ajax = True
     form = ProjectImageForm(request.POST, request.FILES)
     if form.is_valid():
         instance = form.save()
         self.assertEqual(instance.get_filename(), filename)
     else:
         self.fail('Form should be valid')
Ejemplo n.º 3
0
def gallery_image_create(request, project_slug=None, project_step_number=None):
    project_step = None
    if project_slug and project_step_number:
        project = get_object_or_404(Project, slug=project_slug)
        project_step = get_object_or_404(ProjectStep,
                                         project=project,
                                         _order=project_step_number)
        if not project.is_editable(request):
            return HttpResponseForbidden(
                'You are not the owner of this project.')
    form = ProjectImageForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        image = form.save()
        if project_step is not None:
            project_step.gallery.add(image)
        return AjaxResponse(request, ProjectImage.serialize(image))
    # A post was made without any files, just return False
    return AjaxResponse(request, False)
Ejemplo n.º 4
0
def gallery_image_create(request, project_slug=None, project_step_number=None):
    project_step = None
    if project_slug and project_step_number:
        project = get_object_or_404(Project, slug=project_slug)
        project_step = get_object_or_404(
            ProjectStep, project=project, _order=project_step_number
        )
        if not project.is_editable(request):
            return HttpResponseForbidden(
                'You are not the owner of this project.'
            )
    form = ProjectImageForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        image = form.save()
        if project_step is not None:
            project_step.gallery.add(image)
        return AjaxResponse(request, ProjectImage.serialize(image))
    # A post was made without any files, just return False
    return AjaxResponse(request, False)
Ejemplo n.º 5
0
 def test_no_file(self):
     request = self.request_factory.post('/', {})
     request.is_ajax = True
     form = ProjectImageForm(request.POST or None, request.FILES or None)
     self.assertFalse(form.is_valid())
Ejemplo n.º 6
0
 def test_invalid_upload(self):
     request = self.request_factory.post('/', {'filez': self.create_file()})
     request.is_ajax = True
     form = ProjectImageForm(request.POST or None, request.FILES or None)
     self.assertFalse(form.is_valid())
Ejemplo n.º 7
0
 def test_no_file(self):
     request = self.request_factory.post('/', {})
     request.is_ajax = True
     form = ProjectImageForm(request.POST or None, request.FILES or None)
     self.assertFalse(form.is_valid())
Ejemplo n.º 8
0
 def test_invalid_upload(self):
     request = self.request_factory.post('/', {'filez': self.create_file()})
     request.is_ajax = True
     form = ProjectImageForm(request.POST or None, request.FILES or None)
     self.assertFalse(form.is_valid())