Skip to content

Commit a58f626

Browse files
committed
Support to run test servers in different ports
1 parent ed29bb7 commit a58f626

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Check link stats by adding **+** to the URL. Example [pygy.co/pygmy+](https://py
1313
- [Pygmy](#pygmy)
1414
- [Table of Contents](#table-of-contents)
1515
- [Features](#features)
16-
- [Technical Info](#tech-used)
16+
- [Technical Info](#technical-info)
1717
- [Installaton/Setup](#installatonsetup)
1818
- [DB Setup:](#db-setup)
1919
- [Use MySQL](#use-mysql)
@@ -73,12 +73,14 @@ NOTE: **This module only supports Python 3. Make sure pip and virtualenv are bot
7373
4. `cd src`
7474
5. `python run.py` (It runs Flask and Django servers using gunicorn)
7575
6. Visit `127.0.0.1:8000` to use the app
76+
7. Logs can be viewed at `pygmy/data/pygmy.log`
7677

7778
Note:
7879

7980
1. The project has two config files:
8081
- pygmy.cfg: `pygmy/config/pygmy.cfg` rest API and pygmy core settings file
8182
- settings.py: `pygmyui/pygmyui/settings.py` Django settings file
83+
2.Both the files have aparallel <name>_test.<ext> config files to configure it for tests.
8284
2. SQLite is default db, if you are using PostgreSQL or MySQL with this project, make sure they are installed into the system.
8385
3. To modify config settings vim `pygmy/config/pygmy.cfg`
8486
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
235237
Development
236238
===========
237239

240+
If you find any bug, have a question or a general feature request. Open an issue on the 'Issue' page.
241+
238242
Run tests and generate a coverage report:
239243

240244
`coverage run --source pygmy -m py.test`
241245

242-
See coverage report:
246+
See coverage report(Coverage is bad because the coverage for integration tests is not generated yet):
243247

244248
`coverage report`
245249

pygmy/config/pygmy_test.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[pygmy]
22
schema = http
33
host = 0.0.0.0
4-
port = 9119
4+
port = 9118
55
debug = True
66
flask_secret = CvJHGFVBj*&^TRGBHDdBV836bdy73JJDHGV
77
short_url = 127.0.0.1

pygmyui/pygmy/views.py

-6
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ def short_link_stats(request, code):
122122
key=operator.itemgetter(1),
123123
reverse=True)
124124
context = dict(clickmeta=clickmeta)
125-
except UnAuthorized:
126-
# return redirect('/link/secret?next={}'.format(code))
127-
return render(request, '404.html',
128-
context=API_ERROR(dict(
129-
error='Secret link stats are not yet supported.')
130-
), status=404)
131125
except (ObjectNotFound, LinkExpired) as e:
132126
return render(request, '404.html',
133127
context=API_ERROR(e.args[0]), status=404)

pygmyui/pygmyui/settings.py

+4
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@
149149
PYGMY_API_PASSWORD = 'admin'
150150

151151
HOSTNAME = '127.0.0.1:8000'
152+
153+
# Load tests if PYGMYUI_TEST environment variable is set
154+
if os.environ.get('PYGMYUI_TEST') is not None:
155+
from pygmyui.settings_tests import * # pylint: disable=W0614, E0611, E0401

pygmyui/pygmyui/settings_tests.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Pygmy Test Settings
2+
PYGMY_API_ADDRESS = 'http://127.0.0.1:9118'
3+
4+
PYGMY_API_AUTH = 'BasicAuth'
5+
6+
PYGMY_API_USER = 'admin'
7+
8+
PYGMY_API_PASSWORD = 'admin'
9+
10+
HOSTNAME = '127.0.0.1:8001'

tests/fixture.py

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def terminate_pygmy_ui_server(cls):
5858
@pytest.fixture(scope='class')
5959
def run_test_server(request):
6060
# Setup
61+
os.environ.setdefault('PYGMYUI_TEST', 'true')
6162
request.cls.pygmyapi_proc = PygmyApiTestServer.start_pygmy_api_server()
6263
request.cls.pygmyui_proc = PygmyUiTestServer.start_pygmy_ui_server()
6364
yield

tests/test_integration.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ def test_custom_links(self):
287287
# secret_url = self.url + '/link/secret?next={}'.format(short_url.split('/')[-1])
288288
# resp = sess.get(short_url)
289289
# self.assertTrue(resp.url, secret_url)
290-
#
290+
291291
# headers = self.headers
292292
# headers['Cookie'] = 'csrftoken={}'.format(resp.cookies['csrftoken'])
293293
# import pdb
294294
# pdb.set_trace()
295-
#
295+
296296
# resp = sess.post(self.url + '/link/secret', json={'code':short_url.split('/')[-1],'secret_key': data['secret_key'], 'csrfmiddlewaretoken': resp.cookies['csrftoken']}, headers=headers)
297297
# self.assertEqual(resp.status_code, 200)
298298
# self.assertTrue('value="{}"'.format(short_url) in response.text)
@@ -303,27 +303,27 @@ def test_custom_links(self):
303303
# data['remember_time'] = 1 # 1 second
304304
# response = requests.post(self.url + '/shorten', data=data, headers=self.headers)
305305
# short_url = self._get_short_url_from_response(response)
306-
#
306+
307307
# self.assertEqual(requests.get(short_url).url, self.data['long_url'])
308308
# self.assertEqual(response.status_code, 200)
309309
# import time
310310
# time.sleep(1)
311311
# self.assertEqual(requests.get(short_url).status_code, 404)
312312

313-
def test_custom_secret_links(self):
314-
pass
313+
# def test_custom_secret_links(self):
314+
# pass
315315

316-
def test_custom_expiry_links(self):
317-
pass
316+
# def test_custom_expiry_links(self):
317+
# pass
318318

319-
def test_secret_expiry_links(self):
320-
pass
319+
# def test_secret_expiry_links(self):
320+
# pass
321321

322-
def test_custom_secret_expiry_links(self):
323-
pass
322+
# def test_custom_secret_expiry_links(self):
323+
# pass
324324

325-
def test_invalid_char_custom_link(self):
326-
pass
325+
# def test_invalid_char_custom_link(self):
326+
# pass
327327

328328
# ############
329329
# # Link stats

0 commit comments

Comments
 (0)