Skip to content

Commit fae14a5

Browse files
committed
Avoid storing clicks temp
1 parent 4536f7d commit fae14a5

File tree

3 files changed

+65
-64
lines changed

3 files changed

+65
-64
lines changed

src/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '1.0.40'
1+
VERSION = '1.0.41'

src/views/common.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pathlib import Path
1111
from starlette.requests import Request
1212
from starlette.responses import HTMLResponse, RedirectResponse
13-
from time import time
1413
from typing import Optional
1514

1615
logger = logging.getLogger('views.common')
@@ -48,15 +47,15 @@ async def click_redirect_view(
4847

4948
if link:
5049
link_id, link_url = link
51-
if ip_address := X_Forwarded_For:
52-
ip_address = ip_address.split(',', 1)[0]
50+
# if ip_address := X_Forwarded_For:
51+
# ip_address = ip_address.split(',', 1)[0]
52+
#
53+
# try:
54+
# ts = float(X_Request_Start)
55+
# except ValueError:
56+
# ts = time()
5357

54-
try:
55-
ts = float(X_Request_Start)
56-
except ValueError:
57-
ts = time()
58-
59-
await glove.redis.enqueue_job('store_click', link_id=link_id, ip=ip_address, user_agent=User_Agent, ts=ts)
58+
# await glove.redis.enqueue_job('store_click', link_id=link_id, ip=ip_address, user_agent=User_Agent, ts=ts)
6059
if arg_url and arg_url != link_url:
6160
logger.warning('db url does not match arg url: %r != %r', link_url, arg_url)
6261
return RedirectResponse(url=link_url)

tests/test_email.py

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from datetime import datetime, timedelta, timezone
1111
from foxglove.db.helpers import SyncDb
1212
from pathlib import Path
13-
from pytest_toolbox.comparison import AnyInt, RegexStr
13+
from pytest_toolbox.comparison import RegexStr
1414
from starlette.testclient import TestClient
1515
from unittest.mock import Mock, patch
1616
from uuid import uuid4
@@ -687,47 +687,47 @@ def send_with_link(send_email, tmpdir):
687687
return token
688688

689689

690-
def test_link_shortening(send_email, tmpdir, cli: TestClient, sync_db: SyncDb, worker, loop):
691-
token = send_with_link(send_email, tmpdir)
692-
693-
m = sync_db.fetchrow_b('select * from messages')
694-
assert m['status'] == 'send'
695-
696-
link = sync_db.fetchrow_b('select * from links')
697-
assert link['id'] == AnyInt()
698-
assert link['message_id'] == m['id']
699-
assert link['token'] == token
700-
assert link['url'] == 'https://www.foobar.com'
701-
702-
r = cli.get(
703-
'/l' + token,
704-
allow_redirects=False,
705-
headers={
706-
'X-Forwarded-For': '54.170.228.0, 141.101.88.55',
707-
'X-Request-Start': '1969660800',
708-
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
709-
'Chrome/59.0.3071.115 Safari/537.36',
710-
},
711-
)
712-
assert r.status_code == 307, r.text
713-
assert r.headers['location'] == 'https://www.foobar.com'
714-
assert worker.test_run() == 2
715-
716-
m = sync_db.fetchrow_b('select * from messages where :where', where=V('id') == m['id'])
717-
assert m['status'] == 'click'
718-
event = sync_db.fetchrow_b('select * from events')
719-
assert event['status'] == 'click'
720-
assert event['ts'] == datetime(2032, 6, 1, 0, 0, tzinfo=timezone.utc)
721-
extra = json.loads(event['extra'])
722-
assert extra == {
723-
'ip': '54.170.228.0',
724-
'target': 'https://www.foobar.com',
725-
'user_agent': (
726-
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
727-
'Chrome/59.0.3071.115 Safari/537.36'
728-
),
729-
'user_agent_display': 'Chrome 59 on Linux',
730-
}
690+
# def test_link_shortening(send_email, tmpdir, cli: TestClient, sync_db: SyncDb, worker, loop):
691+
# token = send_with_link(send_email, tmpdir)
692+
#
693+
# m = sync_db.fetchrow_b('select * from messages')
694+
# assert m['status'] == 'send'
695+
#
696+
# link = sync_db.fetchrow_b('select * from links')
697+
# assert link['id'] == AnyInt()
698+
# assert link['message_id'] == m['id']
699+
# assert link['token'] == token
700+
# assert link['url'] == 'https://www.foobar.com'
701+
#
702+
# r = cli.get(
703+
# '/l' + token,
704+
# allow_redirects=False,
705+
# headers={
706+
# 'X-Forwarded-For': '54.170.228.0, 141.101.88.55',
707+
# 'X-Request-Start': '1969660800',
708+
# 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
709+
# 'Chrome/59.0.3071.115 Safari/537.36',
710+
# },
711+
# )
712+
# assert r.status_code == 307, r.text
713+
# assert r.headers['location'] == 'https://www.foobar.com'
714+
# assert worker.test_run() == 2
715+
#
716+
# m = sync_db.fetchrow_b('select * from messages where :where', where=V('id') == m['id'])
717+
# assert m['status'] == 'click'
718+
# event = sync_db.fetchrow_b('select * from events')
719+
# assert event['status'] == 'click'
720+
# assert event['ts'] == datetime(2032, 6, 1, 0, 0, tzinfo=timezone.utc)
721+
# extra = json.loads(event['extra'])
722+
# assert extra == {
723+
# 'ip': '54.170.228.0',
724+
# 'target': 'https://www.foobar.com',
725+
# 'user_agent': (
726+
# 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) '
727+
# 'Chrome/59.0.3071.115 Safari/537.36'
728+
# ),
729+
# 'user_agent_display': 'Chrome 59 on Linux',
730+
# }
731731

732732

733733
def test_link_shortening_wrong_url(send_email, tmpdir, cli, dummy_server):
@@ -745,18 +745,20 @@ def test_link_shortening_wrong_url_missing(send_email, tmpdir, cli, dummy_server
745745
assert r.headers['location'] == 'different'
746746

747747

748-
def test_link_shortening_repeat(send_email, tmpdir, cli: TestClient, sync_db: SyncDb, worker, loop, dummy_server):
749-
token = send_with_link(send_email, tmpdir)
750-
r = cli.get('/l' + token, allow_redirects=False)
751-
assert r.status_code == 307, r.text
752-
assert worker.test_run() == 2
753-
assert r.headers['location'] == 'https://www.foobar.com'
754-
assert sync_db.fetchval('select count(*) from events') == 1
755-
756-
r = cli.get('/l' + token, allow_redirects=False)
757-
assert r.status_code == 307, r.text
758-
assert r.headers['location'] == 'https://www.foobar.com'
759-
assert sync_db.fetchval('select count(*) from events') == 1
748+
#
749+
#
750+
# def test_link_shortening_repeat(send_email, tmpdir, cli: TestClient, sync_db: SyncDb, worker, loop, dummy_server):
751+
# token = send_with_link(send_email, tmpdir)
752+
# r = cli.get('/l' + token, allow_redirects=False)
753+
# assert r.status_code == 307, r.text
754+
# assert worker.test_run() == 2
755+
# assert r.headers['location'] == 'https://www.foobar.com'
756+
# assert sync_db.fetchval('select count(*) from events') == 1
757+
#
758+
# r = cli.get('/l' + token, allow_redirects=False)
759+
# assert r.status_code == 307, r.text
760+
# assert r.headers['location'] == 'https://www.foobar.com'
761+
# assert sync_db.fetchval('select count(*) from events') == 1
760762

761763

762764
def test_link_shortening_in_render(send_email, tmpdir, sync_db: SyncDb):

0 commit comments

Comments
 (0)