Ejemplo n.º 1
0
    def test_get_with_valid_token(self, api_client):
        pending_action = PendingActionFactory(category=ActionCategory.CONFIRM_EMAIL.value)

        allow(AuthService).confirm_email.and_return(True)
        expect(AuthService).confirm_email.once()

        response = api_client.get(self.make_confirm_email_url(pending_action.token))
        assert response.status_code == status.HTTP_200_OK
Ejemplo n.º 2
0
    def test_confirm_reset_password(test_user):
        plain_password = '******'
        pending_action = PendingActionFactory(user=test_user, category=ActionCategory.RESET_PASSWORD)
        PasswordService.confirm_reset_password(pending_action, plain_password)
        updated_pending_action = PendingAction.objects.filter(pk=pending_action.pk).first()

        assert test_user.check_password(plain_password)
        assert updated_pending_action is None
def gen_pending_action(user, email=None):
    extra = {'email': email} if email else {}
    pending_action = PendingActionFactory(
        user=user,
        category=ActionCategory.CONFIRM_EMAIL.value,
        extra=extra,
    )
    return pending_action
Ejemplo n.º 4
0
 def test_get_by_token(test_pending_action_category):
     pending_action = PendingActionFactory(
         category=test_pending_action_category)
     selected_pending_action = PendingActionSelector.get_by_token(
         pending_action.token,
         test_pending_action_category,
     )
     assert selected_pending_action is not None
     assert selected_pending_action == pending_action
Ejemplo n.º 5
0
    def test_email_confirmation_valid_token(self, api_client):
        allow(AuthService).confirm_email.and_return(True)
        expect(AuthService).confirm_email.once()

        pending_action = PendingActionFactory(
            category=ActionCategory.CONFIRM_EMAIL.value)
        response = api_client.post(self.email_confirmation_url,
                                   data={'token': pending_action.token})
        response_json = response.json()
        assert response.status_code == status.HTTP_200_OK
        assert {'code', 'message'} <= set(response_json)
        assert response_json['code'] == AccountsResponses.EMAIL_VERIFIED[
            'code']
Ejemplo n.º 6
0
    def test_confirm_reset_password(self, api_client, test_user):
        pending_action = PendingActionFactory(
            user=test_user,
            category=ActionCategory.RESET_PASSWORD.value,
        )
        response = api_client.post(
            self.confirm_reset_password_url,
            data={'token': pending_action.token, 'password': '******'}
        )
        response_json = response.json()

        assert response.status_code == status.HTTP_200_OK
        assert has_response_format(response)
        assert response_json['code'] == response_codes.PASSWORD_UPDATED['code']
Ejemplo n.º 7
0
 def make_pending_action(cls):
     return PendingActionFactory(
         category=ActionCategory.RESET_PASSWORD.value)
Ejemplo n.º 8
0
 def test_send_reset_password(test_user):
     AuthEmailService.send_reset_password(
         PendingActionFactory(user=test_user,
                              category=ActionCategory.RESET_PASSWORD))
     assert mail_outbox() == 1
Ejemplo n.º 9
0
 def test_send_confirm_email(test_user):
     AuthEmailService.send_confirm_email(
         PendingActionFactory(user=test_user,
                              category=ActionCategory.CONFIRM_EMAIL))
     assert mail_outbox() == 1
Ejemplo n.º 10
0
 def test_string_representation():
     pending_action = PendingActionFactory()
     assert str(pending_action) == pending_action.token