From c6fd2f4207f11d904830e42910492ce523e2d93e Mon Sep 17 00:00:00 2001 From: Amit Tripathi Date: Fri, 13 Jul 2018 00:37:26 +0200 Subject: [PATCH] Support to run test servers in different ports :cake: --- pygmy/config/pygmy_test.cfg | 2 +- pygmyui/pygmy/views.py | 6 ------ pygmyui/pygmyui/settings.py | 4 ++++ pygmyui/pygmyui/settings_tests.py | 10 ++++++++++ tests/fixture.py | 1 + tests/test_integration.py | 26 +++++++++++++------------- 6 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 pygmyui/pygmyui/settings_tests.py diff --git a/pygmy/config/pygmy_test.cfg b/pygmy/config/pygmy_test.cfg index 1b377c3..280e380 100644 --- a/pygmy/config/pygmy_test.cfg +++ b/pygmy/config/pygmy_test.cfg @@ -1,7 +1,7 @@ [pygmy] schema = http host = 0.0.0.0 -port = 9119 +port = 9118 debug = True flask_secret = CvJHGFVBj*&^TRGBHDdBV836bdy73JJDHGV short_url = 127.0.0.1 diff --git a/pygmyui/pygmy/views.py b/pygmyui/pygmy/views.py index 8b205b0..7a966ab 100644 --- a/pygmyui/pygmy/views.py +++ b/pygmyui/pygmy/views.py @@ -122,12 +122,6 @@ def short_link_stats(request, code): key=operator.itemgetter(1), reverse=True) context = dict(clickmeta=clickmeta) - except UnAuthorized: - # return redirect('/link/secret?next={}'.format(code)) - return render(request, '404.html', - context=API_ERROR(dict( - error='Secret link stats are not yet supported.') - ), status=404) except (ObjectNotFound, LinkExpired) as e: return render(request, '404.html', context=API_ERROR(e.args[0]), status=404) diff --git a/pygmyui/pygmyui/settings.py b/pygmyui/pygmyui/settings.py index 3b42931..068c68d 100644 --- a/pygmyui/pygmyui/settings.py +++ b/pygmyui/pygmyui/settings.py @@ -149,3 +149,7 @@ PYGMY_API_PASSWORD = 'admin' HOSTNAME = '127.0.0.1:8000' + +# Load tests if PYGMYUI_TEST environment variable is set +if os.environ.get('PYGMYUI_TEST') is not None: + from pygmyui.settings_tests import * # pylint: disable=W0614, E0611, E0401 diff --git a/pygmyui/pygmyui/settings_tests.py b/pygmyui/pygmyui/settings_tests.py new file mode 100644 index 0000000..2cd17db --- /dev/null +++ b/pygmyui/pygmyui/settings_tests.py @@ -0,0 +1,10 @@ +# Pygmy Test Settings +PYGMY_API_ADDRESS = 'http://127.0.0.1:9118' + +PYGMY_API_AUTH = 'BasicAuth' + +PYGMY_API_USER = 'admin' + +PYGMY_API_PASSWORD = 'admin' + +HOSTNAME = '127.0.0.1:8001' diff --git a/tests/fixture.py b/tests/fixture.py index beaeb20..07fea67 100644 --- a/tests/fixture.py +++ b/tests/fixture.py @@ -58,6 +58,7 @@ def terminate_pygmy_ui_server(cls): @pytest.fixture(scope='class') def run_test_server(request): # Setup + os.environ.setdefault('PYGMYUI_TEST', 'true') request.cls.pygmyapi_proc = PygmyApiTestServer.start_pygmy_api_server() request.cls.pygmyui_proc = PygmyUiTestServer.start_pygmy_ui_server() yield diff --git a/tests/test_integration.py b/tests/test_integration.py index 6c5b365..4ed0ad4 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -287,12 +287,12 @@ def test_custom_links(self): # secret_url = self.url + '/link/secret?next={}'.format(short_url.split('/')[-1]) # resp = sess.get(short_url) # self.assertTrue(resp.url, secret_url) - # + # headers = self.headers # headers['Cookie'] = 'csrftoken={}'.format(resp.cookies['csrftoken']) # import pdb # pdb.set_trace() - # + # resp = sess.post(self.url + '/link/secret', json={'code':short_url.split('/')[-1],'secret_key': data['secret_key'], 'csrfmiddlewaretoken': resp.cookies['csrftoken']}, headers=headers) # self.assertEqual(resp.status_code, 200) # self.assertTrue('value="{}"'.format(short_url) in response.text) @@ -303,27 +303,27 @@ def test_custom_links(self): # data['remember_time'] = 1 # 1 second # response = requests.post(self.url + '/shorten', data=data, headers=self.headers) # short_url = self._get_short_url_from_response(response) - # + # self.assertEqual(requests.get(short_url).url, self.data['long_url']) # self.assertEqual(response.status_code, 200) # import time # time.sleep(1) # self.assertEqual(requests.get(short_url).status_code, 404) - def test_custom_secret_links(self): - pass + # def test_custom_secret_links(self): + # pass - def test_custom_expiry_links(self): - pass + # def test_custom_expiry_links(self): + # pass - def test_secret_expiry_links(self): - pass + # def test_secret_expiry_links(self): + # pass - def test_custom_secret_expiry_links(self): - pass + # def test_custom_secret_expiry_links(self): + # pass - def test_invalid_char_custom_link(self): - pass + # def test_invalid_char_custom_link(self): + # pass # ############ # # Link stats