diff --git a/README.md b/README.md index aa1ca8f..6fa4932 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Check link stats by adding **+** to the URL. Example [pygy.co/pygmy+](https://py - [Pygmy](#pygmy) - [Table of Contents](#table-of-contents) - [Features](#features) -- [Technical Info](#tech-used) +- [Technical Info](#technical-info) - [Installaton/Setup](#installatonsetup) - [DB Setup:](#db-setup) - [Use MySQL](#use-mysql) @@ -73,12 +73,14 @@ NOTE: **This module only supports Python 3. Make sure pip and virtualenv are bot 4. `cd src` 5. `python run.py` (It runs Flask and Django servers using gunicorn) 6. Visit `127.0.0.1:8000` to use the app +7. Logs can be viewed at `pygmy/data/pygmy.log` Note: 1. The project has two config files: - pygmy.cfg: `pygmy/config/pygmy.cfg` rest API and pygmy core settings file - settings.py: `pygmyui/pygmyui/settings.py` Django settings file +2.Both the files have aparallel _test. config files to configure it for tests. 2. SQLite is default db, if you are using PostgreSQL or MySQL with this project, make sure they are installed into the system. 3. To modify config settings vim `pygmy/config/pygmy.cfg` 4. You can run pygmy shell present in src directory to run the program on terminal. `python shell` @@ -235,11 +237,13 @@ It uses JWT. When user logs in using username and password two tokens are genera Development =========== +If you find any bug, have a question or a general feature request. Open an issue on the 'Issue' page. + Run tests and generate a coverage report: `coverage run --source pygmy -m py.test` -See coverage report: +See coverage report(Coverage is bad because the coverage for integration tests is not generated yet): `coverage report` 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