Skip to content

Commit

Permalink
Adds test_form_upload_file
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanphix committed Sep 3, 2012
1 parent 654c5d1 commit b8621ff
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
25 changes: 24 additions & 1 deletion resumable/tests/app.py
@@ -1,9 +1,32 @@
# -*- coding: utf-8 -*-
from django.conf import settings
from django.conf.urls import patterns, url
from django.views.generic.edit import FormView
from django.forms import Form
from django.core.urlresolvers import reverse

from resumable.views import ResumableUploadView
from resumable.fields import ResumableFileField


class ResumableForm(Form):
file = ResumableFileField(
allowed_mimes=("audio/ogg",),
upload_url=lambda: reverse('upload'),
chunks_dir=getattr(settings, 'FILE_UPLOAD_TEMP_DIR')
)


class TestFormView(FormView):
form_class = ResumableForm
template_name = 'form.html'

@property
def success_url(self):
return reverse('form')


urlpatterns = patterns('',
url('upload/', ResumableUploadView.as_view(), name='upload')
url('^$', TestFormView.as_view(), name='form'),
url('^upload/$', ResumableUploadView.as_view(), name='upload')
)
12 changes: 12 additions & 0 deletions resumable/tests/templates/form.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<body>
<form method="post" action=".">
<fieldset>
{% csrf_token %}
{{ form.as_p }}
</fieldset>
<p><input type="submit" value="send" /></p>
</form>
</body>
</html>
25 changes: 11 additions & 14 deletions resumable/tests/tests.py
Expand Up @@ -10,16 +10,19 @@
from django.core.files.storage import FileSystemStorage
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.forms import Form

from resumable.files import ResumableFile
from resumable.fields import ResumableFileField

from .app import ResumableForm


TESTS_ROOT = os.path.dirname(__file__)


CHUNKS_ROOT = os.path.join(TESTS_ROOT, 'fixtures', 'files', 'chunks')
FIXTURES_ROOT = os.path.join(TESTS_ROOT, 'fixtures', 'files')


CHUNKS_ROOT = os.path.join(FIXTURES_ROOT, 'chunks')


seagull = {
Expand Down Expand Up @@ -56,17 +59,6 @@ def tearDown(self):
self.storage.delete(filename)


class ResumableForm(Form):
file = ResumableFileField(
allowed_mimes=("audio/ogg",),
upload_url=reverse('upload'),
chunks_dir=getattr(settings, 'FILE_UPLOAD_TEMP_DIR')
)

def __init__(self, *args, **kwargs):
super(ResumableForm, self).__init__(*args, **kwargs)


class ResumableFileFieldTest(BaseTestCase):
def test_clean_invalid_mime(self):
form = ResumableForm()
Expand All @@ -86,6 +78,11 @@ def test_clean_valid_mime(self):
)
self.assertEqual(f, form.fields.get('file').clean(None, f))

def test_form_upload_file(self):
r = self.client.post(reverse('form'), {'file': open(os.path.join(
FIXTURES_ROOT, '147292_seagull.ogg'))})
self.assertEqual(r.status_code, 302)


class ResumableFileTest(BaseTestCase):
def test_chunks(self):
Expand Down

0 comments on commit b8621ff

Please sign in to comment.