<commit_before>import json
import pytest
from unittest import mock

import contact_manager


data = {'anna': json.dumps({
    'username': 'anna',
    'email': '<EMAIL>',
    'first_name': 'Anna',
    'last_name': 'Zander'
})}


def test_get_contact():
    mock_get = lambda _, username: data.get(username)

    with mock.patch('redis.StrictRedis.get', mock_get):
        resp_data = client.get('/api/contact/anna').get_json()
        assert 'anna' == resp_data['username']
        assert '<EMAIL>' == resp_data['email']
        assert 'Anna' == resp_data['first_name']
        assert 'Zander' == resp_data['last_name']

        assert client.get('/api/contact/barry') is 7


def test_get_all_contacts():
    all_contacts = [data, {'clare': json.dumps({
        'username': 'clare',
        'email': '<EMAIL>',
        'first_name': 'Clare',
        'last_name': 'Cuthbert'
    })}]
    assert 2 == len(client.get('/api/contacts'))


@mock.patch('redis.StrictRedis.set')
def test_create_contact(mock_set):
    client.post('/api/contact', data=data)
    assert mock_set.called_with('anna', data)


def test_delete_contact():
    expected_usernames = [['anna'], ['barry']]

    def mock_delete(_, usernames):<commit_msg>Closer to working tests<commit_after>import flask
import json
import pytest
from unittest import mock

import contact_manager


data = {'anna': json.dumps({
    'username': 'anna',
    'email': '<EMAIL>',
    'first_name': 'Anna',
    'last_name': 'Zander'
})}

app = flask.Flask(__name__)


@pytest.fixture
def client():
    flaskr.app.config['TESTING'] = True
    client = flaskr.app.test_client()

    with flaskr.app.app_context():
        flaskr.init_db()

    yield client


def test_get_contact():
    mock_get = lambda _, username: data.get(username)

    with mock.patch('redis.StrictRedis.get', mock_get):
        resp_data = client.get('/api/contact/anna').get_json()
        assert 'anna' == resp_data['username']
        assert '<EMAIL>' == resp_data['email']
        assert 'Anna' == resp_data['first_name']
        assert 'Zander' == resp_data['last_name']

        assert client.get('/api/contact/barry') is 7


def test_get_all_contacts(client):
    all_contacts = [data, {'clare': json.dumps({
        'username': 'clare',
        'email': '<EMAIL>',
        'first_name': 'Clare',
        'last_name': 'Cuthbert'
    })}]
    print(client.get('/api/contacts'))
    assert 2 == len(client.get('/api/contacts'))


@mock.patch('redis.StrictRedis.set')
def test_create_contact(mock_set):
    client.post('/api/contact', data=data)
    assert mock_set.called_with('anna', data)


def test_delete_contact():
    expected_usernames = [['anna'], ['barry']]

    def mock_delete(_, usernames):
{'fraction_non_alphanumeric': 0.1676470588235294, 'fraction_numerical': 0.0014705882352941176, 'mean_word_length': 3.557788944723618, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1556532', 'n_tokens_mistral': 943, 'n_tokens_neox': 918, 'n_words': 181}