tests: update redirect location checks for django 1.11 (#20935)
This commit is contained in:
parent
754cf3292e
commit
75968b27b6
|
@ -48,7 +48,7 @@ def test_add_regie(app, admin_user):
|
|||
resp.forms[0]['service'] = 'dummy'
|
||||
assert resp.form['is_default'].checked is True
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/lingo/regies/'
|
||||
assert resp.location.endswith('/manage/lingo/regies/')
|
||||
assert Regie.objects.count() == 1
|
||||
regie = Regie.objects.all()[0]
|
||||
assert regie.label == 'Test'
|
||||
|
@ -61,7 +61,7 @@ def test_edit_regie(app, admin_user):
|
|||
resp = resp.click('Test')
|
||||
resp.forms[0]['description'] = 'other description'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/lingo/regies/'
|
||||
assert resp.location.endswith('/manage/lingo/regies/')
|
||||
assert Regie.objects.count() == 1
|
||||
regie = Regie.objects.all()[0]
|
||||
assert regie.description == 'other description'
|
||||
|
@ -74,7 +74,7 @@ def test_delete_regie(app, admin_user):
|
|||
resp = resp.click('Delete')
|
||||
assert 'Are you sure you want to delete this?' in resp.body
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/lingo/regies/'
|
||||
assert resp.location.endswith('/manage/lingo/regies/')
|
||||
assert Regie.objects.count() == 0
|
||||
|
||||
def test_add_second_regie(app, admin_user):
|
||||
|
@ -90,7 +90,7 @@ def test_add_second_regie(app, admin_user):
|
|||
resp.forms[0]['service'] = 'dummy'
|
||||
assert resp.form['is_default'].checked is False
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/lingo/regies/'
|
||||
assert resp.location.endswith('/manage/lingo/regies/')
|
||||
|
||||
assert Regie.objects.count() == 2
|
||||
assert Regie.objects.get(id=regie.id).is_default is True
|
||||
|
|
|
@ -46,7 +46,7 @@ def login(app, username='admin', password='admin'):
|
|||
|
||||
def test_unlogged_access(app):
|
||||
# connect while not being logged in
|
||||
assert app.get('/manage/', status=302).location == 'http://testserver/login/?next=/manage/'
|
||||
assert app.get('/manage/', status=302).location.endswith('/login/?next=/manage/')
|
||||
|
||||
def test_access(app, admin_user):
|
||||
app = login(app)
|
||||
|
@ -60,7 +60,7 @@ def test_add_page(app, admin_user):
|
|||
resp = resp.click('New')
|
||||
assert resp.forms[0]['title'].value == 'Home' # default title for first page
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/pages/1/'
|
||||
assert resp.location.endswith('/manage/pages/1/')
|
||||
assert Page.objects.get(slug='index').title == 'Home'
|
||||
assert Page.objects.get(slug='index').template_name == 'standard' # first one was taken
|
||||
|
||||
|
@ -156,7 +156,7 @@ def test_page_edit_picture(app, admin_user):
|
|||
resp.form['picture'] = Upload('black.jpeg',
|
||||
open(os.path.join(TESTS_DATA_DIR, 'black.jpeg')).read(), 'image/jpeg')
|
||||
resp = resp.form.submit()
|
||||
assert resp.location == 'http://testserver/manage/pages/%s/' % page.id
|
||||
assert resp.location.endswith('/manage/pages/%s/' % page.id)
|
||||
resp = resp.follow()
|
||||
assert '<h2>Page - One</h2>' in resp.body
|
||||
assert '<img' in resp.body
|
||||
|
@ -174,7 +174,7 @@ def test_delete_page(app, admin_user):
|
|||
resp = resp.click('delete')
|
||||
assert '<button class="delete-button">Delete</button>' in resp.body
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/'
|
||||
assert resp.location.endswith('/manage/')
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
def test_delete_page_keep_child(app, admin_user):
|
||||
|
@ -192,7 +192,7 @@ def test_delete_page_keep_child(app, admin_user):
|
|||
|
||||
resp.form['choice'].value = 'delete-one'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/'
|
||||
assert resp.location.endswith('/manage/')
|
||||
assert Page.objects.count() == 1
|
||||
assert Page.objects.get(id=page2.id) == page2
|
||||
|
||||
|
@ -211,7 +211,7 @@ def test_delete_page_and_subpage(app, admin_user):
|
|||
|
||||
resp.form['choice'].value = 'delete-all'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/'
|
||||
assert resp.location.endswith('/manage/')
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
def test_export_page(app, admin_user):
|
||||
|
@ -283,7 +283,7 @@ def test_add_edit_cell(app, admin_user):
|
|||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
# click on first option link, this should add a text cell
|
||||
resp = app.get(resp.html.find('option').get('data-add-url'))
|
||||
assert resp.location == 'http://testserver/manage/pages/1/'
|
||||
assert resp.location.endswith('/manage/pages/1/')
|
||||
|
||||
cells = CellBase.get_cells(page_id=page.id)
|
||||
assert len(cells) == 1
|
||||
|
@ -294,7 +294,7 @@ def test_add_edit_cell(app, admin_user):
|
|||
resp.forms[0]['c%s-text' % cells[0].get_reference()].value = 'Hello world'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.status_int == 302
|
||||
assert resp.location == 'http://testserver/manage/pages/1/'
|
||||
assert resp.location.endswith('/manage/pages/1/')
|
||||
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert resp.forms[0]['c%s-text' % cells[0].get_reference()].value == 'Hello world'
|
||||
|
@ -463,7 +463,7 @@ def test_edit_text_cell(app, admin_user):
|
|||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
data_add_url = [x for x in resp.html.find_all('option') if x.text == 'Text'][0].get('data-add-url')
|
||||
resp = app.get(data_add_url)
|
||||
assert resp.location == 'http://testserver/manage/pages/%s/' % page.id
|
||||
assert resp.location.endswith('/manage/pages/%s/' % page.id)
|
||||
|
||||
cells = CellBase.get_cells(page_id=page.id)
|
||||
assert len(cells) == 1
|
||||
|
@ -500,7 +500,7 @@ def test_edit_config_json_cell(app, admin_user):
|
|||
assert 'Foobar' in options
|
||||
data_add_url = [x for x in resp.html.find_all('option') if x.text == 'Foobar'][0].get('data-add-url')
|
||||
resp = app.get(data_add_url)
|
||||
assert resp.location == 'http://testserver/manage/pages/%s/' % page.id
|
||||
assert resp.location.endswith('/manage/pages/%s/' % page.id)
|
||||
|
||||
cells = CellBase.get_cells(page_id=page.id)
|
||||
assert len(cells) == 1
|
||||
|
@ -541,7 +541,7 @@ def test_edit_config_json_cell(app, admin_user):
|
|||
resp.form['c%s-test3' % cells[0].get_reference()].value = 'Hello again'
|
||||
resp = resp.form.submit()
|
||||
assert resp.status_int == 302
|
||||
assert resp.location == 'http://testserver/manage/pages/%s/' % page.id
|
||||
assert resp.location.endswith('/manage/pages/%s/' % page.id)
|
||||
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert resp.form['c%s-test' % cells[0].get_reference()].value == 'Hello world'
|
||||
|
@ -565,7 +565,7 @@ def test_edit_config_json_cell(app, admin_user):
|
|||
def test_logout(app, admin_user):
|
||||
app = login(app)
|
||||
app.get('/logout/')
|
||||
assert app.get('/manage/', status=302).location == 'http://testserver/login/?next=/manage/'
|
||||
assert app.get('/manage/', status=302).location.endswith('/login/?next=/manage/')
|
||||
|
||||
def test_asset_management(app, admin_user):
|
||||
app = login(app)
|
||||
|
|
|
@ -44,7 +44,7 @@ def test_add_layer(app, admin_user):
|
|||
assert resp.form['icon_colour'].value == '#000000'
|
||||
resp.form['icon_colour'] = '#FFFFFF'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/maps/'
|
||||
assert resp.location.endswith('/manage/maps/')
|
||||
assert MapLayer.objects.count() == 1
|
||||
layer = MapLayer.objects.get()
|
||||
assert layer.label == 'Test'
|
||||
|
@ -57,7 +57,7 @@ def test_edit_layer(app, admin_user):
|
|||
resp = resp.click('Test')
|
||||
resp.forms[0]['geojson_url'] = 'http://example.net/new_geojson'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/maps/'
|
||||
assert resp.location.endswith('/manage/maps/')
|
||||
assert MapLayer.objects.count() == 1
|
||||
layer = MapLayer.objects.get()
|
||||
assert layer.geojson_url == 'http://example.net/new_geojson'
|
||||
|
@ -70,7 +70,7 @@ def test_delete_layer(app, admin_user):
|
|||
resp = resp.click('Delete')
|
||||
assert 'Are you sure you want to delete this?' in resp.body
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://testserver/manage/maps/'
|
||||
assert resp.location.endswith('/manage/maps/')
|
||||
assert MapLayer.objects.count() == 0
|
||||
|
||||
@mock.patch('combo.apps.maps.models.requests.get')
|
||||
|
|
|
@ -6,6 +6,7 @@ import json
|
|||
import pytest
|
||||
import os
|
||||
import urllib
|
||||
from urlparse import urlparse
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
|
@ -30,7 +31,7 @@ def test_index(app):
|
|||
page = Page(title='Home', slug='index', template_name='standard')
|
||||
page.save()
|
||||
resp = app.get('/index', status=301)
|
||||
assert resp.location == 'http://testserver/'
|
||||
assert urlparse(resp.location).path == '/'
|
||||
resp = app.get('/', status=200)
|
||||
|
||||
# check {% now %} inside a skeleton_extra_placeholder is interpreted
|
||||
|
@ -72,7 +73,7 @@ def test_page_footer_acquisition(app):
|
|||
page.save()
|
||||
ParentContentCell(page=page, placeholder='footer', order=0).save()
|
||||
resp = app.get('/second', status=301)
|
||||
assert resp.location == 'http://testserver/second/'
|
||||
assert urlparse(resp.location).path == '/second/'
|
||||
resp = app.get('/second/', status=200)
|
||||
assert 'BARFOO' in resp.body
|
||||
|
||||
|
@ -98,7 +99,7 @@ def test_page_private_unlogged(app):
|
|||
page = Page(title='Home', slug='index', template_name='standard', public=False)
|
||||
page.save()
|
||||
resp = app.get('/', status=302)
|
||||
assert resp.location == 'http://testserver/login/?next=http%3A//testserver/'
|
||||
assert resp.location.endswith('/login/?next=http%3A//testserver/')
|
||||
|
||||
def test_page_private_logged_in(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
|
@ -191,8 +192,8 @@ def test_subpage_location(app):
|
|||
resp = app.get('/child-home/grand-child-home/', status=200)
|
||||
assert 'Grand child of home' in resp.body
|
||||
|
||||
assert app.get('/child-home/grand-child-home', status=301).location == \
|
||||
'http://testserver/child-home/grand-child-home/'
|
||||
assert urlparse(app.get('/child-home/grand-child-home', status=301).location
|
||||
).path == '/child-home/grand-child-home/'
|
||||
app.get('/grand-child-home/', status=404)
|
||||
|
||||
resp = app.get('/second/', status=200)
|
||||
|
@ -280,7 +281,7 @@ def test_initial_login_page(app, admin_user):
|
|||
# first visit
|
||||
app = login(app)
|
||||
resp = app.get('/', status=302)
|
||||
assert resp.location == 'http://testserver/initial-login/'
|
||||
assert urlparse(resp.location).path == '/initial-login/'
|
||||
|
||||
# visit again
|
||||
resp = app.get('/', status=200)
|
||||
|
@ -296,13 +297,13 @@ def test_welcome_page(app, admin_user):
|
|||
with override_settings(COMBO_WELCOME_PAGE_PATH='/welcome/'):
|
||||
app.cookiejar.clear()
|
||||
resp = app.get('/', status=302)
|
||||
assert resp.location == 'http://testserver/welcome/'
|
||||
assert urlparse(resp.location).path == '/welcome/'
|
||||
|
||||
resp = app.get('/', status=200)
|
||||
|
||||
app.cookiejar.clear()
|
||||
resp = app.get('/', status=302)
|
||||
assert resp.location == 'http://testserver/welcome/'
|
||||
assert urlparse(resp.location).path == '/welcome/'
|
||||
|
||||
app.cookiejar.clear()
|
||||
app = login(app)
|
||||
|
@ -351,7 +352,7 @@ def test_post_cell(app):
|
|||
resp2 = resp.form.submit()
|
||||
assert requests_post.call_args[0][0] == 'http://test-post-cell/create/'
|
||||
assert requests_post.call_args[1]['json'] == {'value': 'plop'}
|
||||
assert resp2.location == 'http://testserver/'
|
||||
assert urlparse(resp2.location).path == '/'
|
||||
|
||||
# check ajax call
|
||||
with mock.patch('combo.utils.requests.post') as requests_post:
|
||||
|
@ -365,13 +366,13 @@ def test_post_cell(app):
|
|||
with mock.patch('combo.utils.requests.post') as requests_post:
|
||||
requests_post.return_value = mock.Mock(content=json.dumps({'err': 0}), status_code=400)
|
||||
resp2 = resp.form.submit()
|
||||
assert resp2.location == 'http://testserver/'
|
||||
assert urlparse(resp2.location).path == '/'
|
||||
resp2 = resp2.follow()
|
||||
assert 'Error sending data.' in resp2.content
|
||||
|
||||
settings.JSON_CELL_TYPES['test-post-cell']['actions']['create']['error-message'] = 'Failed to create stuff.'
|
||||
resp2 = resp.form.submit()
|
||||
assert resp2.location == 'http://testserver/'
|
||||
assert urlparse(resp2.location).path == '/'
|
||||
resp2 = resp2.follow()
|
||||
assert 'Failed to create stuff.' in resp2.content
|
||||
|
||||
|
|
Loading…
Reference in New Issue