<commit_before>import hashlib
import json
from unittest.mock import Mock
from unittest.mock import ANY

from queue_functions import do_work
from server import handle_post
from uploaders.s3 import get_url
from uploaders.s3 import upload

def test_post():
    q = Mock()
    filename = 'afakefilename'
    files = {'file': [{'body':  b'a-fake-file-body', 'filename': filename}]}

    hash_object = hashlib.md5(filename.encode())
    audio_filename = hash_object.hexdigest() + "-" + filename
    analysis_filename = audio_filename + '.analysis.json'

    result = json.dumps({'analysis': get_url(analysis_filename), 'audio': get_url(audio_filename)})
    # also need to check that we call upload
    assert result == handle_post(q, files, get_url, upload) # wait,this seems to fail half the time, wtf?
    q.enqueue.assert_called_with(do_work, (ANY, audio_filename, analysis_filename, upload))<commit_msg>test for call to enqueue passing<commit_after>import hashlib
import json
from unittest.mock import Mock
from unittest.mock import ANY

from queue_functions import do_work
from server import handle_post
from uploaders.s3 import get_url
from uploaders.s3 import upload

def test_post():
    q = Mock()
    filename = 'afakefilename'
    files = {'file': [{'body':  b'a-fake-file-body', 'filename': filename}]}

    hash_object = hashlib.md5(filename.encode())
    audio_filename = hash_object.hexdigest() + "-" + filename
    analysis_filename = audio_filename + '.analysis.json'

    expected = {'analysis': get_url(analysis_filename), 'audio': get_url(audio_filename)}
    actual = json.reads(handle_post(q, files, get_url, upload))

    q.enqueue.assert_called_with(do_work, (ANY, audio_filename, analysis_filename, upload))
    assert expected == actual
{'fraction_non_alphanumeric': 0.11041548093340922, 'fraction_numerical': 0.003414911781445646, 'mean_word_length': 4.86, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5777336', 'n_tokens_mistral': 537, 'n_tokens_neox': 527, 'n_words': 150}