Exemplo n.º 1
0
    def it_gets_magazines(self, client, db_session):
        create_magazine(title='title', filename='new filename')
        create_magazine(old_id='2', title='title 2', filename='new filename 2')

        response = client.get(url_for('magazines.get_magazines'),
                              headers=[('Content-Type', 'application/json'),
                                       create_authorization_header()])
        assert response.status_code == 200
        assert len(response.json) == 2
Exemplo n.º 2
0
    def it_gets_the_latest_magazine(self, client, db_session):
        create_magazine(old_id='1', title='title', filename='new filename')
        magazine = create_magazine(old_id='2',
                                   title='title 2',
                                   filename='new filename 2')

        response = client.get(url_for('magazines.get_latest_magazine',
                                      old_id=magazine.old_id),
                              headers=[('Content-Type', 'application/json'),
                                       create_authorization_header()])
        assert response.status_code == 200
        assert response.json['id'] == str(magazine.id)
Exemplo n.º 3
0
    def it_updates_a_magazine(self, mocker, client, db_session):
        magazine = create_magazine(title='title', filename='new filename')

        mocker_upload = mocker.patch(
            'app.routes.magazines.rest.upload_tasks.upload_magazine.apply_async'
        )

        data = {
            'title': 'new title',
            'filename': 'Magazine Issue 1.pdf',
            'pdf_data': 'test data',
            'topics': '',
            'tags': 'update tag'
        }

        response = client.post(url_for('magazines.update_magazine',
                                       id=magazine.id),
                               data=json.dumps(data),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])
        assert response.status_code == 200
        assert response.json['title'] == data['title']
        assert data['pdf_data'] in mocker_upload.call_args[0][0]
        magazines = dao_get_magazines()
        assert len(magazines) == 1
        magazines[0].tags == 'update tag'
Exemplo n.º 4
0
def sample_magazine_email(db):
    magazine = create_magazine(title="New mag", filename="new_mag.pdf")
    return create_email(
        magazine_id=magazine.id,
        details='<strong>Fees:</strong> 10, <strong>Concessions:</strong> 5',
        created_at='2019-06-01',
        expires='2019-07-01',
        email_type=MAGAZINE,
        email_state=APPROVED
    )
Exemplo n.º 5
0
    def it_creates_a_magazine_email(self, db_session):
        magazine = create_magazine()
        email = create_email(magazine_id=magazine.id,
                             email_type=MAGAZINE,
                             old_id=None)
        assert Email.query.count() == 1

        email_from_db = Email.query.filter(Email.id == email.id).first()

        assert email == email_from_db
        assert email_from_db.magazine_id == magazine.id
Exemplo n.º 6
0
    def it_gets_latest_magazine_email_only(self, db_session, sample_magazine):
        later_magazine = create_magazine(title='ignored magazine')
        event_email = create_email()
        create_email(email_type=MAGAZINE, magazine_id=sample_magazine.id)
        later_magazine_email = create_email(email_type=MAGAZINE,
                                            magazine_id=later_magazine.id)

        emails = dao_get_latest_emails()

        assert len(emails) == 2
        assert set([event_email, later_magazine_email]) == set(emails)
Exemplo n.º 7
0
def sample_old_emails():
    magazine = create_magazine()

    return [{
        "id":
        "1",
        "eventid":
        "-1",
        "eventdetails":
        "New Acropolis Newsletter Issue 1",
        "extratxt":
        "<a href='http://www.example.org/download.php?<member>&id=1'><img title="
        "'Click to download Issue 1' src='http://www.example.org/images/NA_Newsletter_Issue_1.pdf'></a>",
        "replaceAll":
        "n",
        "timestamp":
        "2019-01-01 10:00:00",
        "Title":
        "",
        "ImageFilename":
        "",
        "Status":
        "new",
        "limit_sending":
        "0"
    }, {
        "id": "2",
        "eventid": "1",
        "magazine_id": str(magazine.id),
        "eventdetails": "",
        "extratxt": "",
        "replaceAll": "n",
        "timestamp": "2019-02-01 11:00:00",
    }, {
        "id": "3",
        "eventid": "-2",
        "eventdetails": "Some announcement",
        "extratxt": "",
        "replaceAll": "n",
        "timestamp": "2019-03-01 11:00:00",
    }, {
        "id": "4",
        "eventid": "-2",
        "eventdetails":
        "Last chance to verify your email to restart your subscription",
        "extratxt": "",
        "replaceAll": "n",
        "timestamp": "2019-03-01 11:00:00",
    }]
Exemplo n.º 8
0
    def it_doesnt_update_a_magazine_if_filename_not_matched(
            self, client, db_session):
        magazine = create_magazine(title='title', filename='new filename')
        data = {
            'title': 'title',
            'filename': 'Magazine 1.pdf',
            'pdf_data': 'test data',
            'topics': '',
            'tags': ''
        }

        response = client.post(url_for('magazines.update_magazine',
                                       id=magazine.id),
                               data=json.dumps(data),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])
        assert response.status_code == 400
Exemplo n.º 9
0
    def it_doesnt_create_a_magazine_if_filename_already_exists(
            self, mocker, client, db_session):
        magazine = create_magazine(title='title',
                                   filename='bi_monthly_issue_1.pdf')

        data = {
            'title': 'new title',
            'filename': magazine.filename,
            'pdf_data': 'test data',
            'tags': 'Philosophy'
        }

        response = client.post(url_for('magazines.create_magazine'),
                               data=json.dumps(data),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])
        assert response.status_code == 400
        assert 'Duplicate key: duplicate key value violates unique constraint "magazines_filename_key"'\
            in response.json['message']
Exemplo n.º 10
0
    def it_updates_a_magazine_without_pdf_data(self, mocker, client,
                                               db_session):
        magazine = create_magazine(title='title', filename='new filename')

        mocker_upload = mocker.patch(
            'app.routes.magazines.rest.upload_tasks.upload_magazine.apply_async'
        )
        data = {
            'title': 'new title',
            'filename': 'Magazine Issue 1.pdf',
            'topics': 'philosophy: new world',
            'tags': 'Philosophy'
        }

        response = client.post(url_for('magazines.update_magazine',
                                       id=magazine.id),
                               data=json.dumps(data),
                               headers=[('Content-Type', 'application/json'),
                                        create_authorization_header()])
        assert response.status_code == 200
        assert response.json['id'] == str(magazine.id)
        assert response.json['title'] == data['title']
        assert response.json['topics'] == data['topics']
        assert not mocker_upload.called
Exemplo n.º 11
0
def sample_magazine(db):
    return create_magazine(
        title='Test magazine',
        filename='magazine.pdf'
    )