Skip to content

Commit

Permalink
Merge 11441a3 into ed2ed76
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-m committed Jan 28, 2021
2 parents ed2ed76 + 11441a3 commit 227e792
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions feder/institutions/factories.py
Expand Up @@ -12,6 +12,16 @@ class InstitutionFactory(factory.django.DjangoModelFactory):
class Meta:
model = Institution

@factory.post_generation
def tags(self, create, extracted, **kwargs):
if not create:
# Simple build, do nothing.
return

if extracted:
for tag in extracted:
self.tags.add(tag)


class TagFactory(factory.django.DjangoModelFactory):
name = factory.Sequence("tag-{}".format)
Expand Down
17 changes: 17 additions & 0 deletions feder/institutions/tests.py
@@ -1,3 +1,4 @@
import json
from django.urls import reverse
from django.test import RequestFactory, TestCase
from django.utils.encoding import force_text
Expand Down Expand Up @@ -177,6 +178,22 @@ def test_get_result_label_with_institution(self):
response = TagAutocomplete.as_view()(request)
self.assertContains(response, "123 (1)")

def test_get_sorted_by_name(self):
source_names = ["a2", "a3", "a1"]
tags = [TagFactory(name=name) for name in source_names]
[
InstitutionFactory.create_batch(tags=[tag], size=count)
for count, tag in enumerate(tags)
]
request = self.factory.get("/customer/details")
response = TagAutocomplete.as_view()(request)
body = json.loads(response.content)

expected_names = sorted(source_names)
result_names = [x["text"].split(" ")[0] for x in body["results"]]

self.assertListEqual(expected_names, result_names)


class SitemapTestCase(ObjectMixin, TestCase):
def test_institutions(self):
Expand Down

0 comments on commit 227e792

Please sign in to comment.