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
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
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
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
def last(): """ Get the last tweet inserted on database. """ return DB.get_last(Tweet.COLLECTION)
def delete_all(): """ Delete all from model collection. """ return DB.clean_data(Tweet.COLLECTION)
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())
def setup_module(): """ Setup module seeding the MongoDB Collection. """ DB.init('tweets_test') seed_collection_with_csv(utils.get_env('DATA_FILENAME'))
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')