annotate tests/mockutil.py @ 60:b7da3d97ea99

Add profile URL handlers Silos register these handlers so that everybody knows if a hyperlink is a mention to another user on a particular social network. If any handler matches, silos not related to that social media will skip that link. It's possible than in rare cases we want that link everywhere, but so far I haven't needed it, compared to all the times I didn't want these links.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 28 Oct 2023 11:57:04 -0700
parents b404445082f8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 def mock_urllib(m):
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import urllib.request
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 m.setattr(urllib.request, 'urlretrieve', _patched_urlretrieve)
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 m.setattr(urllib.request, 'urlcleanup', _patched_urlcleanup)
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 return m
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8
59
b404445082f8 Prevent unit tests from downloading fake posts
Ludovic Chabant <ludovic@chabant.com>
parents: 2
diff changeset
9 def _patched_urlretrieve(url, filename=None):
2
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 return ('/retrieved/' + url.lstrip('/'), None)
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 def _patched_urlcleanup():
27543b2e73b9 Add Twitter silo.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 pass