from django.conf.urls import url from locations.views import LocationDetailView, LocationListView, location_detail_popup urlpatterns = [ url(r'^$', LocationListView.as_view(), name="locations-list"), url(r'^(?P<slug>[^/]+)/popup/$', location_detail_popup, name="location-detail-popup"), url(r'^(?P<slug>[^/]+)/$', LocationDetailView.as_view(), name="location-detail"), ]
def setUp(self): self.view = LocationListView()
from django.conf.urls.defaults import patterns, url from django.views.generic import DetailView from locations.models import Location from locations.views import LocationListView, LocationKMLFeed urlpatterns = patterns('', url(r'^$', view=LocationListView.as_view( template_name="locations/location_index.html", paginate_by=24, ), name="location_index"), url(r'^search/$', view=LocationListView.as_view(), name="location_list"), url(r'^locations.kml$', view=LocationKMLFeed.as_view(), name="location_kml"), url(r'^(?P<pk>[\d]+)/$', view=DetailView.as_view(queryset=Location.objects.public(), context_object_name="location"), name="location_detail"), )
class LocationSearchQuerysetTest(TestCase): fixtures = ["test_data.json"] def setUp(self): self.view = LocationListView() def test_empty_queryset(self): """Ensure that an empty queryset results in full public search""" qs = QueryDict("") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 11) def test_simple_name_search(self): """Ensure a basic search matching a name returns the location""" qs = QueryDict("search=Pooch") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 1) def test_search_matching_city(self): """Ensure a search matching city name(s) returns the locations""" qs = QueryDict("search=Arlington") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 2) def test_single_category(self): """Ensure that filtering by category returns limited locations""" restaurant = LocationCategory.objects.get(name="Restaurant") qs = QueryDict("category=%s" % restaurant.id) queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 4) def test_multiple_categories(self): """Ensure that filtering by multiple categories returns locations""" categories = "&".join( ["category=%s" % category.id for category in LocationCategory.objects.all()]) qs = QueryDict(categories) queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 11) def test_filter_postal_code(self): """Ensure that postal code can be filtered""" qs = QueryDict("postcode=22205&postcode=22150") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 3) def test_filter_state(self): """Ensure that the state can be filtered""" qs = QueryDict("state=AK&state=IL") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 2) def test_json_format(self): """Ensure that a request for JSON sends back a JSON response""" response = self.client.get("%s?format=json" % reverse("location_list")) self.assertEqual(response["Content-Type"], "application/json") def test_json_request(self): """Ensure ajax request always gets JSON""" response = self.client.get(reverse("location_list"), **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}) self.assertEqual(response["Content-Type"], "application/json") def test_results_limit(self): """Ensure results can be limited""" qs = QueryDict("limit=5") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 5)
from django.conf.urls import url from locations.views import LocationListView, ManageLocationView urlpatterns = [ url(r'(?P<location_id>[\w\-]+)/manage', ManageLocationView.as_view(), name='manage_location'), url(r'(?P<location_id>[\w\-]+)/list', LocationListView.as_view(), name='location_list'), url(r'list', LocationListView.as_view(), {'location_id': '00000000-0000-0000-0000-000000000000'}, name='location_list') ]
class LocationSearchQuerysetTest(TestCase): fixtures = ["test_data.json"] def setUp(self): self.view = LocationListView() def test_empty_queryset(self): """Ensure that an empty queryset results in full public search""" qs = QueryDict("") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 11) def test_simple_name_search(self): """Ensure a basic search matching a name returns the location""" qs = QueryDict("search=Pooch") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 1) def test_search_matching_city(self): """Ensure a search matching city name(s) returns the locations""" qs = QueryDict("search=Arlington") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 2) def test_single_category(self): """Ensure that filtering by category returns limited locations""" restaurant = LocationCategory.objects.get(name="Restaurant") qs = QueryDict("category=%s" % restaurant.id) queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 4) def test_multiple_categories(self): """Ensure that filtering by multiple categories returns locations""" categories = "&".join([ "category=%s" % category.id for category in LocationCategory.objects.all() ]) qs = QueryDict(categories) queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 11) def test_filter_postal_code(self): """Ensure that postal code can be filtered""" qs = QueryDict("postcode=22205&postcode=22150") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 3) def test_filter_state(self): """Ensure that the state can be filtered""" qs = QueryDict("state=AK&state=IL") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 2) def test_json_format(self): """Ensure that a request for JSON sends back a JSON response""" response = self.client.get("%s?format=json" % reverse("location_list")) self.assertEqual(response["Content-Type"], "application/json") def test_json_request(self): """Ensure ajax request always gets JSON""" response = self.client.get( reverse("location_list"), **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'}) self.assertEqual(response["Content-Type"], "application/json") def test_results_limit(self): """Ensure results can be limited""" qs = QueryDict("limit=5") queryset = self.view.get_queryset(qs) self.assertEqual(len(queryset), 5)
from django.conf.urls.defaults import patterns, url from django.views.generic import DetailView from locations.models import Location from locations.views import LocationListView, LocationKMLFeed urlpatterns = patterns( '', url(r'^$', view=LocationListView.as_view( template_name="locations/location_index.html", paginate_by=24, ), name="location_index"), url(r'^search/$', view=LocationListView.as_view(), name="location_list"), url(r'^locations.kml$', view=LocationKMLFeed.as_view(), name="location_kml"), url(r'^(?P<pk>[\d]+)/$', view=DetailView.as_view(queryset=Location.objects.public(), context_object_name="location"), name="location_detail"), )