Exemplo n.º 1
0
 def test_upload_form_both(self):   
     image_test_url = 'https://upload.wikimedia.org/wikipedia/commons/e/e0/JPEG_example_JPG_RIP_050.jpg'
     with open("media/images/test/Slowpoke.jpeg", "rb") as image_test_file:
         form_data = {'url_file':image_test_url}
         form_files = {'upload_file':File(image_test_file)}
         form = ImageUploadForm(data=form_data, files=form_files)
         self.assertFalse(form.is_valid()) 
Exemplo n.º 2
0
def upload(request, gallery_uuid=None):
    context = {}
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            # fill some stuff
            if not gallery_uuid:
                gallery = request.user.galleries.get(title="Default")
            else:
                galleries = Gallery.objects.notdefault(user=request.user)
                gallery = get_object_or_404(galleries, uuid=gallery_uuid)

            obj = form.save(commit=False)
            obj.gallery = gallery
            obj.user = request.user
            obj.save()
            form.save_m2m()  # fix for missing tags
            return redirect("upload_success", obj_uuid=obj.uuid)
    else:
        form = ImageUploadForm()

    context['form'] = form
    return render(request, "upload.html", context)
Exemplo n.º 3
0
 def test_upload_form_url(self):   
     image_test_url = 'https://upload.wikimedia.org/wikipedia/commons/e/e0/JPEG_example_JPG_RIP_050.jpg'
     form_data = {'url_file':image_test_url}
     form = ImageUploadForm(form_data)
     self.assertTrue(form.is_valid())
Exemplo n.º 4
0
 def test_upload_form_wrong_format(self):
     with open("media/images/test/wrong.txt", "rb") as test_file:
         form = ImageUploadForm(files={'upload_file':File(test_file)})
         self.assertFalse(form.is_valid())
Exemplo n.º 5
0
 def test_upload_form_empty(self):
     form = ImageUploadForm()
     self.assertFalse(form.is_valid())
Exemplo n.º 6
0
 def test_upload_form_file(self):
     with open("media/images/test/Slowpoke.jpeg", "rb") as image_test_file:
         form = ImageUploadForm(files={'upload_file':File(image_test_file)})
         self.assertTrue(form.is_valid())