Ejemplo n.º 1
0
    def test_save_sermon_note(self, mock_user_get_id, mock_sermon_get_by_id):
        data = {}
        with self.assertRaisesRegexp(Exception,
                                     'notes is required and cannot be empty'):
            model.save_sermon_note(data)
        data = {'notes': 'some notes'}
        with self.assertRaisesRegexp(Exception, 'user id is required'):
            model.save_sermon_note(data)
        data = {'notes': 'some notes', 'user_key': 123}
        with self.assertRaisesRegexp(Exception, 'sermon id is required'):
            model.save_sermon_note(data)
        data = {'notes': 'some notes', 'user_key': 5360119185408000L,
                'sermon_key': 5733953138851840}

        mock_sermon_get_by_id.return_value = model.Sermon(id=5733953138851840)
        mock_user_get_id.return_value = model.User(id=5360119185408000L)
        sermon_note = model.save_sermon_note(data)
        # print sermon_note
        self.assertEquals(sermon_note.created_by.id(), data['user_key'])
        self.assertEquals(sermon_note.sermon_key.id(), data['sermon_key'])
        self.assertEquals(data['notes'], sermon_note.notes)
        mock_user_get_id.assert_called_once_with(data['user_key'])
        mock_sermon_get_by_id.assert_called_once_with(data['sermon_key'])
        data['id'] = sermon_note.key.id()
        data['notes'] = 'updated note'
        sermon_note = model.save_sermon_note(data)
        self.assertEquals(sermon_note.created_by.id(), data['user_key'])
        self.assertEquals(sermon_note.sermon_key.id(), data['sermon_key'])
        self.assertEquals(data['notes'], sermon_note.notes)
Ejemplo n.º 2
0
    def test_save_comment(self):
        data = {}
        s = model.Sermon(id=5733953138851840)
        s.id = s.put()

        data = {'comment': '  '}
        with self.assertRaisesRegexp(Exception,
                                     'comment is required and cannot be empty'):
            model.save_comment(data)
        data = {'comment': 'some comment'}
        with self.assertRaisesRegexp(Exception, 'user id is required'):
            model.save_comment(data)
        data = {'comment': 'some comment',
                'user_key': ndb.Key('User', 5360119185408000),
                'ref_key': s.key}

        comment = model.save_comment(data)
        # print sermon_note
        self.assertEquals(comment.created_by, data['user_key'])
        self.assertEquals(comment.ref_key, data['ref_key'])
        self.assertEquals(data['comment'], comment.comment)
        data = {'comment': 'some comment with reply',
                'user_key': ndb.Key('User', 5360119185408000),
                'ref_key': s.key, 'reply_to': comment.key}
        comment = model.save_comment(data)
        self.assertEquals(comment.created_by, data['user_key'])
        self.assertEquals(comment.ref_key, data['ref_key'])
        self.assertEquals(comment.comment, data['comment'])
        self.assertEquals(comment.reply_to, data['reply_to'])
Ejemplo n.º 3
0
    def test_like_sermon(self, mock_user_get, mock_sermon_get):
        user = model.User(id=123)
        sermon = model.Sermon(id=456)
        mock_user_get.return_value = user
        mock_sermon_get.return_value = sermon

        resp = model.like_sermon(456, 123)
        mock_user_get.assert_called_once_with(123)
        mock_sermon_get.assert_called_once_with(456)
        self.assertEqual([sermon.key], user.fav_sermon_keys)
        self.assertEqual(1, sermon.like_count)
Ejemplo n.º 4
0
    def test_add_church(self, mock_get_user_by_session, mock_user_get,
                        mock_sermon_get):

        user = model.User(id=123)
        sermon = model.Sermon(id=456)
        mock_user_get.return_value = user
        mock_sermon_get.return_value = sermon

        mock_get_user_by_session.return_value = {'user_id': 123}

        response = self.testapp.post('/api/sermon/456/like')
        self.assertEqual(response.status_int, 200)
        self.assertEqual([sermon.key], user.fav_sermon_keys)
        self.assertEqual(1, sermon.like_count)
