Skip to content

Commit

Permalink
fixes to make unittests work
Browse files Browse the repository at this point in the history
  • Loading branch information
kelockhart committed Sep 15, 2022
1 parent 4602d21 commit 38c2d76
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
1 change: 1 addition & 0 deletions myadsp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def task_process_myads(message):
all_audio_out = {b["title"]: b["file"] for b in audio_file_dict}
else:
audio_bib = []
all_audio_out = {}
for s in setup:
if s['frequency'] == message['frequency']:
# only return 5 results, unless it's the daily arXiv posting, then return max
Expand Down
17 changes: 0 additions & 17 deletions myadsp/templates/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@
<tr>
<td align="center" valign="top" style="width:100%;">
<h3 style="margin-top: 0;margin-right: 0;margin-bottom: 10px;margin-left: 0;">myADS - {{ frequency.capitalize() }} email ({{ date }})</h3>
{% if p.audio_files|length > 0 %}
<form method="post" action="XXX" class="inline">
<input
type="hidden"
name="sources"
value={{ p.all_audio_files }}
/>
<button
type="submit"
name="submit_param"
value="submit_value"
class="link-button"
>
Listen to all astro-ph
</button>
</form>
{% endif %}
</td>
</tr>
<tr>
Expand Down
21 changes: 20 additions & 1 deletion myadsp/templates/one_col.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
{% extends "email.html" %}
{% block payload %}
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateColumns" style="max-width: 768px;">
<tr>
{% if payload[0].all_audio_files|length > 0 %}
<form method="post" action="https://dev.adsabs.harvard.edu/audio-player" class="inline">
<input
type="hidden"
name="sources"
value={{ payload[0].all_audio_files }}
/>
<button
type="submit"
name="submit_param"
value="submit_value"
class="link-button"
>
Listen to all astro-ph
</button>
</form>
{% endif %}
</tr>
<tr>
<td align="center" valign="top" width="100%" class="templateColumnContainer">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
Expand All @@ -9,7 +28,7 @@
{% for p in payload %}
<h3><a href="{{ p.query_url.format(p.qtype, p.id) }}" title="{{ p.query }}" style="text-decoration: none; color: #000000; font-weight: bold;">{{ p.name }}</a></h3>
{% if p.audio_files|length > 0 %}
<form method="post" action="XXX" class="inline">
<form method="post" action="https://dev.adsabs.harvard.edu/audio-player" class="inline">
<input
type="hidden"
name="sources"
Expand Down
23 changes: 21 additions & 2 deletions myadsp/templates/two_col.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
{% extends "email.html" %}
{% block payload %}
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="templateColumns" style="">
<tr>
{% if left_payload[0].all_audio_files|length > 0 %}
<form method="post" action="https://dev.adsabs.harvard.edu/audio-player" class="inline">
<input
type="hidden"
name="sources"
value={{ left_payload[0].all_audio_files }}
/>
<button
type="submit"
name="submit_param"
value="submit_value"
class="link-button"
>
Listen to all astro-ph
</button>
</form>
{% endif %}
</tr>
<tr>
<td align="center" valign="top" width="50%" class="templateColumnContainer" style="border-right: 1px solid #dbdbdb;">
<table border="0" cellpadding="10" cellspacing="0" width="100%">
Expand All @@ -9,7 +28,7 @@
{% for p in left_payload %}
<h3><a href="{{ p.query_url.format(p.qtype, p.id) }}" title="{{ p.query }}" style="text-decoration: none; color: #000000; font-weight: bold;">{{ p.name }}</a></h3>
{% if p.audio_files|length > 0 %}
<form method="post" action="XXX" class="inline">
<form method="post" action="https://dev.adsabs.harvard.edu/audio-player" class="inline">
<input
type="hidden"
name="sources"
Expand Down Expand Up @@ -76,7 +95,7 @@ <h3><a href="{{ p.query_url.format(p.qtype, p.id) }}" title="{{ p.query }}" styl
{% for p in right_payload %}
<h3><a href="{{ p.query_url.format(p.qtype, p.id) }}" title="{{ p.query }}" style="text-decoration: none; color: #000000; font-weight: bold;">{{ p.name }}</a></h3>
{% if p.audio_files|length > 0 %}
<form method="post" action="XXX" class="inline">
<form method="post" action="https://dev.adsabs.harvard.edu/audio-player" class="inline">
<input
type="hidden"
name="sources"
Expand Down
28 changes: 19 additions & 9 deletions myadsp/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"year": "2012",
"bibstem": ["ApJS"]}],
'qtype': 'general',
'id': 123},
'id': 123,
'audio_files': {"Title 2012yCat..51392620N": "2012yCat..51392620N.mp3",
"Title 2012ApJS..199...26H": "2012ApJS..199...26H.mp3"},
'all_audio_files': {"Title 2012yCat..51392620N": "2012yCat..51392620N.mp3",
"Title 2012ApJS..199...26H": "2012ApJS..199...26H.mp3"}
},
{'name': 'Query 2',
'query_url': 'https://ui.adsabs.harvard.edu/search/q=bibstem%3Aarxiv?utm_source=myads&utm_medium=email&utm_campaign=type:{0}&utm_term={1}&utm_content=queryurl',
'results': [{"author_norm": ["Nantais, J", "Huchra, J"],
Expand All @@ -43,7 +48,12 @@
"year": "2012",
"bibstem": ["ApJS"]}],
'qtype': 'arXiv',
'id': 456}]
'id': 456,
'audio_files': {"2012yCat..51392620N": "2012yCat..51392620N.mp3",
"2012ApJS..199...26H": "2012ApJS..199...26H.mp3"},
'all_audio_files': {"Title 2012yCat..51392620N": "2012yCat..51392620N.mp3",
"Title 2012ApJS..199...26H": "2012ApJS..199...26H.mp3"}
}]


