Пример #1
0
def create_test_data():
    try:
        from tests.factories import user, user_message_info, message, admin_user

        user1 = user(email='*****@*****.**')
        umi1 = user_message_info(user=user1, info={
            'default': True,
            'prefix': 'Mr.',
            'first_name': 'Clayton',
            'last_name': 'Dunwell',
            'street_address': '2801 Quebec St NW',
            'street_address2': '',
            'city': 'Washington',
            'state': 'DC',
            'zip5': '20008',
            'phone_number': '2025551234'
        })
        msg1_1 = message(umi=umi1)
        msg1_2 = message(umi=umi1)


        # user2 = user(email='*****@*****.**')
        # umi2 = user_message_info(user=user2)
        # msg2 = message(umi=umi2)

        for i in list(range(0,100)):
            user(email=(''.join(random.choice(string.ascii_lowercase) for _ in range(10)))+'@example.com')

        admin1 = admin_user()

    except:
        print(traceback.format_exc())
Пример #2
0
def create_test_data():
    try:
        from tests.factories import user, user_message_info, message, admin_user

        user1 = user(email='*****@*****.**')
        umi1 = user_message_info(user=user1,
                                 info={
                                     'default': True,
                                     'prefix': 'Mr.',
                                     'first_name': 'Clayton',
                                     'last_name': 'Dunwell',
                                     'street_address': '2801 Quebec St NW',
                                     'street_address2': '',
                                     'city': 'Washington',
                                     'state': 'DC',
                                     'zip5': '20008',
                                     'phone_number': '2025551234'
                                 })
        msg1_1 = message(umi=umi1)
        msg1_2 = message(umi=umi1)

        # user2 = user(email='*****@*****.**')
        # umi2 = user_message_info(user=user2)
        # msg2 = message(umi=umi2)

        for i in list(range(0, 100)):
            user(email=(''.join(
                random.choice(string.ascii_lowercase)
                for _ in range(10))) + '@example.com')

        admin1 = admin_user()

    except:
        print(traceback.format_exc())
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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)