Exemplo n.º 1
0
    def testFilterRouteKeywords(self):
        testUser = User.objects.create(username='******',
                                       email='*****@*****.**',
                                       pwHash=auth.encryptPass(
                                           'james', 'password'),
                                       lastLogin=dt.now())
        testRouteOne = Route.objects.create(user=testUser,
                                            name='route 1',
                                            private=True,
                                            mapThumbnail='thumb')
        testRouteTwo = Route.objects.create(user=testUser,
                                            name='route 2',
                                            private=True,
                                            mapThumbnail='thumb')

        newWordOne = Keyword.objects.create(keyword='testWORD')
        newWordTwo = Keyword.objects.create(keyword='test123')
        HasKeyword.objects.create(keyword=newWordOne, route=testRouteOne)
        HasKeyword.objects.create(keyword=newWordTwo, route=testRouteTwo)

        routes = Route.objects.filter(user__username__iexact='james2')

        testBothWords = getHandlers.filterRouteKeywords(
            routes, 'testWORD,test123')
        testOneWord = getHandlers.filterRouteKeywords(
            routes, 'testWORD,UnusedKeyword')
        testUnusedWord = getHandlers.filterRouteKeywords(
            routes, 'UnusedKeyword')

        self.assertEqual(testBothWords.count(), 2)
        self.assertEqual(testOneWord.count(), 1)
        self.assertEqual(testUnusedWord.count(), 0)
Exemplo n.º 2
0
	def testFilterRouteKeywords(self):
		testUser = User.objects.create(username='******', email='*****@*****.**', pwHash=auth.encryptPass('james', 'password'), lastLogin=dt.now())
		testRouteOne = Route.objects.create(user=testUser, name='route 1', private=True, mapThumbnail='thumb')
		testRouteTwo = Route.objects.create(user=testUser, name='route 2', private=True, mapThumbnail='thumb')

		newWordOne = Keyword.objects.create(keyword='testWORD')
		newWordTwo = Keyword.objects.create(keyword='test123')
		HasKeyword.objects.create(keyword=newWordOne, route=testRouteOne)
		HasKeyword.objects.create(keyword=newWordTwo, route=testRouteTwo)

		routes = Route.objects.filter(user__username__iexact='james2')

		testBothWords = getHandlers.filterRouteKeywords(routes, 'testWORD,test123')
		testOneWord = getHandlers.filterRouteKeywords(routes, 'testWORD,UnusedKeyword')
		testUnusedWord = getHandlers.filterRouteKeywords(routes, 'UnusedKeyword')

		self.assertEqual(testBothWords.count(), 2)
		self.assertEqual(testOneWord.count(), 1)
		self.assertEqual(testUnusedWord.count(), 0)
Exemplo n.º 3
0
	def apply_limits(self, request, object_list):
		if request:
			my = object_list.filter(user__username__iexact=request.GET.get('user'))
			others = object_list.exclude(user__username__iexact=request.GET.get('user'))
			others = others.filter(private=False) #remove private routes from list of others' routes
			routes = (my | others).distinct()
			if request.GET.get('filterwords') != None:
				routes = getHandlers.filterRouteKeywords(routes, request.GET.get('filterwords'))
			if request.GET.get('bounds') != None:
				routes = getHandlers.routesWithinBounds(routes, request.GET.get('bounds'))
			return routes
		else:
			return object_list.none()