def test_travelcat(self): # test getsubdests p = Place.objects.get(name="Krabi") sd = travelcat.getAllSubDestinations(p) self.assertEqual(len(sd), 1, "subdests...found " + str(len(sd))) p = Place.objects.get(name="Southern Thailand") sd = travelcat.getAllSubDestinations(p) self.assertEqual(len(sd), 5, "subdests...found " + str(len(sd))) p = Place.objects.get(name="Thailand") sd = travelcat.getAllSubDestinations(p) self.assertEqual(len(sd), 7, "subdests...found " + str(len(sd))) # test getratings p = Place.objects.get(name="Krabi") r = p.get_ratings() self.assertEqual(r.nature, 4.5) self.assertEqual(r.relaxing, 2) # search for location region = Place.objects.get(name="Thailand") self.userp.prefs.social = 5 # party animal time self.userp.prefs.relaxing = 2 self.userp.prefs.budget = 4 # this currently fails if the postgres stored proc is called. # worked around by specifying "django = True" to compute in django space; # that's not how prod works, and not really the path we want test coverage # on, but at least it's an approximation :/ dests = travelcat.get_destinations(self.userp, region, django=True) self.assertTrue( len(dests) > 1, "Only got {} dests back: {}".format(len(dests), dests)) # first item in tuple should be name # this depends on how name is formatted in get_destinations; is rather # arbitrary at moment. self.assertEqual(dests[0][ 0], "Ko Pha Ngan, Thailand", "Party animal wwanted KPNG; got " + dests[0][0]) self.userp.prefs.social = 1 # need to rest self.userp.prefs.relaxing = 4 dests = travelcat.get_destinations(self.userp, region, django=True) self.assertTrue(len(dests) > 1) # print(dests) self.assertEqual( dests[0][0], "Ko Lanta, Thailand", "expecting Ko Lanta; got " + dests[0][0])
def search_and_display_dests(request, region=None, regionid=None): ''' determine suggested destinations for current user under inpassed region, and flow to display dests page. ''' if not region: region = Place.objects.get(id=int(regionid)) dests = travelcat.get_destinations(request.user.tcuserprofile, region) if len(dests) > 1: request.session[TC_MEOW] = region.name request.session[TC_MEOWDESTS] = dests return HttpResponseRedirect(reverse('travelcat:displaydests')) else: # only one dest -- go straight to detail return HttpResponseRedirect(reverse('travelcat:placedetail', args=(dests[0][3],)))