0001-utils-fix-make_url-use-by-list_to_pick-view-fixes-22.patch
fargo/utils.py | ||
---|---|---|
2 | 2 |
from django.utils.http import urlencode |
3 | 3 | |
4 | 4 | |
5 |
def make_url(url, **kwargs): |
|
5 |
def make_url(__url, **kwargs):
|
|
6 | 6 |
request = kwargs.pop('request', None) |
7 |
parsed = urlparse.urlparse(url) |
|
7 |
parsed = urlparse.urlparse(__url)
|
|
8 | 8 |
query = urlparse.parse_qs(parsed.query) |
9 | 9 |
for key, value in kwargs.iteritems(): |
10 | 10 |
if value is not None: |
tests/conftest.py | ||
---|---|---|
1 | 1 |
import logging |
2 | 2 |
import pytest |
3 | 3 |
import django_webtest |
4 | ||
5 |
from django.core.files.base import ContentFile |
|
4 | 6 |
from django.contrib.auth.models import User |
5 | 7 | |
8 |
from fargo.fargo.models import UserDocument, Document |
|
9 | ||
6 | 10 | |
7 | 11 |
class WebTestMixin(django_webtest.WebTestMixin): |
8 | 12 |
csrf_checks = False |
9 | 13 | |
14 | ||
10 | 15 |
@pytest.fixture |
11 | 16 |
def app(request): |
12 | 17 |
wtm = WebTestMixin() |
... | ... | |
80 | 85 |
user = User.objects.create_superuser('admin', email=None, password='admin') |
81 | 86 |
return user |
82 | 87 | |
88 | ||
89 |
@pytest.fixture |
|
90 |
def document(): |
|
91 |
with open('tests/test_oauth2.txt', 'rb') as f: |
|
92 |
content = ContentFile(f.read(), 'test_oauth2.txt') |
|
93 | ||
94 |
return Document.objects.get_by_file(content) |
|
95 | ||
96 | ||
97 |
@pytest.fixture |
|
98 |
def user_doc(document, john_doe): |
|
99 |
return UserDocument.objects.create(user=john_doe, document=document, filename='Baudelaire.txt') |
|
100 | ||
101 |
tests/test_oauth2.py | ||
---|---|---|
4 | 4 |
from urllib import quote |
5 | 5 |
import urlparse |
6 | 6 | |
7 |
from django.core.files.base import ContentFile |
|
8 | 7 |
from django.core.urlresolvers import reverse |
9 | 8 |
from django.utils.http import urlencode |
10 | 9 | |
11 | 10 |
from fargo.oauth2.models import OAuth2Client, OAuth2Authorize, OAuth2TempFile |
12 |
from fargo.fargo.models import Document, UserDocument
|
|
11 |
from fargo.fargo.models import UserDocument |
|
13 | 12 | |
14 | 13 |
from test_manager import login |
15 | 14 | |
... | ... | |
29 | 28 |
redirect_uris='https://example.net/document https://doc.example.net/ https://example.com') |
30 | 29 | |
31 | 30 | |
32 |
@pytest.fixture |
|
33 |
def document(): |
|
34 |
with open('tests/test_oauth2.txt', 'rb') as f: |
|
35 |
content = ContentFile(f.read(), 'test_oauth2.txt') |
|
36 | ||
37 |
return Document.objects.get_by_file(content) |
|
38 | ||
39 | ||
40 |
@pytest.fixture |
|
41 |
def user_doc(document, john_doe): |
|
42 |
return UserDocument.objects.create(user=john_doe, document=document, filename='Baudelaire.txt') |
|
43 | ||
44 | ||
45 | 31 |
def assert_error_redirect(url, error): |
46 | 32 |
assert urlparse.urlparse(url).query == 'error=%s' % error |
47 | 33 |
tests/test_public.py | ||
---|---|---|
4 | 4 |
import pytest |
5 | 5 |
import urlparse |
6 | 6 | |
7 |
from django.core.urlresolvers import reverse |
|
8 | ||
7 | 9 |
try: |
8 | 10 |
import magic |
9 | 11 |
except ImportError: |
... | ... | |
71 | 73 |
response2 = form.submit() |
72 | 74 |
assert response2.status_code == 200 |
73 | 75 |
assert 'Your document box is full (limit is 4)' in response2.content |
76 | ||
77 | ||
78 |
def test_pick(app, private_settings, john_doe, user_doc): |
|
79 |
login(app, user=john_doe) |
|
80 | ||
81 |
return_url = 'http://client.org/callback/' |
|
82 |
response = app.get(reverse('list_to_pick') + '?pick=' + return_url) |
|
83 |
response = response.forms[0].submit('Pick') |
|
84 |
assert response['Location'].startswith(return_url) |
|
85 |
assert '?url=' in response['Location'] |
|
74 |
- |