Skip to content

Commit

Permalink
Merge branch 'adrima01-recent_captures'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Jun 19, 2024
2 parents 15d6beb + 9babff7 commit 9f20da9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pylookyloo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
import warnings

from datetime import datetime
from importlib.metadata import version
from io import BytesIO, StringIO
from typing import Any, TypedDict, overload, Literal
Expand Down Expand Up @@ -494,6 +495,20 @@ def send_mail(self, tree_uuid: str, email: str = '', comment: str | None = None)
r = self.session.post(urljoin(self.root_url, str(PurePosixPath('json', tree_uuid, 'report'))), json=to_send)
return r.json()

def get_recent_captures(self, timestamp: str | datetime | float | None=None) -> list[str]:
'''Gets the uuids of the most recent captures
:param timestamp: Timestamp of the capture
'''
if not timestamp:
url = urljoin(self.root_url, str(PurePosixPath('json', 'recent_captures')))
else:
if isinstance(timestamp, datetime):
timestamp = timestamp.timestamp()
url = urljoin(self.root_url, str(PurePosixPath('json', 'recent_captures', str(timestamp))))
r = self.session.get(url)
return r.json()

@overload
def upload_capture(self, *, quiet: Literal[True],
listing: bool = False,
Expand Down
10 changes: 9 additions & 1 deletion tests/testing_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest
import time

from datetime import datetime
from zipfile import ZipFile

import requests
Expand Down Expand Up @@ -43,13 +44,20 @@ def test_github_instance_is_up(self) -> None:

# Check that a capture is properly made
def test_capture(self) -> None:
oldest_capture_time = datetime.now()
time.sleep(1)
# Query a url for capture; save uuid of the capture in a variable
uuid = self.github_instance.submit(url='https://rafiot.eu.pythonanywhere.com/redirect_http', quiet=True)
self._wait_capture_done(uuid)
response = self.github_instance.get_redirects(uuid)
self.assertEqual('https://rafiot.eu.pythonanywhere.com/redirect_http', response['response']['url'])
self.assertEqual('https://www.youtube.com/watch?v=iwGFalTRHDA', response['response']['redirects'][1])

# test get recent captures
recent_captures = self.github_instance.get_recent_captures(oldest_capture_time)
self.assertEqual(len(recent_captures), 1)
self.assertEqual(recent_captures[0], uuid)

# test export - import
capture_export = self.github_instance.get_complete_capture(uuid)
new_uuid, messages = self.github_instance.upload_capture(full_capture=capture_export, quiet=False)
Expand Down Expand Up @@ -79,8 +87,8 @@ def test_comparables(self) -> None:
self.assertEqual(200, response['final_status_code'])

def test_capture_settings(self) -> None:
uuid = self.github_instance.submit(url='https://rafiot.eu.pythonanywhere.com/all_settings',
# uuid = self.github_instance.submit(url='http://192.168.1.65:5000/all_settings',
uuid = self.github_instance.submit(url='https://rafiot.eu.pythonanywhere.com/all_settings',
user_agent="MyTestAgent",
headers={'Manual-Test': "blahhh", "DNT": "1"},
geolocation={'latitude': 50, 'longitude': 40},
Expand Down

0 comments on commit 9f20da9

Please sign in to comment.