Skip to content

Commit ed29bb7

Browse files
committed
Secret link stats ✨
1 parent d99e96c commit ed29bb7

5 files changed

Lines changed: 38 additions & 20 deletions

File tree

pygmy/app/link.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ def formatted_link_stats(link):
130130
'time_series_base': click_meta.get('time_base'),
131131
'time_stats': click_meta.get('timestamp_hits', {}),
132132
}
133+
134+
# Hide original/long_url in case of protected links
135+
if link.is_protected is True:
136+
link_info['long_url'] = ''
133137
return {**link_info, **click_info}
134138

135139

pygmy/rest/shorturl.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ def resolve(code):
9898
secret_key = request.headers.get('secret_key')
9999
try:
100100
# check if link is not a secret link
101-
long_url = resolve_short(
102-
code.strip('+'), secret_key=secret_key)
103101
if code.startswith('+') or code.endswith('+'):
104102
stats = link_stats(code)
105103
response = jsonify(stats)

pygmy/utilities/urls.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ def validate_url(url):
2626

2727

2828
def make_short_url(short_path):
29-
short_url = urljoin(
30-
config.pygmy['short_url_schema'],
31-
config.pygmy['short_url'],
32-
short_path)
29+
short_url = urljoin('{}{}'.format(config.pygmy['short_url_schema'], config.pygmy['short_url']), short_path)
3330
return short_url
3431

3532

pygmyui/templates/base.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h3><b>SIGN UP</b></h3>
7474
<input type="email" name="email" id="email" tabindex="1" class="form-control" placeholder="Email Address" value="">
7575
</div>
7676
<div class="form-group">
77-
<input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password">
77+
<input type="password" name="password" id="signup_password" tabindex="2" class="form-control" placeholder="Password">
7878
</div>
7979
<div class="form-group">
8080
<input type="password" name="confirm_password" id="confirm_password" tabindex="2" class="form-control" placeholder="Confirm Password">
@@ -105,7 +105,7 @@ <h3><b>LOGIN</b></h3>
105105
</div>
106106
<div class="form-group">
107107
<label for="password">Password</label>
108-
<input type="password" name="password" id="password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off">
108+
<input type="password" name="password" id="login_password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off">
109109
</div>
110110
<div class="form-group">
111111
<div class="row">

tests/test_integration.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import pytest
2-
import sqlite3
32
import unittest
43
import requests
54

6-
from pygmy.config import config
75
from pygmyui.restclient.base import Client
86

97

@@ -22,14 +20,14 @@ def teardown_class(cls):
2220
pass
2321

2422
def teardown_method(self, _):
23+
# self.conn = sqlite3.connect(config.database['url'])
24+
# self.cur = self.conn.cursor()
25+
# tables = ['clickmeta', 'link', 'user']
26+
# for table in tables:
27+
# self.cur.execute('DELETE FROM {}'.format(table))
28+
# self.conn.commit()
29+
# self.conn.close()
2530
return
26-
self.conn = sqlite3.connect(config.database['url'])
27-
self.cur = self.conn.cursor()
28-
tables = ['clickmeta', 'link', 'user']
29-
for table in tables:
30-
self.cur.execute('DELETE FROM {}'.format(table))
31-
self.conn.commit()
32-
self.conn.close()
3331

3432
def setup_method(self, _):
3533
self._token = None
@@ -235,13 +233,34 @@ def test_non_loggedin_dashboard(self):
235233

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

240240
def test_custom_taken_link_availability(self):
241-
pass
241+
custom_code = 'logo'
242+
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
243+
self.assertTrue(response.json().get('ok'))
244+
data = self.data
245+
data['custom_url'] = custom_code
246+
requests.post(self.url + '/shorten', data=data, headers=self.headers)
247+
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
248+
self.assertFalse(response.json().get('ok'))
242249

243250
def test_custom_taken_link_shorten(self):
244-
pass
251+
custom_code = 'go'
252+
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
253+
self.assertTrue(response.json().get('ok'))
254+
255+
data = self.data
256+
data['custom_url'] = custom_code
257+
requests.post(self.url + '/shorten', data=data, headers=self.headers)
258+
259+
response = requests.get(self.url + '/check?custom_code={}'.format(custom_code))
260+
self.assertFalse(response.json().get('ok'))
261+
262+
response = requests.post(self.url + '/shorten', data=data, headers=self.headers)
263+
self.assertEqual(response.status_code, 400)
245264

246265
def test_custom_links(self):
247266
data = self.data

0 commit comments

Comments
 (0)