<commit_before>import os
import subprocess
from requests import get, delete


def test_pre_authentication_hook(env):
    os.environ.update({
        'DO_API_KEY': env.key,
        'DO_DOMAIN': env.domain,
        'CERTBOT_DOMAIN': '%s.%s' % (env.hostname, env.domain),
        'CERTBOT_VALIDATION': env.auth_token,
    })

    record_id = subprocess.check_output('lets-do-dns')

    assert int(record_id) > 0

    request_uri = '%s/%s/records/%s' % (
        env.base_uri, env.domain, record_id)
    response = get(request_uri, headers=env.auth_header)
    record_data = response.json()['domain_record']

    assert (record_data['type'] == 'TXT' and
            record_data['name'] == env.hostname and
            record_data['data'] == env.auth_token)

    delete(request_uri, headers=env.auth_header)<commit_msg>Test Post-Authentication Hook Process Works<commit_after>import os
import subprocess
from requests import get, delete, post


def test_pre_authentication_hook(env):
    os.environ.update({
        'DO_API_KEY': env.key,
        'DO_DOMAIN': env.domain,
        'CERTBOT_DOMAIN': '%s.%s' % (env.hostname, env.domain),
        'CERTBOT_VALIDATION': env.auth_token,
    })

    record_id = subprocess.check_output('lets-do-dns')

    assert int(record_id) > 0

    request_uri = '%s/%s/records/%s' % (
        env.base_uri, env.domain, record_id)
    response = get(request_uri, headers=env.auth_header)
    record_data = response.json()['domain_record']

    assert (record_data['type'] == 'TXT' and
            record_data['name'] == env.hostname and
            record_data['data'] == env.auth_token)

    delete(request_uri, headers=env.auth_header)


def test_post_authentication_hook(env):
    create_response = post(
        '%s/%s/records' % (env.base_uri, env.domain),
        headers=env.auth_header,
        json={'type': 'TXT',
              'name': env.hostname,
              'data': env.auth_token})
    record_id = create_response.json()['domain_record']['id']

    os.environ.update({
        'DO_API_KEY': env.key,
        'DO_DOMAIN': env.domain,
        'CERTBOT_DOMAIN': '%s.%s' % (env.hostname, env.domain),
        'CERTBOT_VALIDATION': env.auth_token,
        'CERTBOT_AUTH_OUTPUT': str(record_id)
    })

    subprocess.check_call('lets-do-dns')

    request_uri = '%s/%s/records/%s' % (
        env.base_uri, env.domain, record_id)
    get_response = get(request_uri, headers=env.auth_header)

    assert get_response.status_code == 404
{'fraction_non_alphanumeric': 0.14274160938131825, 'fraction_numerical': 0.0020218358269308533, 'mean_word_length': 3.151006711409396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4612776', 'n_tokens_mistral': 856, 'n_tokens_neox': 840, 'n_words': 141}