<commit_before><commit_msg>Add forgot password test<commit_after>import json

from radar_api.tests.fixtures import get_user
from radar.database import db


def test_forgot_password(app):
    user = get_user('admin')

    client = app.test_client()

    assert user.reset_password_token is None
    assert user.reset_password_date is None

    response = client.post('/forgot-password', data={
        'username': user.username,
        'email': user.email
    })

    assert response.status_code == 200

    db.session.refresh(user)

    assert user.reset_password_token is not None
    assert user.reset_password_date is not None


def test_missing_username(app):
    user = get_user('admin')

    client = app.test_client()

    response = client.post('/forgot-password', data={
        'email': user.email,
    })

    assert response.status_code == 422

    data = json.loads(response.data)

    assert data == {
        'errors': {
            'username': ['This field is required.']
        }
    }


def test_missing_email(app):
    user = get_user('admin')

    client = app.test_client()

    response = client.post('/forgot-password', data={
        'username': user.username,
    })

    assert response.status_code == 422

    data = json.loads(response.data)

    assert data == {
        'errors': {
            'email': ['This field is required.']
        }
    }


def test_user_not_found(app):
    client = app.test_client()

    response = client.post('/forgot-password', data={
        'username': '404',
        'email': '<EMAIL>',
    })

    assert response.status_code == 422

    data = json.loads(response.data)

    assert data == {
        'errors': {
            'username': ['No user found with that username and email.']
        }
    }

{'fraction_non_alphanumeric': 0.12393887945670629, 'fraction_numerical': 0.008488964346349746, 'mean_word_length': 2.557344064386318, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '813520', 'n_tokens_mistral': 553, 'n_tokens_neox': 518, 'n_words': 124}