예제 #1
0
    def it_unsubscribes_member(self, mocker, app, client, db_session,
                               sample_member):
        mock_send_email = mocker.patch('app.routes.members.rest.send_email')
        mock_ga_event = mocker.patch('app.routes.members.rest.send_ga_event')

        unsubcode = encrypt(
            "{}={}".format(app.config['EMAIL_TOKENS']['member_id'],
                           str(sample_member.id)),
            app.config['EMAIL_UNSUB_SALT'])

        response = client.post(url_for('members.unsubscribe_member',
                                       unsubcode=unsubcode),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])

        assert not sample_member.active
        assert response.json == {
            'message': '{} unsubscribed'.format(sample_member.name)
        }
        assert mock_ga_event.called
        assert mock_send_email.called
        assert mock_send_email.call_args[0][0] == sample_member.email
        assert mock_send_email.call_args[0][
            1] == 'New Acropolis unsubscription'
        assert '{}, you have successfully unsubscribed from New Acropolis events and magazines'.format(
            sample_member.name) in mock_send_email.call_args[0][2]
예제 #2
0
    def it_gets_member_from_unsubcode(self, app, client, db_session,
                                      sample_member):
        unsubcode = encrypt(
            "{}={}".format(app.config['EMAIL_TOKENS']['member_id'],
                           str(sample_member.id)),
            app.config['EMAIL_UNSUB_SALT'])

        response = client.get(url_for('members.get_member_from_unsubcode',
                                      unsubcode=unsubcode),
                              headers=[('Content-Type', 'application/json'),
                                       create_authorization_header()])
        assert response.json['id'] == str(sample_member.id)
예제 #3
0
    def it_unsubscribes_member(self, app, client, db_session, sample_member):
        unsubcode = encrypt(
            "{}={}".format(app.config['EMAIL_TOKENS']['member_id'],
                           str(sample_member.id)),
            app.config['EMAIL_UNSUB_SALT'])

        response = client.post(url_for('members.unsubscribe_member',
                                       unsubcode=unsubcode),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])

        assert not sample_member.active
        assert response.json == {
            'message': '{} unsubscribed'.format(sample_member.name)
        }
예제 #4
0
def get_email_html(email_type, **kwargs):
    member_id = kwargs.get('member_id')
    unsubcode = encrypt(
        "{}={}".format(current_app.config['EMAIL_TOKENS']['member_id'],
                       member_id),
        current_app.config['EMAIL_UNSUB_SALT']) if member_id else None

    if email_type == EVENT:
        event = dao_get_event_by_id(kwargs.get('event_id'))
        current_app.logger.debug('Email Tokens %s',
                                 current_app.config['EMAIL_TOKENS'])
        return render_template(
            'emails/events.html',
            event=event,
            event_dates=get_nice_event_dates(event.event_dates),
            description=h.unescape(event.description),
            details=kwargs.get('details'),
            extra_txt=kwargs.get('extra_txt'),
            unsubcode=unsubcode,
            remote_access=kwargs.get('remote_access'),
            remote_pw=kwargs.get('remote_pw'),
        )
    elif email_type == MAGAZINE:
        magazine = dao_get_magazine_by_id(kwargs.get('magazine_id'))
        topics = []
        if magazine.topics:
            if all([':' in t for t in magazine.topics.split('\n')]):
                _topics = [(t.split(':')[0], t.split(':')[1])
                           for t in magazine.topics.split('\n')]
            else:
                _topics = [
                    ("Missing divider",
                     "Use : as divider between topic header and sub-header"),
                    ("Topics", magazine.topics)
                ]

            for title, description in _topics:
                topics.append({'title': title, 'description': description})
        return render_template('emails/magazine.html',
                               magazine=magazine,
                               topics=topics,
                               unsubcode=unsubcode)
    elif email_type == BASIC:
        return render_template('emails/basic.html',
                               title=kwargs.get('title', ''),
                               message=kwargs.get('message'),
                               unsubcode=unsubcode)
예제 #5
0
def get_email_html(email_type, **kwargs):
    if email_type == EVENT:
        event = dao_get_event_by_id(kwargs.get('event_id'))
        member_id = kwargs.get('member_id')
        if not member_id:
            member_id = '0'  # for preview of emails
        current_app.logger.debug('Email Tokens %s',
                                 current_app.config['EMAIL_TOKENS'])
        unsubcode = encrypt(
            "{}={}".format(current_app.config['EMAIL_TOKENS']['member_id'],
                           member_id), current_app.config['EMAIL_UNSUB_SALT'])
        return render_template('emails/events.html',
                               event=event,
                               event_dates=get_nice_event_dates(
                                   event.event_dates),
                               description=h.unescape(event.description),
                               details=kwargs.get('details'),
                               extra_txt=kwargs.get('extra_txt'),
                               unsubcode=unsubcode)
예제 #6
0
    def it_downloads_a_pdf(self, app, db_session, client, mocker, mock_storage, sample_member, sample_magazine):
        mocker.patch.dict('app.application.config', {'ENVIRONMENT': 'development'})
        enc_member_id = encrypt(
            "{}={}".format(app.config['EMAIL_TOKENS']['member_id'], str(sample_member.id)),
            app.config['EMAIL_UNSUB_SALT']
        )

        mocker.patch("app.utils.storage.Storage.get_blob", return_value=b'Test data')

        with requests_mock.mock() as r:
            r.post("http://www.google-analytics.com/collect")

            response = client.get(
                url_for('legacy.download_pdf_handler', enc=enc_member_id, id=sample_magazine.old_id)
            )
            assert r.last_request.text ==\
                "v=1&tid=1&cid=888&t=event&ec=legacy_magazine_email&ea=download&el=Test+magazine&ev=1"

        assert response.status_code == 200
        assert response.headers['Content-Disposition'] == 'attachment; filename=magazine.pdf'
예제 #7
0
    def it_updates_member(self, app, client, db_session, sample_member):
        unsubcode = encrypt(
            "{}={}".format(app.config['EMAIL_TOKENS']['member_id'],
                           str(sample_member.id)),
            app.config['EMAIL_UNSUB_SALT'])
        old_name = sample_member.name

        data = {
            'name': 'New test member',
            'email': '*****@*****.**',
        }

        response = client.post(url_for('members.update_member',
                                       unsubcode=unsubcode),
                               data=json.dumps(data),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])
        member = Member.query.one()
        assert response.json['message'] == '{} updated'.format(old_name)
        assert member.name == data['name']
        assert member.email == data['email']
예제 #8
0
 def it_encrypts_key_value(self, app):
     enc = encrypt(sample_tokens, sample_salt)
     assert enc == sample_enc
예제 #9
0
def get_unsubcode(member_id):
    unsubcode = encrypt(
        "{}={}".format(application.config['EMAIL_TOKENS']['member_id'],
                       member_id), application.config['EMAIL_UNSUB_SALT'])
    print(unsubcode)