Esempio n. 1
0
    def test_stats_for_user(self):
        g.user = h.MockUser('alice', 'fooconsumer')
        Annotation({
            'user': '******',
            'consumer': 'fooconsumer',
            'uri': 'a'
        }).save()
        Annotation({
            'user': '******',
            'consumer': 'fooconsumer',
            'uri': 'a'
        }).save()
        Annotation({
            'user': '******',
            'consumer': 'fooconsumer',
            'uri': 'b'
        }).save()
        Annotation({
            'user': '******',
            'consumer': 'fooconsumer',
            'uri': 'b'
        }).save()

        Annotation.es.conn.cluster.health(wait_for_status='yellow')

        stats = Annotation.stats_for_user(g.user)
        h.assert_equal(stats['num_annotations'], 3)
        h.assert_equal(stats['num_uris'], 2)
Esempio n. 2
0
    def test_view_annotation_logged_out(self):
        a = Annotation(user='******',
                       consumer='annotateit',
                       uri='http://example.com',
                       text='This is the annotation text',
                       quote='This is what was annotated',
                       permissions={'read': []})
        a.save()

        res = self.cli.get(url_for('main.view_annotation', id=a.id))

        h.assert_equal(401, res.status_code)
Esempio n. 3
0
    def test_view_annotation_logged_out(self):
        a = Annotation(user='******',
                       consumer='annotateit',
                       uri='http://example.com',
                       text='This is the annotation text',
                       quote='This is what was annotated',
                       permissions={'read': []})
        a.save()

        res = self.cli.get(url_for('main.view_annotation', id=a.id))

        h.assert_equal(401, res.status_code)
Esempio n. 4
0
def home_for_user(username):
    if username != g.user.username:
        abort(401)

    bookmarklet = render_template('bookmarklet.js', root=request.host_url.rstrip('/'))
    annotations = Annotation.search(user=g.user.id, limit=20)
    stats = Annotation.stats_for_user(g.user)

    return render_template('user/home.html',
                           user=g.user,
                           bookmarklet=bookmarklet,
                           annotations=annotations,
                           stats=stats)
Esempio n. 5
0
    def test_view_annotation(self):
        a = Annotation(user='******',
                       consumer='annotateit',
                       uri='http://example.com',
                       text='This is the annotation text',
                       quote='This is what was annotated')
        a.save()

        self.login()
        res = self.cli.get(url_for('main.view_annotation', id=a.id))

        h.assert_in(a['user'], res.data)
        h.assert_in(a['uri'], res.data)
        h.assert_in(a['text'], res.data)
        h.assert_in(a['quote'][:25], res.data)
Esempio n. 6
0
    def test_view_annotation(self):
        a = Annotation(user='******',
                       consumer='annotateit',
                       uri='http://example.com',
                       text='This is the annotation text',
                       quote='This is what was annotated')
        a.save()

        self.login()
        res = self.cli.get(url_for('main.view_annotation', id=a.id))

        h.assert_in(a['user'], res.data)
        h.assert_in(a['uri'], res.data)
        h.assert_in(a['text'], res.data)
        h.assert_in(a['quote'][:25], res.data)
Esempio n. 7
0
    def test_stats_for_user(self):
        g.user = h.MockUser('alice', 'fooconsumer')
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'a'}).save()
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'a'}).save()
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'b'}).save()
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'b'}).save()

        Annotation.es.conn.cluster.health(wait_for_status='yellow')

        stats = Annotation.stats_for_user(g.user)
        h.assert_equal(stats['num_annotations'], 3)
        h.assert_equal(stats['num_uris'], 2)
Esempio n. 8
0
    def test_stats_for_user(self):
        g.user = h.MockUser('alice', 'fooconsumer')
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'a'}).save()
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'a'}).save()
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'b'}).save()
        Annotation({'user': '******', 'consumer': 'fooconsumer', 'uri': 'b'}).save()

        Annotation.es.conn.refresh(timesleep=0.01)

        stats = Annotation.stats_for_user(g.user)
        h.assert_equal(stats['num_annotations'], 3)
        h.assert_equal(stats['num_uris'], 2)
Esempio n. 9
0
def view_annotation(id, format=None):
    ann = Annotation.fetch(id)

    if ann is None:
        return abort(404)

    if g.authorize(ann, 'read', g.user):

        if ann['consumer'] == 'annotateit':
            user = User.fetch(ann['user'])
        else:
            user = None

        return {'annotation': ann, 'user': user}

    abort(401)
Esempio n. 10
0
def view_annotation(id, format=None):
    ann = Annotation.fetch(id)

    if ann is None:
        return abort(404)

    if g.authorize(ann, 'read', g.user):

        if ann['consumer'] == 'annotateit':
            user = User.fetch(ann['user'])
        else:
            user = None

        return {'annotation': ann, 'user': user}

    abort(401)
Esempio n. 11
0
def annotations_index():
    annotations = Annotation.search(limit=20)
    return render_template('401.html'), 401
Esempio n. 12
0
def annotations_index():
    annotations = Annotation.search(limit=20)
    return render_template('401.html'), 401