Skip to content

Commit

Permalink
Secret link stats ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
amitt001 committed Jul 10, 2018
1 parent 87a19bc commit 5b8a6fc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 20 deletions.
4 changes: 4 additions & 0 deletions pygmy/app/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def formatted_link_stats(link):
'time_series_base': click_meta.get('time_base'),
'time_stats': click_meta.get('timestamp_hits', {}),
}

# Hide original/long_url in case of protected links
if link.is_protected is True:
link_info['long_url'] = ''
return {**link_info, **click_info}


Expand Down
2 changes: 0 additions & 2 deletions pygmy/rest/shorturl.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ def resolve(code):
secret_key = request.headers.get('secret_key')
try:
# check if link is not a secret link
long_url = resolve_short(
code.strip('+'), secret_key=secret_key)
if code.startswith('+') or code.endswith('+'):
stats = link_stats(code)
response = jsonify(stats)
Expand Down
5 changes: 1 addition & 4 deletions pygmy/utilities/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def validate_url(url):


def make_short_url(short_path):
short_url = urljoin(
config.pygmy['short_url_schema'],
config.pygmy['short_url'],
short_path)
short_url = urljoin('{}{}'.format(config.pygmy['short_url_schema'], config.pygmy['short_url']), short_path)
return short_url


Expand Down
4 changes: 2 additions & 2 deletions pygmyui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h3><b>SIGN UP</b></h3>
<input type="email" name="email" id="email" tabindex="1" class="form-control" placeholder="Email Address" value="">
</div>
<div class="form-group">
<input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password">
<input type="password" name="password" id="signup_password" tabindex="2" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<input type="password" name="confirm_password" id="confirm_password" tabindex="2" class="form-control" placeholder="Confirm Password">
Expand Down Expand Up @@ -105,7 +105,7 @@ <h3><b>LOGIN</b></h3>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off">
<input type="password" name="password" id="login_password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off">
</div>
<div class="form-group">
<div class="row">
Expand Down
43 changes: 31 additions & 12 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pytest
import sqlite3
import unittest
import requests

from pygmy.config import config
from pygmyui.restclient.base import Client


Expand All @@ -22,14 +20,14 @@ def teardown_class(cls):
pass

def teardown_method(self, _):
# self.conn = sqlite3.connect(config.database['url'])
# self.cur = self.conn.cursor()
# tables = ['clickmeta', 'link', 'user']
# for table in tables:
# self.cur.execute('DELETE FROM {}'.format(table))
# self.conn.commit()
# self.conn.close()
return
self.conn = sqlite3.connect(config.database['url'])
self.cur = self.conn.cursor()
tables = ['clickmeta', 'link', 'user']
for table in tables:
self.cur.execute('DELETE FROM {}'.format(table))
self.conn.commit()
self.conn.close()

def setup_method(self, _):
self._token = None
Expand Down Expand Up @@ -235,13 +233,34 @@ def test_non_loggedin_dashboard(self):

def test_check_link_availability(self):
custom_code = 'logo'
requests.get(self.url + '/check?custom_code={}'.format(custom_code), 200)
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
self.assertEqual(response.status_code, 200)
self.assertTrue(response.json().get('ok'))

def test_custom_taken_link_availability(self):
pass
custom_code = 'logo'
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
self.assertTrue(response.json().get('ok'))
data = self.data
data['custom_url'] = custom_code
requests.post(self.url + '/shorten', data=data, headers=self.headers)
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
self.assertFalse(response.json().get('ok'))

def test_custom_taken_link_shorten(self):
pass
custom_code = 'go'
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
self.assertTrue(response.json().get('ok'))

data = self.data
data['custom_url'] = custom_code
requests.post(self.url + '/shorten', data=data, headers=self.headers)

response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
self.assertFalse(response.json().get('ok'))

response = requests.post(self.url + '/shorten', data=data, headers=self.headers)
self.assertEqual(response.status_code, 400)

def test_custom_links(self):
data = self.data
Expand Down

0 comments on commit 5b8a6fc

Please sign in to comment.