예제 #1
0
    def test_import_fare_rules_txt_route(self):
        fare_rules_txt = StringIO.StringIO("""\
fare_id,route_id,origin_id,destination_id,contains_id
p,AB,,,
""")
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        FareRule.import_txt(fare_rules_txt, self.feed)
        fr = FareRule.objects.get()
        self.assertEqual(fr.fare, self.fare)
        self.assertEqual(fr.route, route)
        self.assertEqual(fr.origin, None)
        self.assertEqual(fr.destination, None)
        self.assertEqual(fr.contains, None)
예제 #2
0
    def test_import_fare_rules_txt_route(self):
        fare_rules_txt = StringIO.StringIO("""\
fare_id,route_id,origin_id,destination_id,contains_id
p,AB,,,
""")
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        FareRule.import_txt(fare_rules_txt, self.feed)
        fr = FareRule.objects.get()
        self.assertEqual(fr.fare, self.fare)
        self.assertEqual(fr.route, route)
        self.assertEqual(fr.origin, None)
        self.assertEqual(fr.destination, None)
        self.assertEqual(fr.contains, None)
예제 #3
0
    def test_import_fare_rules_txt_origin(self):
        fare_rules_txt = StringIO.StringIO("""\
fare_id,route_id,origin_id
p,,2
""")
        zone = Zone.objects.create(feed=self.feed, zone_id='2')
        FareRule.import_txt(fare_rules_txt, self.feed)
        fr = FareRule.objects.get()
        self.assertEqual(fr.fare, self.fare)
        self.assertEqual(fr.route, None)
        self.assertEqual(fr.origin, zone)
        self.assertEqual(fr.destination, None)
        self.assertEqual(fr.contains, None)
예제 #4
0
    def test_import_fare_rules_txt_origin(self):
        fare_rules_txt = StringIO.StringIO("""\
fare_id,route_id,origin_id
p,,2
""")
        zone = Zone.objects.create(feed=self.feed, zone_id='2')
        FareRule.import_txt(fare_rules_txt, self.feed)
        fr = FareRule.objects.get()
        self.assertEqual(fr.fare, self.fare)
        self.assertEqual(fr.route, None)
        self.assertEqual(fr.origin, zone)
        self.assertEqual(fr.destination, None)
        self.assertEqual(fr.contains, None)
예제 #5
0
    def test_import_fare_rules_txt_duplicate(self):
        fare_rules_txt = StringIO("""\
fare_id,route_id
p,AB
p,AB
p,CD
""")
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        route2 = Route.objects.create(feed=self.feed, route_id='CD', rtype=3)
        FareRule.import_txt(fare_rules_txt, self.feed)
        self.assertEqual(FareRule.objects.count(), 2)
        fr = FareRule.objects.get(route=route)  # Just one
        self.assertEqual(fr.fare, self.fare)
        fr = FareRule.objects.get(route=route2)
        self.assertEqual(fr.fare, self.fare)
예제 #6
0
    def test_import_fare_rules_txt_duplicate(self):
        fare_rules_txt = StringIO("""\
fare_id,route_id
p,AB
p,AB
p,CD
""")
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        route2 = Route.objects.create(feed=self.feed, route_id='CD', rtype=3)
        FareRule.import_txt(fare_rules_txt, self.feed)
        self.assertEqual(FareRule.objects.count(), 2)
        fr = FareRule.objects.get(route=route)  # Just one
        self.assertEqual(fr.fare, self.fare)
        fr = FareRule.objects.get(route=route2)
        self.assertEqual(fr.fare, self.fare)
예제 #7
0
    def test_import_fare_rules_txt_full(self):
        fare_rules_txt = StringIO.StringIO("""\
fare_id,route_id,origin_id,destination_id,contains_id
p,AB,1,2,12
""")
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        zone1 = Zone.objects.create(feed=self.feed, zone_id='1')
        zone2 = Zone.objects.create(feed=self.feed, zone_id='2')
        zone12 = Zone.objects.create(feed=self.feed, zone_id='12')
        FareRule.import_txt(fare_rules_txt, self.feed)
        fr = FareRule.objects.get()
        self.assertEqual(fr.fare, self.fare)
        self.assertEqual(fr.route, route)
        self.assertEqual(fr.origin, zone1)
        self.assertEqual(fr.destination, zone2)
        self.assertEqual(fr.contains, zone12)
