Пример #1
0
 def test_recommended_going_query(self):
     # Creates the available journeys with driver...
     user1 = UserFactory()
     residence1 = ResidenceFactory(user=user1, position=Point(883877.34, 547084.05, srid=DEFAULT_PROJECTED_SRID))
     user2 = UserFactory()
     residence2 = ResidenceFactory(user=user2, position=Point(882823.07, 545542.48, srid=DEFAULT_PROJECTED_SRID))
     campus = CampusFactory()
     user3 = UserFactory()
     residence3 = ResidenceFactory(user=user3, position=Point(865621.24, 545274.90, srid=DEFAULT_PROJECTED_SRID))
     template = JourneyTemplateFactory(user=user1, driver=user1, residence=residence1, campus=campus)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user2, driver=user2, residence=residence2, campus=campus)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user3, driver=user3, residence=residence3, campus=campus)
     JourneyFactory(template=template)
     user4 = UserFactory()
     residence4 = ResidenceFactory(
         user=user4, position=Point(882532.74, 545437.43, srid=DEFAULT_PROJECTED_SRID), distance=2500
     )
     template = JourneyTemplateFactory(user=user4, residence=residence4, campus=campus)
     JourneyFactory(template=template)
     self.assertEquals(Journey.objects.recommended(
         user=user4,
         kind=GOING
     ).count(), 2)
Пример #2
0
 def test_get_messages(self):
     user = UserFactory()
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     journey1 = JourneyFactory(user=user,
                               residence=origin,
                               campus=destination)
     journey2 = JourneyFactory(user=user,
                               residence=origin,
                               campus=destination)
     journey3 = JourneyFactory(user=UserFactory(),
                               residence=origin,
                               campus=destination)
     [MessageFactory(user=user, journey=journey1) for _ in range(2)]
     [
         MessageFactory(user=UserFactory(), journey=journey1)
         for _ in range(2)
     ]
     [MessageFactory(user=user, journey=journey2) for _ in range(2)]
     [
         MessageFactory(user=UserFactory(), journey=journey2)
         for _ in range(2)
     ]
     [
         MessageFactory(user=UserFactory(), journey=journey3)
         for _ in range(2)
     ]
     url = "/api/v1/messages/"
     self.client.force_authenticate(user=user)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = json.loads(response.content.decode('utf-8'))
     self.assertEquals(8, len(response_data['results']))
Пример #3
0
 def test_available_going_query(self):
     # Creates the available journeys with driver...
     user1 = UserFactory()
     residence1 = ResidenceFactory(user=user1,
                                   position=Point(
                                       883877.34,
                                       547084.05,
                                       srid=DEFAULT_PROJECTED_SRID))
     user2 = UserFactory()
     residence2 = ResidenceFactory(user=user2,
                                   position=Point(
                                       882823.07,
                                       545542.48,
                                       srid=DEFAULT_PROJECTED_SRID))
     campus = CampusFactory()
     JourneyFactory(user=user1,
                    driver=user1,
                    residence=residence1,
                    campus=campus)
     JourneyFactory(user=user2,
                    driver=user2,
                    residence=residence2,
                    campus=campus)
     # Creates a journey without driver
     user3 = UserFactory()
     residence3 = ResidenceFactory(user=user3,
                                   position=Point(
                                       882454.58,
                                       545877.33,
                                       srid=DEFAULT_PROJECTED_SRID))
     JourneyFactory(user=user3, residence=residence3, campus=campus)
     self.assertEquals(
         Journey.objects.available(user=user3, kind=GOING).count(), 2)
Пример #4
0
    def test_search_form(self):
        user = UserFactory()
        JourneyFactory(departure=datetime.datetime.now() +
                       datetime.timedelta(days=2),
                       user=user,
                       driver=user)
        journey = JourneyFactory(user=user, driver=user)

        data = {
            "departure_date":
            journey.departure.date(),
            "departure_time":
            journey.departure.time(),
            "distance":
            1000,
            "time_window":
            30,
            "position":
            six.text_type(
                make_point(journey.residence.position,
                           origin_coord_srid=DEFAULT_PROJECTED_SRID,
                           destiny_coord_srid=DEFAULT_GOOGLE_MAPS_SRID))
        }
        form = SearchJourneyForm(data)
        self.assertTrue(form.is_valid())
        results = form.search(UserFactory())
        self.assertEquals(1, results.count())
Пример #5
0
 def test_recommended_journeys(self):
     # Creates the available journeys with driver...
     user1 = UserFactory()
     residence1 = ResidenceFactory(user=user1,
                                   position=Point(
                                       883877.34,
                                       547084.05,
                                       srid=DEFAULT_PROJECTED_SRID))
     user2 = UserFactory()
     residence2 = ResidenceFactory(user=user2,
                                   position=Point(
                                       882823.07,
                                       545542.48,
                                       srid=DEFAULT_PROJECTED_SRID))
     campus = CampusFactory()
     user3 = UserFactory()
     residence3 = ResidenceFactory(user=user3,
                                   position=Point(
                                       865621.24,
                                       545274.90,
                                       srid=DEFAULT_PROJECTED_SRID))
     template = JourneyTemplateFactory(user=user1,
                                       driver=user1,
                                       residence=residence1,
                                       campus=campus)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user2,
                                       driver=user2,
                                       residence=residence2,
                                       campus=campus)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user3,
                                       driver=user3,
                                       residence=residence3,
                                       campus=campus)
     JourneyFactory(template=template)
     user4 = UserFactory()
     residence4 = ResidenceFactory(user=user4,
                                   position=Point(
                                       882532.74,
                                       545437.43,
                                       srid=DEFAULT_PROJECTED_SRID),
                                   distance=2500)
     template = JourneyTemplateFactory(user=user4,
                                       residence=residence4,
                                       campus=campus)
     journey = JourneyFactory(template=template)
     # Make query...
     url = "/api/v1/journeys/{}/recommended/".format(journey.pk)
     self.client.force_authenticate(user=user4)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = json.loads(response.content.decode('utf-8'))
     self.assertEquals(2, len(response_data['results']))
