Beispiel #1
0
def create_user_with_finished_letter(html: str = "<p>I am a letter</p>"):
    user = UserFactory()
    lr = LetterRequest(user=user,
                       mail_choice=LOC_MAILING_CHOICES.WE_WILL_MAIL,
                       html_content=html)
    lr.save()
    return user
Beispiel #2
0
 def test_it_returns_info_when_already_mailed(self):
     lr = LetterRequest()
     lr.lob_letter_object = test_lob_api.get_sample_letter()
     assert self.lob_integration(lr) == (
         'The letter was <a href="https://dashboard.lob.com/#/letters/ltr_4868c3b754655f90" '
         'rel="noreferrer noopener" target="_blank">'
         'sent via Lob</a> with the tracking number 9407300000000000000004 and has an '
         'expected delivery date of 2017-09-12.')
Beispiel #3
0
def test_letter_html_prefers_prerendered_content(client):
    zzzz = '<p>ZZZZ</p>'
    user = UserFactory()
    lr = LetterRequest(user=user,
                       mail_choice=LOC_MAILING_CHOICES.WE_WILL_MAIL,
                       html_content=zzzz)
    lr.save()
    client.force_login(user)
    assert zzzz in get_letter_html(client)
    assert zzzz not in get_letter_html(client, '?live_preview=on')
Beispiel #4
0
 def test_it_returns_info_when_already_mailed(self):
     lr = LetterRequest()
     lr.lob_letter_object = lob_fixture.SAMPLE_LETTER
     lr.tracking_number = lr.lob_letter_object["tracking_number"]
     assert self.lob_integration(lr) == (
         'The letter was <a href="https://dashboard.lob.com/#/letters/ltr_4868c3b754655f90" '
         'rel="noreferrer noopener" target="_blank">sent via Lob</a> with the '
         "tracking number <a href="
         '"https://tools.usps.com/go/TrackConfirmAction?tLabels=9407300000000000000004" '
         'rel="noreferrer noopener" target="_blank">9407300000000000000004</a> and has '
         "an expected delivery date of 2017-09-12.")
Beispiel #5
0
 def test_it_is_false_when_it_has_been_mailed_via_lob(self):
     assert LetterRequest(
         html_content='boop',
         lob_letter_object={
             'blah': 1
         },
     ).can_change_content() is False
Beispiel #6
0
def save_letter_request_form(
    data={"mail_choice": "WE_WILL_MAIL"}, form_class=LetterRequestForm, instance=None
):
    if instance is None:
        user = create_user_with_all_info()
        instance = LetterRequest(user=user)
    form = form_class(data=data, instance=instance)
    form.full_clean()
    assert form.is_valid() is True
    form.save()

    return form
Beispiel #7
0
 def test_it_is_false_when_outside_leeway_window(self):
     assert LetterRequest(created_at=timezone.make_aware(
         datetime(2001, 1, 1)),
                          html_content='boop').can_change_content() is False
Beispiel #8
0
 def test_it_is_true_when_within_leeway_window(self):
     assert LetterRequest(created_at=timezone.now(),
                          html_content='boop').can_change_content() is True
Beispiel #9
0
 def test_it_is_true_for_instances_without_created_at(self):
     assert LetterRequest(html_content='boop').can_change_content() is True
Beispiel #10
0
def test_letter_request_str_works_when_fields_are_not_set():
    info = LetterRequest()
    assert str(info) == 'LetterRequest object (None)'
Beispiel #11
0
def test_letter_request_str_works_when_fields_are_set():
    info = LetterRequest(user=UserFactory.build(),
                         created_at=datetime(2018, 1, 2))
    assert str(
        info
    ) == "Boop Jones's letter of complaint request from Tuesday, January 02 2018"
Beispiel #12
0
 def test_it_works_when_lob_integration_is_disabled(self):
     assert get_lob_nomail_reason(
         LetterRequest()) == 'Lob integration is disabled'
Beispiel #13
0
 def make(self, user, mail_choice=WE_WILL_MAIL, **kwargs):
     return LetterRequest(user=user, mail_choice=mail_choice, **kwargs)
Beispiel #14
0
 def test_it_is_false_when_it_has_been_mailed_manually(self):
     assert LetterRequest(
         html_content='boop',
         tracking_number='1234').can_change_content() is False
Beispiel #15
0
def test_loc_actions_shows_text_when_user_has_no_letter_request():
    lr = LetterRequest()
    assert LetterRequestInline.loc_actions(None, lr) == (
        'This user has not yet completed the letter of complaint process.')
Beispiel #16
0
 def test_it_is_nonempty_if_tracking_number_set(self):
     url = "https://tools.usps.com/go/TrackConfirmAction?tLabels=1234"
     assert LetterRequest(tracking_number='1234').usps_tracking_url == url
Beispiel #17
0
 def test_it_is_empty_if_tracking_number_not_set(self):
     assert LetterRequest().usps_tracking_url == ''
Beispiel #18
0
 def test_it_returns_reason_when_it_cannot_be_mailed(self):
     assert self.lob_integration(LetterRequest()) == \
         'Unable to send mail via Lob because Lob integration is disabled.'
Beispiel #19
0
 def test_it_works_when_letter_has_no_pk(self, enable_lob):
     assert get_lob_nomail_reason(
         LetterRequest()) == 'the letter has not yet been created'
Beispiel #20
0
def test_loc_actions_shows_pdf_link_when_user_has_letter_request():
    user = UserFactory()
    lr = LetterRequest(user=user)
    lr.save()
    assert f'/loc/admin/{user.pk}/letter.pdf' in LetterRequestInline.loc_actions(
        None, lr)