Skip to content

Commit

Permalink
Support to run test servers in different ports 🍰
Browse files Browse the repository at this point in the history
  • Loading branch information
amitt001 committed Jul 12, 2018
1 parent ed29bb7 commit c2befee
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <name>_test.<ext> 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`
Expand Down Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion pygmy/config/pygmy_test.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions pygmyui/pygmy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pygmyui/pygmyui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions pygmyui/pygmyui/settings_tests.py
Original file line number Diff line number Diff line change
@@ -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'
1 change: 1 addition & 0 deletions tests/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit c2befee

Please sign in to comment.