Commit d96e1b04 authored by Łukasz Nowak's avatar Łukasz Nowak

playbook: Increase test result readability

By using dict comparision with assertEqual the result will be presented
as diff between expected and found values. This allows test reader to
understand the reason of failing test, instead of trying to guess what
is really wrong with the deployed site.
parent a24b54c9
...@@ -8,18 +8,30 @@ class TestSiteHttp(unittest.TestCase): ...@@ -8,18 +8,30 @@ class TestSiteHttp(unittest.TestCase):
def setUp(self): def setUp(self):
self.http_url = os.environ['TEST_ACCESS_URL_HTTP'] self.http_url = os.environ['TEST_ACCESS_URL_HTTP']
self.https_url = os.environ['TEST_ACCESS_URL_HTTPS'] self.https_url = os.environ['TEST_ACCESS_URL_HTTPS']
self.http_url_norm = self.http_url.replace(':10080', '')
self.https_url_norm = self.https_url.replace(':10443', '')
def test_http_erp5_login_form(self): def test_http_erp5_login_form(self):
"""Check that accessing site over HTTP redirects to HTTPS""" """Check that accessing site over HTTP redirects to HTTPS"""
result = requests.get( result = requests.get(
self.http_url + '/erp5/login_form', verify=False, self.http_url + '/erp5/login_form', verify=False,
allow_redirects=False) allow_redirects=False)
self.assertTrue(result.ok) self.assertEqual(
self.assertTrue(result.is_redirect) dict(
self.assertFalse(result.is_permanent_redirect) ok=result.ok,
self.assertEqual(result.status_code, 302) is_redirect=result.is_redirect,
self.assertTrue(result.headers['Location'].endswith('/erp5/login_form')) is_permanent_redirect=result.is_permanent_redirect,
self.assertTrue(result.headers['Location'].startswith('https://')) status_code=result.status_code,
location=result.headers['Location']
),
dict(
ok=True,
is_redirect=True,
is_permanent_redirect=False,
status_code=302,
location=self.https_url_norm + '/erp5/login_form'
)
)
def test_http_erp5_anydomain(self): def test_http_erp5_anydomain(self):
"""Checks that any domain can be used""" """Checks that any domain can be used"""
...@@ -27,11 +39,19 @@ class TestSiteHttp(unittest.TestCase): ...@@ -27,11 +39,19 @@ class TestSiteHttp(unittest.TestCase):
self.http_url + '/erp5/', allow_redirects=False, self.http_url + '/erp5/', allow_redirects=False,
headers={'Host': 'anyhost'} headers={'Host': 'anyhost'}
) )
self.assertTrue(result.ok)
self.assertTrue(result.is_redirect)
self.assertFalse(result.is_permanent_redirect)
self.assertEqual(result.status_code, 302)
self.assertEqual( self.assertEqual(
result.headers['Location'], dict(
'https://anyhost/erp5/' ok=result.ok,
) is_redirect=result.is_redirect,
is_permanent_redirect=result.is_permanent_redirect,
status_code=result.status_code,
location=result.headers['Location']
),
dict(
ok=True,
is_redirect=True,
is_permanent_redirect=False,
status_code=302,
location='https://anyhost/erp5/'
)
)
\ No newline at end of file
...@@ -6,27 +6,48 @@ import os ...@@ -6,27 +6,48 @@ import os
class TestSiteHttps(unittest.TestCase): class TestSiteHttps(unittest.TestCase):
"""Check that configuration generated in the machine works""" """Check that configuration generated in the machine works"""
def setUp(self): def setUp(self):
self.http_url = os.environ['TEST_ACCESS_URL_HTTP']
self.https_url = os.environ['TEST_ACCESS_URL_HTTPS'] self.https_url = os.environ['TEST_ACCESS_URL_HTTPS']
self.https_url_norm = self.https_url.replace(':10443', '')
def test_https_erp5_login_form(self): def test_https_erp5_login_form(self):
"""Check that accessing login_form over HTTPS works""" """Check that accessing login_form over HTTPS works"""
result = requests.get(self.https_url + '/erp5/login_form', verify=False) result = requests.get(self.https_url + '/erp5/login_form', verify=False)
self.assertTrue(result.ok) self.assertEqual(
self.assertFalse(result.is_redirect) dict(
self.assertFalse(result.is_permanent_redirect) ok=result.ok,
self.assertEqual(result.status_code, 200) is_redirect=result.is_redirect,
is_permanent_redirect=result.is_permanent_redirect,
status_code=result.status_code
),
dict(
ok=True,
is_redirect=False,
is_permanent_redirect=False,
status_code=200
)
)
self.assertTrue('ERP5 Free Open Source ERP and CRM' in result.text) self.assertTrue('ERP5 Free Open Source ERP and CRM' in result.text)
def test_https_erp5(self): def test_https_erp5(self):
"""Check that accessing site over HTTPS redirects to login_form""" """Check that accessing site over HTTPS redirects to login_form"""
result = requests.get( result = requests.get(
self.https_url + '/erp5/', verify=False, allow_redirects=False) self.https_url + '/erp5/', verify=False, allow_redirects=False)
self.assertTrue(result.ok) self.assertEqual(
self.assertTrue(result.is_redirect) dict(
self.assertFalse(result.is_permanent_redirect) ok=result.ok,
self.assertEqual(result.status_code, 302) is_redirect=result.is_redirect,
self.assertTrue(result.headers['Location'].endswith('/erp5/login_form')) is_permanent_redirect=result.is_permanent_redirect,
status_code=result.status_code,
location=result.headers['Location']
),
dict(
ok=True,
is_redirect=True,
is_permanent_redirect=False,
status_code=302,
location=self.https_url_norm + '/erp5/login_form'
)
)
@unittest.skip( @unittest.skip(
'Currently HTTPS will reply with "Hostname 172.16.0.9 provided via SNI ' 'Currently HTTPS will reply with "Hostname 172.16.0.9 provided via SNI '
...@@ -37,11 +58,19 @@ class TestSiteHttps(unittest.TestCase): ...@@ -37,11 +58,19 @@ class TestSiteHttps(unittest.TestCase):
self.https_url + '/erp5/', verify=False, allow_redirects=False, self.https_url + '/erp5/', verify=False, allow_redirects=False,
headers={'Host': 'anyhost'} headers={'Host': 'anyhost'}
) )
self.assertTrue(result.ok)
self.assertTrue(result.is_redirect)
self.assertFalse(result.is_permanent_redirect)
self.assertEqual(result.status_code, 302)
self.assertEqual( self.assertEqual(
result.headers['Location'], dict(
'https://anyhost/erp5/login_form' ok=result.ok,
) is_redirect=result.is_redirect,
is_permanent_redirect=result.is_permanent_redirect,
status_code=result.status_code,
location=result.headers['Location']
),
dict(
ok=True,
is_redirect=True,
is_permanent_redirect=False,
status_code=302,
location='https://anyhost/erp5/login_form'
)
)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment