Esempio n. 1
0
    def test_current_user_check_watching(self):
        user = User(active=True, **self.userdata)
        self.db.session.add(user)

        watched_story = fac.story()
        user.watching.append(watched_story)
        not_watched_story = fac.story()
        save()

        r = self.auth_get('/user/watching/{0}'.format(watched_story.id))
        self.assertEqual(r.status_code, 204)

        r = self.auth_get('/user/watching/{0}'.format(not_watched_story.id))
        self.assertEqual(r.status_code, 404)
Esempio n. 2
0
    def test_get_current_user_feed(self):
        user = User(active=True, **self.userdata)
        self.db.session.add(user)

        story = fac.story()
        not_watched_story = fac.story()
        user.watching.append(story)
        save()

        r = self.auth_get('/user/feed')
        expected_event_ids = [event.id for event in story.events]
        not_expected_event_ids = [event.id for event in not_watched_story.events]
        result_event_ids = [event['id'] for event in self.json(r)]
        self.assertEqual(result_event_ids, expected_event_ids)
        self.assertNotEqual(result_event_ids, not_expected_event_ids)
Esempio n. 3
0
    def test_only_specified_types(self):
        event = fac.event()
        event.title = "Foo bar hey"
        save()

        story = fac.story()
        story.title = "Hey there foo foo foo"
        save()

        r = self.client.get('/search/foo?types=story')
        data = self.json(r)

        expected_story = {
            'id': story.id,
            'title': story.title,
            'image': story.image,
            'name': None,
            'slug': None,
            'rank': '0.0',
            'summary': story.summary,
            'updated_at': story.updated_at.isoformat(),
            'created_at': story.created_at.isoformat(),
            'type': 'story',
            'url': '/stories/{0}'.format(story.id)
        }

        self.assertEqual(data['pagination']['total_count'], 1)
        self.assertEqual(data['results'], [expected_story])
Esempio n. 4
0
 def test_GET_concept(self):
     story = fac.story()
     concept = story.concepts[0]
     r = self.client.get('/concepts/{0}'.format(concept.slug))
     expected = {
             'name': concept.name,
             'names': concept.names,
             'slug': concept.slug,
             'url': '/concepts/{0}'.format(concept.slug),
             'updated_at': concept.updated_at.isoformat(),
             'summary': concept.summary,
             'sources': concept.sources,
             'profile': {},
             'image': concept.image,
             'commonness': '100.0',
             'stories': [{
                 'id': story.id,
                 'title': story.title,
                 'updated_at': story.updated_at.isoformat(),
                 'created_at': story.created_at.isoformat(),
                 'relatedness': str(concept.score),
                 'num_events': story.num_events,
                 'url': '/stories/{0}'.format(story.id)}]
     }
     self.assertEqual(self.json(r), expected)
Esempio n. 5
0
    def test_GET_story(self):
        story = fac.story()
        users = fac.user(num=4)
        story.watchers = users
        save()

        expected_members = []
        entities = []
        expected_watchers = []
        for member in story.members:
            expected_members.append({'url': '/events/{0}'.format(member.id)})
            for entity in member.entities:
                entities.append({'url': '/entities/{0}'.format(entity.slug)})
        for user in users:
            expected_watchers.append({'url': '/users/{0}'.format(user.id)})

        # Filter down to unique entities.
        expected_entities = list({v['url']: v for v in entities}.values())

        expected = {
            'id': story.id,
            'url': '/stories/{0}'.format(story.id),
            'title': story.title,
            'summary': story.summary,
            'image': story.image,
            'updated_at': story.updated_at.isoformat(),
            'created_at': story.created_at.isoformat(),
            'events': expected_members,
            'entities': expected_entities,
            'watchers': expected_watchers
        }

        r = self.client.get('/stories/{0}'.format(story.id))

        self.assertEqual(self.json(r), expected)
Esempio n. 6
0
    def test_GET_story(self):
        story = fac.story()
        users = fac.user(num=4)
        story.watchers = users
        save()

        expected_members = []
        entities = []
        expected_watchers = []
        for member in story.members:
            expected_members.append({"url": "/events/{0}".format(member.id)})
            for entity in member.entities:
                entities.append({"url": "/entities/{0}".format(entity.slug)})
        for user in users:
            expected_watchers.append({"url": "/users/{0}".format(user.id)})

        # Filter down to unique entities.
        expected_entities = list({v["url"]: v for v in entities}.values())

        expected = {
            "id": story.id,
            "url": "/stories/{0}".format(story.id),
            "title": story.title,
            "summary": story.summary,
            "image": story.image,
            "updated_at": story.updated_at.isoformat(),
            "created_at": story.created_at.isoformat(),
            "events": expected_members,
            "entities": expected_entities,
            "watchers": expected_watchers,
        }

        r = self.client.get("/stories/{0}".format(story.id))

        self.assertEqual(self.json(r), expected)
Esempio n. 7
0
    def test_only_specified_types(self):
        event = fac.event()
        event.title = "Foo bar hey"
        save()

        story = fac.story()
        story.title = "Hey there foo foo foo"
        save()

        r = self.client.get('/search/foo?types=story')
        data = self.json(r)

        expected_story = {
            'id': story.id,
            'title': story.title,
            'image': story.image,
            'name': None,
            'slug': None,
            'rank': '0.0',
            'summary': story.summary,
            'updated_at': story.updated_at.isoformat(),
            'created_at': story.created_at.isoformat(),
            'type': 'story',
            'url': '/stories/{0}'.format(story.id)
        }

        self.assertEqual(data['pagination']['total_count'], 1)
        self.assertEqual(data['results'], [expected_story])
Esempio n. 8
0
    def test_story_clustering_with_matching_entities(self):
        # This creates a story with duplicate member events.
        story = fac.story()

        # This event is a duplicate of the story's events.
        event = fac.event()

        Story.cluster([event])
        self.assertEqual(len(story.members), 3)
Esempio n. 9
0
    def test_story_clustering_with_matching_entities(self):
        # This creates a story with duplicate member events.
        story = fac.story()

        # This event is a duplicate of the story's events.
        event = fac.event()

        Story.cluster([event])
        self.assertEqual(len(story.members), 3)
Esempio n. 10
0
 def test_delete_current_user_watching(self):
     user = User(active=True, **self.userdata)
     self.db.session.add(user)
     story = fac.story()
     user.watching.append(story)
     save()
     r = self.auth_delete('/user/watching/{0}'.format(story.id))
     self.assertEqual(r.status_code, 204)
     self.assertEqual(story.watchers, [])
     self.assertEqual(user.watching, [])
Esempio n. 11
0
    def test_post_current_user_watching_not_authenticated(self):
        user = User(active=True, **self.userdata)
        self.db.session.add(user)
        story = fac.story()
        save()

        r = self.client.post('/user/watching', data={'story_id':story.id})
        self.assertEqual(r.status_code, 401)
        self.assertEqual(story.watchers, [])
        self.assertEqual(user.watching, [])
Esempio n. 12
0
    def test_story_clustering_without_matching_entities(self):
        story = fac.story()

        # Create an event with completely different entities
        # from the story.
        article = fac.article(title='The Illiad', text='The Illiad has Argos in it.')
        event = Event([article])

        Story.cluster([event])
        self.assertEqual(len(story.members), 2)
        self.assertEqual(Story.query.count(), 2)
Esempio n. 13
0
    def test_story_entitize(self):
        story = fac.story()

        expected_entities = []
        for event in story.events:
            expected_entities += [ent.name for ent in event.entities]

        expected_entities = set(expected_entities)

        entities = {ent.name for ent in story.entities}
        self.assertEqual(entities, expected_entities)
Esempio n. 14
0
    def test_story_entitize(self):
        story = fac.story()

        expected_entities = []
        for event in story.events:
            expected_entities += [ent.name for ent in event.entities]

        expected_entities = set(expected_entities)

        entities = {ent.name for ent in story.entities}
        self.assertEqual(entities, expected_entities)
Esempio n. 15
0
    def test_story_clustering_without_matching_entities(self):
        story = fac.story()

        # Create an event with completely different entities
        # from the story.
        article = fac.article(title='The Illiad',
                              text='The Illiad has Argos in it.')
        event = Event([article])

        Story.cluster([event])
        self.assertEqual(len(story.members), 2)
        self.assertEqual(Story.query.count(), 2)
Esempio n. 16
0
    def test_POST_story_watchers(self):
        story = fac.story()
        users = fac.user(num=4)
        user = users[-1]
        story.watchers = users[:3]
        save()

        self.assertEqual(len(story.watchers), 3)

        # Login the user so we have an authenticated user.
        r = self.client.post('/test_login', data={'id': user.id})

        r = self.client.post('/stories/{0}/watchers'.format(story.id))
        self.assertEqual(len(story.watchers), 4)
Esempio n. 17
0
    def test_GET_story(self):
        story = fac.story()
        users = fac.user(num=4)
        story.watchers = users
        story.members[0].image = 'http://foo.jpg'
        story.members[1].image = 'http://foo2.jpg'
        save()

        expected_members = []
        expected_watchers = []
        expected_concepts = [{
            'slug': concept.slug,
            'url': '/concepts/{0}'.format(concept.slug),
            'score': str(concept.score)
        } for concept in story.concepts]
        expected_mentions = [{'name': alias.name, 'slug': alias.concept.slug, 'id': alias.id} for alias in story.mentions]
        for member in story.events:
            expected_members.append({
                'id': member.id,
                'url': '/events/{0}'.format(member.id),
                'title': member.title,
                'score': str(member.score),
                'updated_at': member.updated_at.isoformat(),
                'created_at': member.created_at.isoformat(),
                'num_articles': member.num_articles,
            })
        for user in users:
            expected_watchers.append({
                'id': user.id,
                'url': '/users/{0}'.format(user.id)
            })

        expected = {
                'id': story.id,
                'url': '/stories/{0}'.format(story.id),
                'title': story.title,
                'summary': story.summary_sentences,
                'image': story.image,
                'images': ['http://foo2.jpg', 'http://foo.jpg'],
                'updated_at': story.updated_at.isoformat(),
                'created_at': story.created_at.isoformat(),
                'events': expected_members,
                'concepts': expected_concepts,
                'mentions': expected_mentions,
                'watchers': expected_watchers
        }

        r = self.client.get('/stories/{0}'.format(story.id))

        self.assertEqual(self.json(r), expected)
Esempio n. 18
0
    def test_ranking(self):
        event = fac.event()
        event.title = "Foo bar hey"
        event.summary = "bar bar bar bar bar"

        story = fac.story()
        story.title = "Hey there foo"
        story.summary = "foo foo foo foo foo"
        save()

        r = self.client.get('/search/foo')
        data = self.json(r)

        self.assertEqual(data['results'][0]['title'], story.title)
Esempio n. 19
0
    def test_ranking(self):
        event = fac.event()
        event.title = "Foo bar hey"
        event.summary = "bar bar bar bar bar"

        story = fac.story()
        story.title = "Hey there foo"
        story.summary = "foo foo foo foo foo"
        save()

        r = self.client.get('/search/foo')
        data = self.json(r)

        self.assertEqual(data['results'][0]['title'], story.title)
Esempio n. 20
0
    def test_POST_story_watchers(self):
        story = fac.story()
        users = fac.user(num=4)
        user = users[-1]
        story.watchers = users[:3]
        save()

        self.assertEqual(len(story.watchers), 3)

        # Login the user so we have an authenticated user.
        r = self.client.post("/test_login", data={"id": user.id})

        r = self.client.post("/stories/{0}/watchers".format(story.id))
        self.assertEqual(len(story.watchers), 4)
Esempio n. 21
0
    def test_DELETE_story_watchers(self):
        story = fac.story()
        users = fac.user(num=3)
        user = users[0]
        story.watchers = users
        save()

        self.assertEqual(len(story.watchers), 3)

        # Login the user so we have an authenticated user.
        r = self.client.post("/test_login", data={"id": user.id})

        r = self.client.delete("/stories/{0}/watchers".format(story.id))
        self.assertEqual(len(story.watchers), 2)
        for watcher in story.watchers:
            self.assertNotEqual(watcher, user)
Esempio n. 22
0
    def test_DELETE_story_watchers(self):
        story = fac.story()
        users = fac.user(num=3)
        user = users[0]
        story.watchers = users
        save()

        self.assertEqual(len(story.watchers), 3)

        # Login the user so we have an authenticated user.
        r = self.client.post('/test_login', data={'id': user.id})

        r = self.client.delete('/stories/{0}/watchers'.format(story.id))
        self.assertEqual(len(story.watchers), 2)
        for watcher in story.watchers:
            self.assertNotEqual(watcher, user)
Esempio n. 23
0
    def test_story_conceptize(self):
        story = fac.story()

        expected_concepts = []
        expected_mentions = []
        for event in story.events:
            expected_concepts += [con.slug for con in event.concepts]
            expected_mentions += [ali.name for ali in event.mentions]

        expected_concepts = set(expected_concepts)
        expected_mentions = set(expected_mentions)

        concepts = {con.slug for con in story.concepts}
        mentions = {ali.name for ali in story.mentions}
        self.assertEqual(concepts, expected_concepts)
        self.assertEqual(mentions, expected_mentions)
Esempio n. 24
0
    def test_pagination(self):
        events = fac.event(num=20)
        for event in events:
            event.title = "Foo bar hey"
            event.summary = "foo foo foo foo foo"

        stories = fac.story(num=20)
        for story in stories:
            story.title = "Hey there foo"
            story.summary = "foo foo foo foo foo"
        save()

        r = self.client.get('/search/foo')
        data = self.json(r)

        self.assertEqual(data['pagination']['total_count'], 40)
        self.assertEqual(len(data['results']), 20)
Esempio n. 25
0
    def test_pagination(self):
        events = fac.event(num=20)
        for event in events:
            event.title = "Foo bar hey"
            event.summary = "foo foo foo foo foo"

        stories = fac.story(num=20)
        for story in stories:
            story.title = "Hey there foo"
            story.summary = "foo foo foo foo foo"
        save()

        r = self.client.get('/search/foo')
        data = self.json(r)

        self.assertEqual(data['pagination']['total_count'], 40)
        self.assertEqual(len(data['results']), 20)
Esempio n. 26
0
    def test_get_current_user_watching(self):
        user = User(active=True, **self.userdata)
        self.db.session.add(user)

        story = fac.story()
        user.watching.append(story)
        save()

        r = self.auth_get('/user/watching')

        expected_members = []
        expected_concepts = [{
            'slug': concept.slug,
            'url': '/concepts/{0}'.format(concept.slug),
            'score': str(concept.score)
        } for concept in story.concepts]
        expected_watchers = [{'url': '/users/{0}'.format(user.id), 'id': user.id}]
        expected_mentions = [{'name': alias.name, 'slug': alias.concept.slug, 'id': alias.id} for alias in story.mentions]
        for member in story.members:
            expected_members.append({
                'id': member.id,
                'title': member.title,
                'score': str(member.score),
                'updated_at': member.updated_at.isoformat(),
                'created_at': member.created_at.isoformat(),
                'num_articles': member.num_articles,
                'url': '/events/{0}'.format(member.id)
            })

        expected = {
                'id': story.id,
                'url': '/stories/{0}'.format(story.id),
                'title': story.title,
                'summary': story.summary_sentences,
                'image': story.image,
                'images': [],
                'updated_at': story.updated_at.isoformat(),
                'created_at': story.created_at.isoformat(),
                'events': expected_members,
                'concepts': expected_concepts,
                'mentions': expected_mentions,
                'watchers': expected_watchers
        }
        self.assertEqual(self.json(r), [expected])
Esempio n. 27
0
    def test_GET_story_watchers(self):
        story = fac.story()
        users = fac.user(num=3)
        story.watchers = users
        save()

        expected = []
        for user in users:
            expected.append({
                'id': user.id,
                'name': user.name,
                'image': user.image,
                'created_at': user.created_at.isoformat(),
                'updated_at': user.updated_at.isoformat()
            })

        r = self.client.get('/stories/{0}/watchers'.format(story.id))

        self.assertEqual(self.json(r), expected)
Esempio n. 28
0
    def test_GET_story_watchers(self):
        story = fac.story()
        users = fac.user(num=3)
        story.watchers = users
        save()

        expected = []
        for user in users:
            expected.append({
                'id': user.id,
                'name': user.name,
                'image': user.image,
                'created_at': user.created_at.isoformat(),
                'updated_at': user.updated_at.isoformat()
            })

        r = self.client.get('/stories/{0}/watchers'.format(story.id))

        self.assertEqual(self.json(r), expected)
Esempio n. 29
0
    def test_GET_story_watchers(self):
        story = fac.story()
        users = fac.user(num=3)
        story.watchers = users
        save()

        expected = []
        for user in users:
            expected.append(
                {
                    "id": user.id,
                    "name": user.name,
                    "image": user.image,
                    "created_at": user.created_at.isoformat(),
                    "updated_at": user.updated_at.isoformat(),
                }
            )

        r = self.client.get("/stories/{0}/watchers".format(story.id))

        self.assertEqual(self.json(r), expected)
Esempio n. 30
0
 def test_story_summarize(self):
     story = fac.story()
     self.assertTrue(story.summary)