예제 #1
0
def create_app(config_name):
    """ Create and return the flask app.
    """
    app = Flask(__name__)
    app.config.from_object(config_name)
    DB.init(app.config['MONGODB_DATABASE'])
    from tweet_tips_predictor.main import BP as main_bp
    app.register_blueprint(main_bp)
    return app
예제 #2
0
 def delete(self):
     """ Delete the tweet. """
     if self._id:
         result = DB.delete_one(collection=Tweet.COLLECTION, _id=self._id)
         self._id = None
         return result
     return False
예제 #3
0
 def insert(self):
     """ Insert data into tweets collection. """
     result = DB.insert(collection=Tweet.COLLECTION, data=self.dict())
     self._id = result.inserted_id
     if self._id:
         return result
     return False
예제 #4
0
 def update(self):
     """ Update the tweet data.  """
     if self._id:
         result = DB.find_one_and_update(collection=Tweet.COLLECTION,
                                         _id=self._id,
                                         data=self.dict())
         return result
     return False
예제 #5
0
 def last():
     """ Get the last tweet inserted on database. """
     return DB.get_last(Tweet.COLLECTION)
예제 #6
0
 def delete_all():
     """ Delete all from model collection. """
     return DB.clean_data(Tweet.COLLECTION)
예제 #7
0
 def all():
     """ Return all data from tweets. """
     return list(DB.get_all(Tweet.COLLECTION))
 def setup_class(cls):
     """ Setups the TipPredictor object for using in the test methods. """
     DB.init(utils.get_env('MONGODB_DATABASE_TEST'))
     seed_collection_with_csv(utils.get_env('DATA_FILENAME'))
     cls.predictor = TipPredictor(Tweet.all())
예제 #9
0
def setup_module():
    """ Setup module seeding the MongoDB Collection. """
    DB.init('tweets_test')
    seed_collection_with_csv(utils.get_env('DATA_FILENAME'))
예제 #10
0
def mongodb():
    """ Pass a mongodb and clean data after the test is runned."""
    DB.init(get_env('MONGODB_DATABASE_TEST'))
    yield DB
    DB.clean_data('tweets')