Пример #1
0
 def test_should_mark_valid( self ):
     response= validate_new( Mapping.view('mapping/new', descending=True) )
     self.assertEqual( 3, len( response ) )
     self.assertEqual( 1, len( response['route'] ) )
     self.assertEqual( 1, len( response['stop'] ) )
     self.assertEqual( 1, len( response['vehicle'] ) )
     status= set( m.status for m in Mapping.view('mapping/all', descending=True) )
     self.assertEqual( set(['valid']), status )
Пример #2
0
 def push_mapping( self, mapping_type, effective_date, timestamp, content_file ):
     global db
     Mapping.set_db(db)
     mapping= Mapping(
         timestamp= timestamp,
         mapping_type= mapping_type,
         effective_date= effective_date,
     )
     db.save_doc( mapping )
     if content_file is not None:
         mapping.put_attachment( content_file, name="content", content_type="text/csv" )
     return mapping
Пример #3
0
 def test_should_mark_date_ranges_and_fetch( self ):
     response1= validate_new( Mapping.view('mapping/new', descending=True) )
     self.assertEqual( 3, len( response1['route'] ) )
     status= set( m.status for m in Mapping.view('mapping/all', descending=True) )
     self.assertEqual( set(['valid']), status )
     response2= assemble_timeline( 'route' )
     self.assertEqual( 3, len( response2 ) )
     self.assertEqual( datetime.date(2012,4,1), response2[0].effective_date )
     self.assertEqual( response2[0].ending_date, response2[1].effective_date )
     self.assertEqual( response2[1].ending_date, response2[2].effective_date )
     self.assertEqual( 2200, response2[2].ending_date.year )
     response3= fetch_current( 'route', datetime.date(2012,4,2) )
     self.assertTrue( response3.effective_date <=  datetime.date(2012,4,2) < response3.ending_date)
     response4= fetch_current( 'route', datetime.date(2012,3,15) )
     self.assertIsNone( response4 )
Пример #4
0
 def test_handler_see_bad_attachment( self ):
     global db
     mappings = list( Mapping.view("mapping/new") )
     self.assertEqual( 1, len(mappings) )
     handler= mapping_attachment(mappings[0])
     self.assertEqual( set(["Invalid","Column","Names"]), set(handler.reader.fieldnames) )
     self.assertFalse( set( (Vehicle_Attachment.source_name, Vehicle_Attachment.gtf_name) ) <= set(handler.reader.fieldnames) )
Пример #5
0
 def test_should_set_mappings( self ):
     cache= {}
     mappings = refresh_mapping_cache( cache, Mapping.view('mapping/new', descending=True), today=datetime.date(2012,4,2) )
     self.assertNotIn( 'vehicle', mappings )
     self.assertNotIn( 'stop', mappings )
     self.assertIn( 'route', mappings )
     self.assertEqual( cache, mappings )
     expected= {'2': '2', '5': '17'} # route 2 on the
     self.assertEqual( expected, mappings['route'].map )
Пример #6
0
 def test_should_see_valid( self ):
     global db
     mappings = list( Mapping.view("mapping/new") )
     self.assertEqual( 3, len(mappings) )
     self.assertEqual( "route", mappings[0].mapping_type )
     self.assertTrue( validate(mappings[0]) )
     self.assertEqual( "stop", mappings[1].mapping_type )
     self.assertTrue( validate(mappings[1]) )
     self.assertEqual( "vehicle", mappings[2].mapping_type )
     self.assertTrue( validate(mappings[2]) )
Пример #7
0
 def test_should_see_duplicate( self ):
     global db
     mappings = list( Mapping.view("mapping/new") )
     self.assertEqual( 2, len(mappings) )
     self.assertTrue( validate(mappings[0]) )
     mappings[0].status= 'valid'
     mappings[0].save()
     try:
         self.assertFalse( validate( mappings[1] ) )
         self.fail( "Did not raise exception" )
     except Invalid_Mapping as ex:
         self.assertEqual( "duplicate type and effective date", ex.message )
Пример #8
0
def upload_mapping(mapping_type, effective_date, filename):
    """Upload a specific mapping file with a given effective date.

    The effective date must be a datetime.date object.

    :param mapping_type: "vehicle", "route" or "stop" mapping type
    :param effective_date: datetime.date at which this mapping becomes effective.
        Mappings remain effective until a mapping with a later effective date
        is pushed and validated.
    :param filename: a file to read and push.
    """
    Mapping.set_db(settings.db)
    mapping = Mapping(
        timestamp=datetime.datetime.fromtimestamp(os.path.getmtime(filename)),
        effective_date=effective_date,
        mapping_type=mapping_type,
    )
    settings.db.save_doc(mapping)
    with open(filename, "r") as source:
        mapping.put_attachment(source, name="content", content_type="text/csv")
    return mapping
Пример #9
0
 def test_should_see_invalid_mappings( self ):
     global db
     mappings = list( Mapping.view("mapping/new") )
     self.assertEqual( 3, len(mappings) )
     try:
         self.assertFalse( validate( mappings[0] ) )
         self.fail( "Did not raise exception" )
     except ResourceNotFound as ex:
         self.assertEqual( "Document is missing attachment", ex.message )
     try:
         self.assertFalse( validate( mappings[1] ) )
         self.fail( "Did not raise exception" )
     except Invalid_Mapping as ex:
         self.assertEqual( 'unknown type: invalid_type', ex.message )
     try:
         self.assertFalse( validate( mappings[2] ) )
         self.fail( "Did not raise exception" )
     except Invalid_Mapping as ex:
         self.assertEqual( "bad columns: ('vid', 'bus') not in ['Invalid', 'Column', 'Names']", ex.message )
Пример #10
0
 def test_should_mark_invalid( self ):
     response= validate_new( Mapping.view('mapping/new', descending=True) )
     self.assertEqual( 0, len( response ) )
     status= set( m.status for m in Mapping.view('mapping/all', descending=True) )
     expected = set( [u"bad columns: ('vid', 'bus') not in ['Invalid', 'Column', 'Names']", None, u'unknown type: invalid_type'] )
     self.assertEqual( expected, status )