Пример #6
0
 def test_destination(self):
     user = UserFactory()
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     template = JourneyTemplateFactory(user=user, residence=origin, campus=destination, kind=GOING)
     journey = JourneyFactory(template=template)
     self.assertEquals(journey.destination, destination)
Пример #7
0
 def _make_journey(user=None, kind=GOING):
     user = UserFactory() if user is None else user
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     return JourneyFactory(user=user,
                           residence=origin,
                           campus=destination,
                           kind=kind)
Пример #8
0
 def test_available_query(self):
     # Creates the available journeys with driver...
     user1 = UserFactory()
     residence1 = ResidenceFactory(user=user1, position=Point(883877.34, 547084.05, srid=DEFAULT_PROJECTED_SRID))
     user2 = UserFactory()
     residence2 = ResidenceFactory(user=user2, position=Point(882823.07, 545542.48, srid=DEFAULT_PROJECTED_SRID))
     campus = CampusFactory()
     template = JourneyTemplateFactory(user=user1, driver=user1, residence=residence1, campus=campus, kind=RETURN)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user2, driver=user2, residence=residence2, campus=campus)
     JourneyFactory(template=template)
     # Creates a journey without driver
     user3 = UserFactory()
     residence3 = ResidenceFactory(user=user3, position=Point(865621.24, 545274.90, srid=DEFAULT_PROJECTED_SRID))
     template = JourneyTemplateFactory(user=user3, residence=residence3, campus=campus, kind=RETURN)
     JourneyFactory(template=template)
     self.assertEquals(Journey.objects.available(user=user3).count(), 2)
Пример #9
0
 def test_origin(self):
     user = UserFactory()
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     journey = JourneyFactory(user=user,
                              residence=origin,
                              campus=destination,
                              kind=GOING)
     self.assertEquals(journey.origin, origin)
Пример #10
0
 def _make_journey(kind=GOING):
     user = UserFactory()
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     template = JourneyTemplateFactory(user=user,
                                       residence=origin,
                                       campus=destination,
                                       kind=kind)
     return JourneyFactory(template=template,
                           departure=template.departure,
                           arrival=template.arrival)
Пример #11
0
 def test_nearby_query(self):
     # Creates the available journeys with driver...
     user1 = UserFactory()
     residence1 = ResidenceFactory(user=user1, position=Point(883877.34, 547084.05, srid=DEFAULT_PROJECTED_SRID))
     user2 = UserFactory()
     residence2 = ResidenceFactory(user=user2, position=Point(882823.07, 545542.48, srid=DEFAULT_PROJECTED_SRID))
     campus = CampusFactory()
     user3 = UserFactory()
     residence3 = ResidenceFactory(user=user3, position=Point(865621.24, 545274.90, srid=DEFAULT_PROJECTED_SRID))
     template = JourneyTemplateFactory(user=user1, driver=user1, residence=residence1, campus=campus)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user2, driver=user2, residence=residence2, campus=campus)
     JourneyFactory(template=template)
     template = JourneyTemplateFactory(user=user3, driver=user3, residence=residence3, campus=campus)
     JourneyFactory(template=template)
     point = Point(882532.74, 545437.43, srid=DEFAULT_PROJECTED_SRID)
     self.assertEquals(Journey.objects.nearby(
         geometry=point,
         distance=D(m=2500)
     ).count(), 2)
Пример #12
0
 def test_get_messages_journey(self):
     user = UserFactory()
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     template = JourneyTemplateFactory(user=user,
                                       residence=origin,
                                       campus=destination)
     journey = JourneyFactory(template=template)
     [
         MessageFactory(
             user=UserFactory(),
             journey=JourneyFactory(template=JourneyTemplateFactory(
                 user=UserFactory(), residence=origin, campus=destination)))
         for _ in range(2)
     ]
     [MessageFactory(user=user, journey=journey) for _ in range(5)]
     [MessageFactory(user=UserFactory(), journey=journey) for _ in range(5)]
     url = "/api/v1/journeys/{}/messages/".format(journey.pk)
     self.client.force_authenticate(user=user)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     response_data = json.loads(response.content.decode('utf-8'))
     self.assertEquals(10, len(response_data['results']))
Пример #13
0
    def test_expand_september(self):
        journey = JourneyFactory()
        journey.departure = journey.departure.replace(month=9)
        journey.save()

        rule = recurrence.Rule(recurrence.DAILY)
        pattern = recurrence.Recurrence(
            dtstart=make_naive(journey.departure) + datetime.timedelta(days=1),
            dtend=make_naive(journey.departure) + datetime.timedelta(days=20),
            rrules=[
                rule,
            ])

        journey.recurrence = pattern
        journey.save()
        journeys = expand(journey)
        self.assertEquals(22, len(journeys))
Пример #14
0
 def test_create_message_owner_user(self):
     user = UserFactory()
     origin = ResidenceFactory(user=user)
     destination = CampusFactory()
     journey = JourneyFactory(user=user,
                              residence=origin,
                              campus=destination)
     self.assertEquals(0, journey.messages.count())
     data = {
         "content": "Hello!",
         "journey": journey.pk,
     }
     self.client.force_authenticate(user=user)
     url = "/api/v1/messages/"
     response = self.client.post(url, data=data)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEquals(1, journey.messages.count())