mirror of
https://github.com/peeringdb/peeringdb.git
synced 2024-05-11 05:55:09 +00:00
Qu1003 (#621)
* use new peeringdb client (1.0.0) for pdb_load_data sync (#599) * drop django-mobi for lack of py3/dj2 support (#492) remove django-forms-bootstrap for lack of py3/dj2 support (#492) * black formatted * django2.2 and py3 upgrade (#492) * drop ixlans (#21) ui and api changes * drop local_asn (#168) * org search (#193) * phone number validation (#50) * implement help text tooltips (#228) * Mark own ASN as transit-free (#394) * py3 fix for `pdb_migrate_ixlans` command when writing migration report * pdb_migrate_ixlans: properly handle py3 Runtime error if ixlan dict changes during iteration * set rest DEFAULT_SCHEMA_CLASS to coreapi to fix swagger apidocs fix migration 0027 missing from facsimile manifest * fix swagger doc strings * fix tests that were broken from api doc fixes * fix UniqueFieldValidator for netixlan ipaddress validation that broke during django/drf upgrade * fix org merge tool layout issues * travis config * update pipfile and lock * black formatting * update travis dist * beta mode banner (#411) * add beta banner template (#411) * automatically scheduled sync may not always be on, add a flag that lets us reflect that state in the beta banner message clean up beta banner implementation (#411) * add tests for beta banner (#411)
This commit is contained in:
@@ -21,6 +21,28 @@ class SearchTests(TestCase):
|
||||
Test quick-search functionality
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def create_instance(cls, model, org, asn=1, prefix="Test", accented=False):
|
||||
|
||||
kwargs = {}
|
||||
if model.handleref.tag == "net":
|
||||
kwargs = {"asn": asn}
|
||||
|
||||
kwargs.update(status="ok", name=u"{} {}".format(prefix, model.handleref.tag))
|
||||
|
||||
if accented:
|
||||
kwargs.update(name=u"ãccented {}".format(model.handleref.tag))
|
||||
|
||||
if model.handleref.tag != "org":
|
||||
kwargs.update(org=org)
|
||||
|
||||
instance = model.objects.create(**kwargs)
|
||||
|
||||
if model.handleref.tag == "org":
|
||||
instance.org_id = instance.id
|
||||
|
||||
return instance
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
@@ -34,32 +56,24 @@ class SearchTests(TestCase):
|
||||
|
||||
# create an instance of each searchable model, so we have something
|
||||
# to search for
|
||||
cls.org = models.Organization.objects.create(name="Test org")
|
||||
cls.org = models.Organization.objects.create(name="Parent org")
|
||||
for model in search.searchable_models:
|
||||
kwargs = {}
|
||||
if model.handleref.tag == "net":
|
||||
kwargs = {"asn": 1}
|
||||
cls.instances[model.handleref.tag] = model.objects.create(
|
||||
status="ok", org=cls.org, name="Test %s" % model.handleref.tag, **kwargs
|
||||
)
|
||||
|
||||
if model.handleref.tag == "net":
|
||||
kwargs = {"asn": 2}
|
||||
cls.instances_accented[model.handleref.tag] = model.objects.create(
|
||||
status="ok",
|
||||
org=cls.org,
|
||||
name=u"ãccented {}".format(model.handleref.tag),
|
||||
**kwargs
|
||||
cls.instances[model.handleref.tag] = cls.create_instance(model, cls.org)
|
||||
cls.instances_accented[model.handleref.tag] = cls.create_instance(
|
||||
model, cls.org, asn=2, accented=True
|
||||
)
|
||||
|
||||
# we also need to test that sponsor ship status comes through
|
||||
# accordingly
|
||||
cls.org_w_sponsorship = models.Organization.objects.create(
|
||||
name="Sponsor org", status="ok"
|
||||
name="Sponsor Parent org", status="ok"
|
||||
)
|
||||
|
||||
now = datetime.datetime.now().replace(tzinfo=models.UTC())
|
||||
|
||||
cls.sponsorship = models.Sponsorship.objects.create(
|
||||
start_date=datetime.datetime.now() - datetime.timedelta(days=1),
|
||||
end_date=datetime.datetime.now() + datetime.timedelta(days=1),
|
||||
start_date=now - datetime.timedelta(days=1),
|
||||
end_date=now + datetime.timedelta(days=1),
|
||||
level=1,
|
||||
)
|
||||
models.SponsorshipOrganization.objects.create(
|
||||
@@ -67,15 +81,8 @@ class SearchTests(TestCase):
|
||||
)
|
||||
|
||||
for model in search.searchable_models:
|
||||
if model.handleref.tag == "net":
|
||||
kwargs = {"asn": 3}
|
||||
else:
|
||||
kwargs = {}
|
||||
cls.instances_sponsored[model.handleref.tag] = model.objects.create(
|
||||
status="ok",
|
||||
org=cls.org_w_sponsorship,
|
||||
name="Sponsor %s" % model.handleref.tag,
|
||||
**kwargs
|
||||
cls.instances_sponsored[model.handleref.tag] = cls.create_instance(
|
||||
model, cls.org_w_sponsorship, asn=3, prefix="Sponsor"
|
||||
)
|
||||
|
||||
def test_search(self):
|
||||
@@ -85,7 +92,7 @@ class SearchTests(TestCase):
|
||||
"""
|
||||
|
||||
rv = search.search("Test")
|
||||
for k, inst in self.instances.items():
|
||||
for k, inst in list(self.instances.items()):
|
||||
assert k in rv
|
||||
assert len(rv[k]) == 1
|
||||
assert rv[k][0]["name"] == inst.search_result_name
|
||||
@@ -110,10 +117,11 @@ class SearchTests(TestCase):
|
||||
request = factory.get("/search", {"q": "Sponsor"})
|
||||
response = views.request_search(request)
|
||||
m = re.findall(
|
||||
re.escape('<a href="/sponsors" class="sponsor silver">'), response.content
|
||||
re.escape('<a href="/sponsors" class="sponsor silver">'),
|
||||
response.content.decode(),
|
||||
)
|
||||
|
||||
assert len(m) == 3
|
||||
assert len(m) == 4
|
||||
|
||||
def test_search_case(self):
|
||||
"""
|
||||
@@ -121,7 +129,7 @@ class SearchTests(TestCase):
|
||||
instances we created during setUp since matching is case-insensitive
|
||||
"""
|
||||
rv = search.search("test")
|
||||
for k, inst in self.instances.items():
|
||||
for k, inst in list(self.instances.items()):
|
||||
assert k in rv
|
||||
assert len(rv[k]) == 1
|
||||
assert rv[k][0]["name"] == inst.search_result_name
|
||||
@@ -163,16 +171,16 @@ class SearchTests(TestCase):
|
||||
search for entities containing 'ãccented' using accented and unaccented
|
||||
terms
|
||||
"""
|
||||
rv = search.search(u"accented")
|
||||
for k, inst in self.instances_accented.items():
|
||||
rv = search.search("accented")
|
||||
for k, inst in list(self.instances_accented.items()):
|
||||
assert k in rv
|
||||
assert len(rv[k]) == 1
|
||||
assert unidecode.unidecode(rv[k][0]["name"]) == unidecode.unidecode(
|
||||
inst.search_result_name
|
||||
)
|
||||
|
||||
rv = search.search(u"ãccented")
|
||||
for k, inst in self.instances_accented.items():
|
||||
rv = search.search("ãccented")
|
||||
for k, inst in list(self.instances_accented.items()):
|
||||
assert k in rv
|
||||
assert len(rv[k]) == 1
|
||||
assert unidecode.unidecode(rv[k][0]["name"]) == unidecode.unidecode(
|
||||
|
||||
Reference in New Issue
Block a user