def setUp(self): """Set up the environment before the tests.""" self.app = Flask(__name__) self.test_app = self.app.test_client() self.config = { "DEBUG": True, "TESTING": True, "CELERY_BROKER_URL": "redis://*****:*****@gmail.com" # Time variables self.tomorrow = datetime.now() + timedelta(days=1) self.next_to_tomorrow = datetime.now() + timedelta(days=2) self.next_to_next_to_tomorrow = datetime.now() + timedelta(days=3) self.next_to_tomorrow_tm = float(self.next_to_tomorrow.strftime("%s")) self.next_to_next_to_tomorrow_tm = \ float(self.next_to_next_to_tomorrow.strftime("%s")) # Create basic event to use in the tests, id randomized self.event = Event("1234", event_type="user", title="This is a test", body="This is the body of a test", sender="system", recipients=["jvican"], expiration_datetime=self.tomorrow) self.event_json = self.event.to_json()
"CELERY_ACCEPT_CONTENT": ["application/json"], "CELERY_TASK_SERIALIZER": "json", "CELERY_RESULT_SERIALIZER": "json", "REDIS_URL": redis_url, # Notifications configuration "BACKEND": "flask_notifications.backend.redis_backend.RedisBackend" } app.config.update(config) celery = FlaskCeleryExt(app).celery redis = StrictRedis(host=redis_host) # Define our notifications extension notifications = Notifications(app=app, celery=celery, broker=redis) # Define the hubs for specific types of event user_hub = notifications.create_hub("UserHub") system_hub = notifications.create_hub("EventHub") user_hub_id = user_hub.hub_id system_hub_id = system_hub.hub_id # Add a new consumer to the user_hub @user_hub.register_consumer(name="app.write_to_file") def write_to_file(event, *args, **kwargs): with open("events.log", "a+w") as f: f.write(str(event))