Beispiel #1
0
    def test_resubscribe(self):
        user_email = '*****@*****.**'
        user_password = '******'
        add_admin(user_email, user_password)

        hub = 'http://push.superfeedr.com'
        responses.add(responses.POST,
                      hub,
                      body='{"title": "Success"}',
                      status=204,
                      content_type='application/json')

        less_24 = datetime.utcnow() + relativedelta(hours=10)
        feed1 = FeedFactory(lease_end=less_24,
                            status=STATUS.SUBSCRIBED,
                            hub=hub)
        feed1.save()

        with self.app.test_client() as c:
            h = Headers()
            auth = requests.auth._basic_auth_str(user_email, user_password)
            h.add('Authorization', auth)
            url = url_for('pubsubhubbub.resubscribe')
            response = c.post(url, headers=h)
            self.assertEqual(response.status_code, 200)
Beispiel #2
0
def test_cron_update_single_user(subhandler, client, session):
    # users = User.query.all()
    # pprint(users)


    user = UserFactory(active=True)
    user2 = UserFactory(active=True)
    author = AuthorFactory()
    now = datetime.utcnow()
    entry1 = EntryFactory(published=now - timedelta(hours=5))
    entry2 = EntryFactory(published=now - timedelta(hours=3))
    entry3 = EntryFactory(published=now - timedelta(hours=26))
    entry1.authors.append(author)
    entry2.authors.append(author)
    entry3.authors.append(author)

    db.session.commit()

    sub = SubscriptionFactory(user=user, author=author, active=True)
    sub2 = SubscriptionFactory(user=user2, author=author, active=True)
    sub.add_period(PERIOD.DAILY)
    sub2.add_period(PERIOD.DAILY)

    user_email = '*****@*****.**'
    user_password = '******'
    add_admin(user_email, user_password)

    db.session.commit()

    # with client as c:
    with mail.record_messages() as outbox:
        h = Headers()
        auth = requests.auth._basic_auth_str(user_email, user_password)
        h.add('Authorization', auth)
        url = url_for('subscriptions.send_update') + '?period=Daily' + '&user_id=' + str(user.id)

        response = client.post(url, headers=h)

        assert response.status_code == 200

        assert len(outbox) == 1
        assert outbox[0].recipients[0] == user.email

        email_count = Email.query.count()
        assert email_count == 1

        email = Email.query.filter_by(
            user_id=user.id,
            period_id=Period.get_period_id(PERIOD.DAILY)).first()

        assert email.address == user.email
        assert len(email.authors) == 1
        assert len(email.entries) == 2
        TestCase().assertCountEqual(email.entries, [entry1, entry2])
        assert email.period == PERIOD.DAILY

        TestCase().assertAlmostEqual(sub.last_email_sent,
                                     datetime.utcnow(),
                                     delta=timedelta(seconds=1))
Beispiel #3
0
    def test_add_admin(self):
        email = '*****@*****.**'
        password = '******'

        add_admin(email, password)
        user = User.query.filter_by(email=email).first()
        admin_role = Role.query.filter_by(name='admin').first()

        self.assertEqual(user.email, email)
        self.assertTrue(user.active)
        self.assertIn(admin_role, user.roles)
        self.assertTrue(verify_password('password', user.password))
        self.assertTrue(verify_and_update_password(password, user))
Beispiel #4
0
    def test_author_rss_url_returns_404(self):
        admin_email = '*****@*****.**'
        admin_password = '******'
        add_admin(admin_email, admin_password)

        with self.app.test_client() as c:
            h = Headers()
            auth = requests.auth._basic_auth_str(admin_email, admin_password)
            h.add('Authorization', auth)
            response = c.get(url_for('authors.author_rss',
                                     author_id=2),
                             headers=h)

            self.assertEqual(response.status_code, 404)
Beispiel #5
0
    def test_author_rss_url(self):
        author = AuthorFactory()
        admin_email = '*****@*****.**'
        admin_password = '******'
        add_admin(admin_email, admin_password)

        with self.app.test_client() as c:
            h = Headers()
            auth = requests.auth._basic_auth_str(admin_email, admin_password)
            h.add('Authorization', auth)
            response = c.get(url_for('authors.author_rss',
                                     author_id=author.id), headers=h)

            self.assertEqual(response.status_code, 200)

            rss = feedparser.parse(response.data)

            self.assertEqual(rss.feed.title, author.name)