示例#1
0
 def test_should_remove_old( self ):
     global db
     feeds = list( Feed.view("feed/old") )
     self.assertEqual( 1, len(feeds) )
     remove_old( db, today = datetime.date(2012,3,16) )
     feeds = list( Feed.view("feed/old") )
     self.assertEqual( 0, len(feeds) )
示例#2
0
 def push_feed( self, timestamp, status='new', feed_file=None ):
     global db
     Feed.set_db(db)
     feed= Feed(
         timestamp= timestamp,
         status= status,
     )
     db.save_doc( feed )
     if feed_file is not None:
         feed.put_attachment( feed_file, name="feed", content_type="text/csv" )
     return feed
示例#3
0
def upload_feed( filename ):
    """Upload a specific feed file.

    This depends on a previous invocation of :func:`config` to set
    the global database variable, :data:`settings.db`.

    :param filename: a file to read and push.
    """
    Feed.set_db(settings.db)
    feed= Feed(
        timestamp= datetime.datetime.fromtimestamp(os.path.getmtime(filename)),
        status= "new",
    )
    settings.db.save_doc( feed )
    with open(filename,'r') as source:
        feed.put_attachment( source, name="feed", content_type="text/csv" )
    return feed
示例#4
0
def upload_rtf( db, filename ):
    """Upload the Real-Time Feed from a given filename.

    The following sequence of curl requests have the same effect.

    ::

        curl -X POST http://localhost:5984/couchdbkit_test/ -H "Content-Type: application/json" -d '{"timestamp":"2012-03-02T16:16:00Z", "status":"new", "doc_type":"Feed"}'

    The response is::

        {"ok":true,"id":"09833a88a1cbb06f64c555d0245f1af3","rev":"1-7750ef2dbce77303f957de17c754852a"}

    ::

        curl -X PUT http://localhost:5984/couchdbkit_test/09833a88a1cbb06f64c555d0245f1af3/feed/?rev=1-7750ef2dbce77303f957de17c754852a -H "Content-Type: text/csv" --data-ascii @201203022302.rpt

    The response is::

        {"ok":true,"id":"09833a88a1cbb06f64c555d0245f1af3","rev":"2-748151ff136b0001671fb0fa14eb886d"}
    """
    Feed.set_db(db)
    feed = Feed(
        timestamp= datetime.datetime.fromtimestamp(os.path.getmtime(filename)),
        status = "new",
    )
    feed.save()
    with open(filename,'r') as source:
        feed.put_attachment( source, name="feed", content_type="text/csv" )
    print( feed, feed._id )
示例#5
0
 def test_should_see_bad_attachment( self ):
     global db
     feeds1 = list( Feed.view("feed/new") )
     self.assertEqual( 1, len(feeds1) )
     feeds2 = list( new_feed_iter() )
     self.assertEqual( 1, len(feeds2) )
     f, rdr= validate_and_open( feeds2[0] )
     self.assertIsNone( rdr )
     self.assertEquals( "wrong format attachment", f.status )
示例#6
0
 def test_should_process_feed( self ):
     arrivals = []
     def track_arrival( mappings, report ):
         arrivals.append( report )
     locations = []
     def track_location( mappings, report ):
         locations.append( report )
     mappings = {}
     counts= transform_new(
         mappings, new_feed_iter(),
         track_arrival, track_location,
         today=datetime.date(2012,3,15) )
     self.assertEqual( 1, counts['all'] )
     self.assertEqual( 1, counts['arrival'] )
     self.assertEqual( 0, counts['location'] )
     self.assertEqual( 1, len(arrivals) )
     self.assertEqual( 0, len(locations) )
     feeds2 = list( new_feed_iter() )
     self.assertEqual( 0, len(feeds2) )
     old = list( Feed.view('feed/old') )
     self.assertEqual( 1, len(old) )
     self.assertEqual( "processed", old[0].status )