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()
 def create_message(self, event_json):
     """Create a message from an event."""
     event = Event.from_json(event_json)
     return Message(subject="Event {0}".format(event["event_id"]),
                    sender=self.sender,
                    recipients=self.recipients,
                    body=event_json)
 def create_message(self, event_json):
     """Create a message from an event."""
     event = Event.from_json(event_json)
     return EmailMessage(
         "Event {0}".format(event['event_id']),
         event_json, self.sender, self.recipients
     )
 def create_message(self, event_json):
     """Create a message from an event."""
     event = Event.from_json(event_json)
     return Message(subject="Event {0}".format(event["event_id"]),
                    sender=self.sender,
                    recipients=self.recipients,
                    body=event_json)
Esempio n. 5
0
def notify_system_event():
    """Sends a notification of type system"""
    event = Event(None,
                  "system",
                  "This is a system test",
                  "This is the body of the test",
                  sender="system")
    notifications.send(event)

    return "Sent event"
    def test_json_parser(self):
        """Is to_json and from_json working correctly?"""

        with self.app.test_request_context():
            json = self.event.to_json()
            event_from_parser = Event.from_json(json)

            assert event_from_parser["event_id"] == self.event["event_id"]
            assert event_from_parser["title"] == self.event["title"]
            assert event_from_parser["body"] == self.event["body"]
Esempio n. 7
0
def notify_user_event():
    """Sends a notification of type user"""
    event = Event(event_id=None,
                  event_type="user",
                  title="This is a user test",
                  body="This is the body of the test",
                  sender="john",
                  recipients=["tom", "tim"])
    notifications.send(event)

    return "Sent event"