Skip to content

Commit

Permalink
Handle different responses in 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 22, 2024
1 parent 9a62c76 commit 063f03c
Showing 1 changed file with 90 additions and 39 deletions.
129 changes: 90 additions & 39 deletions ckanext/pages/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,17 @@ def test_revisions_page(self, app):

assert '404 Not Found' in response.body

response = app.get(
toolkit.url_for('pages.pages_revisions', page="page_name"),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
if toolkit.check_ckan_version(min_version="2.10.0"):
response = app.get(
toolkit.url_for('pages.pages_revisions', page="page_name"),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
else:
response = app.get(
toolkit.url_for('pages.pages_revisions', page="page_name")
)
assert '<h1 class="page-heading">Login</h1>' in response.body

def test_revision_preview_page(self, app):
user = factories.Sysadmin()
Expand Down Expand Up @@ -281,14 +287,23 @@ def test_revision_preview_page(self, app):

assert '404 Not Found' in response.body

response = app.get(
toolkit.url_for(
'pages.pages_revisions_preview',
page="page_name",
revision=revision_id),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
if toolkit.check_ckan_version(min_version="2.10.0"):
response = app.get(
toolkit.url_for(
'pages.pages_revisions_preview',
page="page_name",
revision=revision_id),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
else:
response = app.get(
toolkit.url_for(
'pages.pages_revisions_preview',
page="page_name",
revision=revision_id),
)
assert '<h1 class="page-heading">Login</h1>' in response.body

def test_revision_restore_page(self, app):
user = factories.Sysadmin()
Expand Down Expand Up @@ -343,14 +358,24 @@ def test_revision_restore_page(self, app):

assert 'Bad values, please make sure that provided values exist' in response.body

response = app.get(
toolkit.url_for(
'pages.pages_revision_restore',
page="page_name",
revision=last_revision[0]),
status=401)
if toolkit.check_ckan_version(min_version="2.10.0"):
response = app.get(
toolkit.url_for(
'pages.pages_revision_restore',
page="page_name",
revision=last_revision[0]),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
else:
response = app.get(
toolkit.url_for(
'pages.pages_revision_restore',
page="page_name",
revision=last_revision[0]),
)

assert '<h1>401 Unauthorized</h1>' in response.body
assert '<h1 class="page-heading">Login</h1>' in response.body

def test_revisions_blog(self, app):
user = factories.Sysadmin()
Expand Down Expand Up @@ -378,11 +403,18 @@ def test_revisions_blog(self, app):

assert '404 Not Found' in response.body

response = app.get(
toolkit.url_for('pages.blog_revisions', page="blog_name"),
status=401)
if toolkit.check_ckan_version(min_version="2.10.0"):
response = app.get(
toolkit.url_for('pages.blog_revisions', page="blog_name"),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
assert '<h1>401 Unauthorized</h1>' in response.body
else:
response = app.get(
toolkit.url_for('pages.blog_revisions', page="blog_name"),
)

assert '<h1 class="page-heading">Login</h1>' in response.body

def test_revision_preview_blog(self, app):
user = factories.Sysadmin()
Expand Down Expand Up @@ -420,14 +452,23 @@ def test_revision_preview_blog(self, app):

assert '404 Not Found' in response.body

response = app.get(
toolkit.url_for(
'pages.blog_revisions_preview',
page="blog_name",
revision=revision_id),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
if toolkit.check_ckan_version(min_version="2.10.0"):
response = app.get(
toolkit.url_for(
'pages.blog_revisions_preview',
page="blog_name",
revision=revision_id),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
else:
response = app.get(
toolkit.url_for(
'pages.blog_revisions_preview',
page="blog_name",
revision=revision_id),
)
assert '<h1 class="page-heading">Login</h1>' in response.body

def test_revision_restore_blog(self, app):
user = factories.Sysadmin()
Expand Down Expand Up @@ -487,11 +528,21 @@ def test_revision_restore_blog(self, app):

assert 'Bad values, please make sure that provided values exist' in response.body

response = app.get(
toolkit.url_for(
'pages.blog_revision_restore',
page="blog_name",
revision=last_revision[0]),
status=401)
if toolkit.check_ckan_version(min_version="2.10.0"):
response = app.get(
toolkit.url_for(
'pages.blog_revision_restore',
page="blog_name",
revision=last_revision[0]),
status=401)

assert '<h1>401 Unauthorized</h1>' in response.body
else:
response = app.get(
toolkit.url_for(
'pages.blog_revision_restore',
page="blog_name",
revision=last_revision[0]),
)

assert '<h1>401 Unauthorized</h1>' in response.body
assert '<h1 class="page-heading">Login</h1>' in response.body

0 comments on commit 063f03c

Please sign in to comment.