예제 #8
0
    def test_import_fare_rules_txt_full(self):
        fare_rules_txt = StringIO.StringIO("""\
fare_id,route_id,origin_id,destination_id,contains_id
p,AB,1,2,12
""")
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        zone1 = Zone.objects.create(feed=self.feed, zone_id='1')
        zone2 = Zone.objects.create(feed=self.feed, zone_id='2')
        zone12 = Zone.objects.create(feed=self.feed, zone_id='12')
        FareRule.import_txt(fare_rules_txt, self.feed)
        fr = FareRule.objects.get()
        self.assertEqual(fr.fare, self.fare)
        self.assertEqual(fr.route, route)
        self.assertEqual(fr.origin, zone1)
        self.assertEqual(fr.destination, zone2)
        self.assertEqual(fr.contains, zone12)
예제 #9
0
    def test_export_fare_rules_route_id(self):
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        FareRule.objects.create(fare=self.fare, route=route)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id,route_id
p,AB
''')
예제 #10
0
    def test_export_fare_rules_contains(self):
        zone12 = Zone.objects.create(feed=self.feed, zone_id='12')
        FareRule.objects.create(fare=self.fare, contains=zone12)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id,contains_id
p,12
''')
예제 #11
0
    def test_export_fare_rules_route_id(self):
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        FareRule.objects.create(fare=self.fare, route=route)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id,route_id
p,AB
''')
예제 #12
0
    def test_export_fare_rules_degraded(self):
        # This is possible, but pointless
        FareRule.objects.create(fare=self.fare)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id
p
''')
예제 #13
0
    def test_export_fare_rules_contains(self):
        zone12 = Zone.objects.create(feed=self.feed, zone_id='12')
        FareRule.objects.create(fare=self.fare, contains=zone12)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id,contains_id
p,12
''')
예제 #14
0
    def test_export_fare_rules_degraded(self):
        # This is possible, but pointless
        FareRule.objects.create(fare=self.fare)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id
p
''')
예제 #15
0
    def test_export_fare_rules_complete(self):
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        zone1 = Zone.objects.create(feed=self.feed, zone_id='1')
        zone2 = Zone.objects.create(feed=self.feed, zone_id='2')
        zone12 = Zone.objects.create(feed=self.feed, zone_id='12')
        FareRule.objects.create(
            fare=self.fare, route=route, origin=zone1, destination=zone2,
            contains=zone12)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(fare_rules_txt, '''\
fare_id,route_id,origin_id,destination_id,contains_id
p,AB,1,2,12
''')
예제 #16
0
    def test_export_fare_rules_complete(self):
        route = Route.objects.create(feed=self.feed, route_id='AB', rtype=3)
        zone1 = Zone.objects.create(feed=self.feed, zone_id='1')
        zone2 = Zone.objects.create(feed=self.feed, zone_id='2')
        zone12 = Zone.objects.create(feed=self.feed, zone_id='12')
        FareRule.objects.create(fare=self.fare,
                                route=route,
                                origin=zone1,
                                destination=zone2,
                                contains=zone12)
        fare_rules_txt = FareRule.export_txt(self.feed)
        self.assertEqual(
            fare_rules_txt, '''\
fare_id,route_id,origin_id,destination_id,contains_id
p,AB,1,2,12
''')
예제 #17
0
 def test_export_fare_rules_empty(self):
     fare_rules_txt = FareRule.export_txt(self.feed)
     self.assertFalse(fare_rules_txt)
예제 #18
0
 def test_export_fare_rules_empty(self):
     fare_rules_txt = FareRule.export_txt(self.feed)
     self.assertFalse(fare_rules_txt)