Permalink
Browse files

fixed minor address bug; more tests

  • Loading branch information...
1 parent b156865 commit 0c71ed612bb106fcf6fbc2018e15108526142831 @evildmp committed Oct 16, 2012
Showing with 50 additions and 30 deletions.
  1. +1 −1 contacts_and_people/models.py
  2. +11 −12 contacts_and_people/tests.py
  3. +38 −17 links/tests.py
@@ -135,7 +135,7 @@ def get_postal_address(self):
if self.additional_street_address:
address.append(self.additional_street_address)
if self.site.post_town:
- address.append(self.site.post_town + " " + (self.postcode or ""))
+ address.append(" ".join((item for item in (self.site.post_town, self.postcode) if item)))
elif self.postcode:
address.append(self.postcode)
return address
@@ -1,5 +1,3 @@
-from datetime import datetime
-
from django.test import TestCase
from contacts_and_people.models import Site, Person, Building, Entity, Membership
@@ -9,7 +7,7 @@ class EntityTestObjectsMixin(object):
Create a set of inter-related objects that we'll use in a series of tests
"""
- def setUp(self):
+ def setUp(self):
# a geographical Site
self.cardiff = Site(
site_name="Main site",
@@ -55,6 +53,7 @@ def setUp(self):
parent=self.school,
slug="departments",
abstract_entity=True,
+ building=self.heart_testing_centre, # this should be ignored by everything!
)
self.departments.save()
@@ -115,7 +114,7 @@ def test_entity_get_building(self):
self.assertEquals(self.departments.get_building, None)
# the section has no Building assigned so should inherit from its parent
self.assertEquals(self.section.get_building, self.main_building)
- # the department has no Building assigned so should inherit from its parent
+ # the department has no Building assigned so should inherit from its real ancestor
self.assertEquals(self.department.get_building, self.main_building)
def test_entity_get_institutional_address(self):
@@ -136,16 +135,16 @@ def test_entity_get_full_address(self):
"""
# an entity with a building
- self.assertEquals(self.school.get_full_address, [u'Main Building', u"St Mary's Street", u'Cardiff '])
+ self.assertEquals(self.school.get_full_address, [u'Main Building', u"St Mary's Street", u'Cardiff'])
# an abstract entity has no address
self.assertEquals(self.departments.get_full_address, [])
# abstract entity is skipped in address
- self.assertEquals(self.department.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff '])
+ self.assertEquals(self.department.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff'])
# an entity that doesn't display its parent in the address
- self.assertEquals(self.student_centre.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff '])
+ self.assertEquals(self.student_centre.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff'])
# an entity with building_recapitulates_entity_name flag shares
# its name with the building & drops the 1st line of postal address
- self.assertEquals(self.testing_centre.get_full_address, [self.department, self.school, u"Queen Street", u'Cardiff '])
+ self.assertEquals(self.testing_centre.get_full_address, [self.department, self.school, u"Queen Street", u'Cardiff'])
def test_person_methods(self):
"""
@@ -187,9 +186,9 @@ def test_person_methods(self):
self.assertEquals(self.smith.get_role, smith_department_membership)
self.assertEquals(self.smith.get_entity, self.department)
self.assertEquals(self.smith.get_building, self.main_building)
- self.assertEquals(self.smith.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff '])
+ self.assertEquals(self.smith.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff'])
- # now smith have a better entity: school
+ # now smith has a better entity: school
smith_school_membership = Membership(
person=self.smith,
entity=self.school,
@@ -202,7 +201,7 @@ def test_person_methods(self):
self.assertEquals(self.smith.get_role, smith_school_membership)
self.assertEquals(self.smith.get_entity, self.school)
self.assertEquals(self.smith.get_building, self.main_building)
- self.assertEquals(self.smith.get_full_address, [u'Main Building', u"St Mary's Street", u'Cardiff '])
+ self.assertEquals(self.smith.get_full_address, [u'Main Building', u"St Mary's Street", u'Cardiff'])
# now smith's best entity will be department
smith_department_membership.importance_to_person = 5
@@ -211,6 +210,6 @@ def test_person_methods(self):
self.assertEquals(self.smith.get_role, smith_department_membership)
self.assertEquals(self.smith.get_entity, self.department)
self.assertEquals(self.smith.get_building, self.main_building)
- self.assertEquals(self.smith.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff '])
+ self.assertEquals(self.smith.get_full_address, [self.school, u'Main Building', u"St Mary's Street", u'Cardiff'])
# check that his membership of school has been downgraded by the save()
self.assertEquals(Membership.objects.get(pk=smith_school_membership.pk).importance_to_person, 4)
View
@@ -1,23 +1,44 @@
-"""
-This file demonstrates two different styles of tests (one doctest and one
-unittest). These will both pass when you run "manage.py test".
+from django.test import TestCase
-Replace these with more appropriate tests for your application.
-"""
+from django.contrib.contenttypes.models import ContentType
-from django.test import TestCase
+from cms.api import create_page, add_plugin
-class SimpleTest(TestCase):
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.failUnlessEqual(1 + 1, 2)
+from links.models import Link
-__test__ = {"doctest": """
-Another way to test that 1 + 1 is equal to 2.
+from contacts_and_people.models import Site, Person, Building, Entity, Membership
+from contacts_and_people.tests import EntityTestObjectsMixin
->>> 1 + 1 == 2
-True
-"""}
+class SearchTests(EntityTestObjectsMixin, TestCase):
+
+ def test_entity_description(self):
+
+ link_to_school = Link(
+ destination_content_type = ContentType.objects.get_for_model(self.school),
+ destination_object_id = self.school.id,
+ )
+
+ self.assertEquals(link_to_school.text(), self.school.name)
+ # home_page = create_page("title", "arkestra.html", "en", menu_title=None, slug=None, apphook=None, redirect=None, meta_description="Description")
+ #
+ #
+ # self.assertEquals(link_to_school.description(), "Description")
+
+ link_to_building = Link(
+ destination_content_type = ContentType.objects.get_for_model(self.main_building),
+ destination_object_id = self.main_building.id,
+ )
+
+ self.assertEquals(link_to_building.text(), self.main_building.get_name())
+ self.assertEquals(link_to_building.description(), u"St Mary's Street, Cardiff")
+
+ """
+ Currently autocomplete searches on description, but this isn't good enough.
+
+ Sometimes when searching in the admin, we need to return useful information for the user, such as warnings about some of the objects.
+
+ However, searching on the front end should not necessarily return warnings in the same way.
+
+ So we should have an "admin_description" (or something) attribute on which to search as well.
+ """

0 comments on commit 0c71ed6

Please sign in to comment.