def testGetFeaturedSpeaker(self):
        """ TEST: Returns the featured speakers and their registered sessions from memcache. """
        self.initDatabase()
        # Verify database fixture
        speakers = {}
        for session in Session.query():
            assert speakers.get(session.speaker.name, None) is None, \
                "This shouldn't fail. Maybe someone messed with database fixture"
            speakers[session.name] = session.key
        assert None == memcache.get(MEMCACHE_FEATURED_SPEAKER_KEY), \
            "This shouldn't fail. Maybe someone messed with database fixture"

        # Since a featured speaker was never set `getFeaturedSpeaker()` should return an empty StringMessage
        response = self.api.getFeaturedSpeaker(message_types.VoidMessage())
        assert response.data == '', 'Expected an empty string since no announcement was set'

        # Login and grab a conference owned by the current user
        self.login()
        conf = Conference.query(ancestor=ndb.Key(Profile, self.getUserId())).get()

        # Add 2 sessions with the same speaker using `createSession` endpoint
        sessions = [
            {'name': 'PHP', 'speaker': 'hitler', 'typeOfSession': 'educational',
             'date': str(conf.startDate), 'startTime': '08:00', 'duration': 60},
            {'name': 'Python', 'speaker': 'hitler', 'typeOfSession': 'educational',
             'date': str(conf.startDate), 'startTime': '12:30', 'duration': 60},
        ]
        initial_count = Session.query().count()
        for session in sessions:
            form = SessionForm(**session)
            form.is_initialized()
            container = SESSION_POST_REQUEST.combined_message_class(
                websafeConferenceKey=conf.key.urlsafe(),
                **session
            )
            self.api.createSession(container)
        count = Session.query().count()
        assert count == initial_count + 2, 'Failed to add sessions to conference...'

        tasks = self.taskqueue_stub.get_filtered_tasks()
        assert len(tasks) == 2, 'No tasks were added to queue'
        for task in tasks:
            request = webapp2.Request.blank(task.url + '?' + task.payload)
            request.method = task.method
            response = request.get_response(main.app)
            # validate http status
            assert response.status_int == 204, 'Invalid response expected 204 but got %d' % response.status_int

        # Verify featured speaker has been updated
        response = self.api.getFeaturedSpeaker(message_types.VoidMessage())
        data = response.data
        memData = memcache.get(MEMCACHE_FEATURED_SPEAKER_KEY)
        assert 'hitler' in memData and \
               'PHP' in memData and \
               'Python' in memData, 'Failed to add featured speaker to memcache'
        assert 'hitler' in data and \
               'PHP' in data and \
               'Python' in data, 'Returned an invalid featured speaker'
    def testCreateSession(self):
        """ TEST: Create a session open to the organizer of the conference"""
        self.initDatabase()
        conf = Conference.query(Conference.name == 'room #1').fetch(1)[0]

        # fill out session form fields in SESSION_POST_REQUEST
        sessionFields = {
            'name': 'Computer programming',
            'speaker': 'Donald Knuth',
            'typeOfSession': 'educational',
            'date': '2015-08-6',
            'startTime': '11:00',
            'duration': 100
        }

        form = SessionForm(**sessionFields)
        form.check_initialized()
        container = SESSION_POST_REQUEST.combined_message_class(
            websafeConferenceKey=conf.key.urlsafe(),
            **sessionFields
        )

        # get current session count
        initialCount = conf.sessions.count()

        # Attempt to add a session without being logged in
        try:
            r = self.api.createSession(container)
            assert False, 'UnauthorizedException should of been thrown...'
        except UnauthorizedException:
            pass
        # make sure a session wasn't added
        count = conf.sessions.count()
        assert count == initialCount, 'Only the organizer of the conference may create sessions'

        # Attempt to add a session with a logged in but unauthorized user.
        self.login(email='*****@*****.**')
        try:
            r = self.api.createSession(container)
            assert False, 'ForbiddenException should of been thrown...'
        except ForbiddenException:
            pass
        # make sure a session wasn't added
        count = conf.sessions.count()
        assert count == initialCount, 'Only the organizer of the conference may create sessions'

        # Finally, add session using the authorized user
        self.login(email=conf.organizerUserId)
        r = self.api.createSession(container)
        count = conf.sessions.count()
        assert count == initialCount + 1, 'Failed to add session to conference'