class TestmyADSCelery(unittest.TestCase):
Expand Down Expand Up @@ -590,19 +600,19 @@ def test_payload_to_html(self):
formatted_payload = utils.payload_to_html(payload, col=1, email_address="test@tester.com")

split_payload = formatted_payload.split('\n')
self.assertIn(u'templateColumnContainer"', split_payload[77])
self.assertEqual(split_payload[79].strip(),
self.assertIn(u'templateColumnContainer"', split_payload[93])
self.assertEqual(split_payload[98].strip(),
u'<h3><a href="https://ui.adsabs.harvard.edu/search/q=bibstem%3Aarxiv?utm_source=myads&amp;utm_medium=email&amp;utm_campaign=type:general&amp;utm_term=123&amp;utm_content=queryurl" title="" style="text-decoration: none; color: #000000; font-weight: bold;">Query 1</a></h3>')
self.assertIn(u'href="https://ui.adsabs.harvard.edu/abs/2012yCat..51392620N/abstract?utm_source=myads&amp;utm_medium=email&amp;utm_campaign=type:general&amp;utm_term=123&amp;utm_content=rank:1"', split_payload[98])

self.assertIn(u'href="https://ui.adsabs.harvard.edu/abs/2012yCat..51392620N/abstract?utm_source=myads&amp;utm_medium=email&amp;utm_campaign=type:general&amp;utm_term=123&amp;utm_content=rank:1"', split_payload[134])

formatted_payload = utils.payload_to_html(payload, col=2)

split_payload = formatted_payload.split('\n')

self.assertIn(u'class="leftColumnContent"', split_payload[77])
self.assertEqual(split_payload[79].strip(),
self.assertIn(u'class="leftColumnContent"', split_payload[96])
self.assertEqual(split_payload[98].strip(),
u'<h3><a href="https://ui.adsabs.harvard.edu/search/q=bibstem%3Aarxiv?utm_source=myads&amp;utm_medium=email&amp;utm_campaign=type:general&amp;utm_term=123&amp;utm_content=queryurl" title="" style="text-decoration: none; color: #000000; font-weight: bold;">Query 1</a></h3>')
self.assertIn(u'href="https://ui.adsabs.harvard.edu/abs/2012yCat..51392620N/abstract?utm_source=myads&amp;utm_medium=email&amp;utm_campaign=type:general&amp;utm_term=123&amp;utm_content=rank:1"', split_payload[98])
self.assertIn(u'href="https://ui.adsabs.harvard.edu/abs/2012yCat..51392620N/abstract?utm_source=myads&amp;utm_medium=email&amp;utm_campaign=type:general&amp;utm_term=123&amp;utm_content=rank:1"', split_payload[134])

formatted_payload = utils.payload_to_html(payload, col=3)
self.assertIsNone(formatted_payload)
Expand Down

0 comments on commit 38c2d76

Please sign in to comment.