コード例 #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_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)
コード例 #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_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)
コード例 #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)