예제 #1
0
    def test_import_trips_txt_multiple_services(self):
        '''
        If a trip is associated with several services, only one is created

        Before 0.4.0, the trip was related to both services
        After 0.4.0, the trip is related to only the first service
        '''
        trips_txt = StringIO("""\
route_id,service_id,trip_id
R1,S1,T1
R1,S2,T1
""")
        service1 = Service.objects.create(feed=self.feed,
                                          service_id='S1',
                                          start_date=date(2011, 4, 14),
                                          end_date=date(2011, 12, 31))
        service2 = Service.objects.create(feed=self.feed,
                                          service_id='S2',
                                          start_date=date(2012, 1, 1),
                                          end_date=date(2012, 4, 14))

        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()
        self.assertEqual(trip.route, self.route)
        self.assertEqual(trip.service, service1)
        self.assertFalse(service2.trip_set.exists())
예제 #2
0
    def test_import_trips_txt_maximal(self):
        trips_txt = StringIO.StringIO(
            """\
route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,\
block_id,shape_id,wheelchair_accessible,bikes_allowed
R1,S1,T1,Headsign,HS,0,B1,S1,1,2
"""
        )
        service = Service.objects.create(
            feed=self.feed, service_id="S1", start_date=date(2011, 4, 14), end_date=date(2011, 12, 31)
        )
        block = Block.objects.create(feed=self.feed, block_id="B1")
        shape = Shape.objects.create(feed=self.feed, shape_id="S1")
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()
        self.assertEqual(trip.route, self.route)
        self.assertEqual(list(trip.services.all()), [service])
        self.assertEqual(trip.trip_id, "T1")
        self.assertEqual(trip.headsign, "Headsign")
        self.assertEqual(trip.short_name, "HS")
        self.assertEqual(trip.direction, "0")
        self.assertEqual(trip.block, block)
        self.assertEqual(trip.shape, shape)
        self.assertEqual(trip.wheelchair_accessible, "1")
        self.assertEqual(trip.bikes_allowed, "2")
예제 #3
0
파일: trip.py 프로젝트: derickl/gtfs-server
    def test_import_trips_txt_duplicate(self):
        trips_txt = StringIO("""\
route_id,service_id,trip_id
R1,S1,T1
R1,S1,T1
""")
        Service.objects.create(
            feed=self.feed, service_id='S1', start_date=date(2011, 4, 14),
            end_date=date(2011, 12, 31))
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()  # Just one
        self.assertEqual(trip.trip_id, 'T1')
예제 #4
0
    def test_import_trips_txt_duplicate(self):
        trips_txt = StringIO("""\
route_id,service_id,trip_id
R1,S1,T1
R1,S1,T1
""")
        Service.objects.create(feed=self.feed,
                               service_id='S1',
                               start_date=date(2011, 4, 14),
                               end_date=date(2011, 12, 31))
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()  # Just one
        self.assertEqual(trip.trip_id, 'T1')
예제 #5
0
    def test_import_trips_txt_quoted_direction_id(self):
        '''
        A direction_id should be stripped of quotation marks

        Issue 64
        '''
        trips_txt = StringIO("""\
route_id,service_id,trip_id,shape_id,trip_headsign,direction_id
R1,"S1","T3","46-860-y11-1.2.I","Aston Quay", "1"
""")
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get(trip_id='T3')
        self.assertEqual(trip.direction, '1')
예제 #6
0
    def test_import_trips_txt_quoted_direction_id(self):
        '''
        A direction_id should be stripped of quotation marks

        Issue 64
        '''
        trips_txt = StringIO("""\
route_id,service_id,trip_id,shape_id,trip_headsign,direction_id
R1,"S1","T3","46-860-y11-1.2.I","Aston Quay", "1"
""")
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get(trip_id='T3')
        self.assertEqual(trip.direction, '1')
예제 #7
0
    def test_import_trips_txt_minimal(self):
        trips_txt = StringIO.StringIO("""\
route_id,service_id,trip_id
R1,S1,T1
""")
        service = Service.objects.create(
            feed=self.feed, service_id='S1', start_date=date(2011, 4, 14),
            end_date=date(2011, 12, 31))
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()
        self.assertEqual(trip.route, self.route)
        self.assertEqual(list(trip.services.all()), [service])
        self.assertEqual(trip.trip_id, 'T1')
        self.assertEqual(trip.headsign, '')
        self.assertEqual(trip.short_name, '')
        self.assertEqual(trip.direction, '')
        self.assertEqual(trip.block, None)
        self.assertEqual(trip.shape, None)
예제 #8
0
    def test_import_trips_txt_multiple_services(self):
        '''If a trip is associated with several services, one is created'''
        trips_txt = StringIO.StringIO("""\
route_id,service_id,trip_id
R1,S1,T1
R1,S2,T1
""")
        service1 = Service.objects.create(
            feed=self.feed, service_id='S1', start_date=date(2011, 4, 14),
            end_date=date(2011, 12, 31))
        service2 = Service.objects.create(
            feed=self.feed, service_id='S2', start_date=date(2012, 1, 1),
            end_date=date(2012, 4, 14))

        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()
        self.assertEqual(trip.route, self.route)
        self.assertEqual(trip.services.count(), 2)
        self.assertTrue(service1 in trip.services.all())
        self.assertTrue(service2 in trip.services.all())
예제 #9
0
    def test_import_trips_txt_maximal(self):
        trips_txt = StringIO.StringIO("""\
route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id,\
block_id,shape_id
R1,S1,T1,Headsign,HS,0,B1,S1
""")
        service = Service.objects.create(
            feed=self.feed, service_id='S1', start_date=date(2011, 4, 14),
            end_date=date(2011, 12, 31))
        block = Block.objects.create(feed=self.feed, block_id='B1')
        shape = Shape.objects.create(feed=self.feed, shape_id='S1')
        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()
        self.assertEqual(trip.route, self.route)
        self.assertEqual(list(trip.services.all()), [service])
        self.assertEqual(trip.trip_id, 'T1')
        self.assertEqual(trip.headsign, 'Headsign')
        self.assertEqual(trip.short_name, 'HS')
        self.assertEqual(trip.direction, '0')
        self.assertEqual(trip.block, block)
        self.assertEqual(trip.shape, shape)
예제 #10
0
파일: trip.py 프로젝트: derickl/gtfs-server
    def test_import_trips_txt_multiple_services(self):
        '''
        If a trip is associated with several services, only one is created

        Before 0.4.0, the trip was related to both services
        After 0.4.0, the trip is related to only the first service
        '''
        trips_txt = StringIO("""\
route_id,service_id,trip_id
R1,S1,T1
R1,S2,T1
""")
        service1 = Service.objects.create(
            feed=self.feed, service_id='S1', start_date=date(2011, 4, 14),
            end_date=date(2011, 12, 31))
        service2 = Service.objects.create(
            feed=self.feed, service_id='S2', start_date=date(2012, 1, 1),
            end_date=date(2012, 4, 14))

        Trip.import_txt(trips_txt, self.feed)
        trip = Trip.objects.get()
        self.assertEqual(trip.route, self.route)
        self.assertEqual(trip.service, service1)
        self.assertFalse(service2.trip_set.exists())