Skip to content

Commit

Permalink
fix for test
Browse files Browse the repository at this point in the history
  • Loading branch information
drkane committed Jan 18, 2024
1 parent 6639ca4 commit d276e95
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions findthatcharity/jinja2.py
Original file line number Diff line number Diff line change
@@ -56,6 +56,10 @@ def get_orgtypes():
return value


def orgtypes_to_dict(orgtypes):
return {o.slug: o.title for o in orgtypes.values()}


def get_sources():
cache_key = "sources"
value = cache.get(cache_key)
@@ -142,6 +146,7 @@ def environment(**options):
"a_or_an": a_or_an,
"markdown": markdownify,
"number_format": number_format,
"orgtypes_to_dict": orgtypes_to_dict,
}
)
return env
14 changes: 10 additions & 4 deletions findthatcharity/tests.py
Original file line number Diff line number Diff line change
@@ -71,15 +71,21 @@ def test_index(self):
response = self.client.get(reverse("index"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Find that Charity", html=True)
self.assertContains(response, "contains information about 3 ")
self.assertContains(response, "Registered Charity (England and Wales)")
self.assertContains(response, "Source publisher")
self.assertContains(
response,
"<p>Find that Charity contains information about 3 UK charities.</p>",
html=True,
)
self.assertContains(
response, "Registered Charity (England and Wales)", html=True
)
self.assertContains(response, "Source publisher", html=True)

def test_index_search(self):
response = self.client.get(reverse("index") + "?q=organisation")
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Find that Charity", html=True)
self.assertContains(response, "Search Results")
self.assertContains(response, "Search Results", html=True)

def test_index_search_csv(self):
response = self.client.get(reverse("index") + "?q=organisation&filetype=csv")
5 changes: 1 addition & 4 deletions ftc/jinja2/index.html.j2
Original file line number Diff line number Diff line change
@@ -128,10 +128,7 @@
{% block bodyscripts %}
<script type="text/javascript">
const AUTOCOMPLETE_URL = {{ request.build_absolute_uri(url('suggest', kwargs = { 'orgtype': 'all' })) | tojson }};
var ORGTYPES = {
{% for o in orgtypes.values() %} { { o.slug | tojson } }: { { o.title | tojson } },
{% endfor %}
}
var ORGTYPES = {{ orgtypes| orgtypes_to_dict | tojson(indent = 4) }};
</script>
<script src='{{ static("js/autocomplete.js") }}' type="text/javascript"></script>
{% endblock %}

0 comments on commit d276e95

Please sign in to comment.