Ejemplo n.º 5
0
    def test_log_sermon_view(self, mock_user_get, mock_sermon_get):
        user = model.User(id=123)
        sermon = model.Sermon(id=456)
        mock_user_get.return_value = user
        mock_sermon_get.return_value = sermon

        resp = model.log_sermon_view(456, 123)
        mock_user_get.assert_called_once_with(123)
        mock_sermon_get.assert_called_once_with(456)
        self.assertTrue(resp)
        self.assertEqual([user.key], sermon.viewers_key)
        self.assertEqual(1, sermon.view_count)

        resp = model.log_sermon_view(456, 123)
        self.assertEqual([user.key], sermon.viewers_key)
        self.assertEqual(1, sermon.view_count)
Ejemplo n.º 6
0
    def test_save_note(self, mock_sermon_get):
        # test note for existing sermon
        sermon = model.Sermon(title='test sermon')
        sermon.put()
        data = {
            'notes': 'lorem ipsum..',
            'sermon': {
                'id': sermon.key.id()
            }
        }
        user = ndb.Key('User', 1)
        note = model.save_note(user, data)
        self.assertEqual(data['notes'], note.notes)

        # test note for adhoc sermon
        data = {
            'notes': 'loremzo ipsum',
            'title': 'bla bla',
            'pastor': 'Pastor Foo Bar',
        }
        note = model.save_note(user, data)
        self.assertEqual(data['notes'], note.notes)
        self.assertEqual(data['pastor'], note.pastor)

        pastor = model.User(is_pastor=True, first_name='Foo')
        pastor.put()
        church = model.Church(name='Foo Bar')
        church.put()
        data = {
            'notes': 'loremzo ipsum',
            'title': 'bla bla',
            'pastor_id': pastor.key.id(),
            'church_id': church.key.id(),
        }
        note = model.save_note(user, data)
        self.assertEqual(data['notes'], note.notes)
        self.assertIsNone(note.sermon_key)
        self.assertIsNone(note.pastor)
        self.assertEqual(pastor.key, note.pastor_key)
        self.assertEqual(church.key, note.church_key)
Ejemplo n.º 7
0
    def test_get_feed(self):
        # create some sample feeds.
        u = model.User(first_name='foo', last_name='bar')
        u.key = u.put()
        c = model.Church(name='my church')
        c.key = c.put()
        s1 = model.Sermon(title='sermon 1', church_key=c.key, created_by=u.key)
        s1.key = s1.put()

        s2 = model.Sermon(title='sermon 2', church_key=c.key, created_by=u.key)
        s2.key = s2.put()

        s3 = model.Sermon(title='sermon 3', church_key=c.key, created_by=u.key)
        s3.key = s3.put()

        s = model.Sermon(title='sermon excl',
                         church_key=ndb.Key('Church', '999'))
        s.key = s.put()

        model.Feed(ref_key=s1.key).put()
        model.Feed(ref_key=s2.key).put()
        model.Feed(ref_key=s3.key).put()

        m = model.User(first_name='john', last_name='doe', church_key=c.key)
        m.key = m.put()

        _user = model.User.query(model.User.key == u.key).get(
            projection=[model.User.first_name, model.User.last_name,
                        model.User.title])
        # load first feed
        initial = model.get_feed(m.key.id(), page_size=1)
        data = util.model_to_dict(s3)
        data['user'] = _user
        data['kind'] = 'Sermon'
        data['comments'] = {'comments': [], 'next': None}
        self.assertEquals([data], initial['feeds'])

        # scroll to load more
        more = model.get_feed(m.key.id(), cursor=initial['next'], page_size=1)
        data = util.model_to_dict(s2)
        data['user'] = _user
        data['kind'] = 'Sermon'
        data['comments'] = {'comments': [], 'next': None}
        self.assertEquals([data], more['feeds'])

        # new feed since last fetch
        s4 = model.Sermon(title='sermon 4', church_key=c.key, created_by=u.key)
        s4.key = s4.put()

        model.Feed(ref_key=s4.key).put()

        new = model.get_feed(m.key.id(), last_time=initial['ts'], page_size=1)
        data = util.model_to_dict(s4)
        data['user'] = _user
        data['kind'] = 'Sermon'
        data['comments'] = {'comments': [], 'next': None}
        self.assertEquals([data], new['feeds'])

        # scroll to load more
        more = model.get_feed(m.key.id(), cursor=more['next'], page_size=1)
        data = util.model_to_dict(s1)
        data['user'] = _user
        data['kind'] = 'Sermon'
        data['comments'] = {'comments': [], 'next': None}
        self.assertEquals([data], more['feeds'])
        self.assertIsNone(more['next'])