<commit_before>from hashlib import md5
from mock import patch
from os import path as ospath
from random import choice
from regparser.web.jobs.models import job_status_values
from regparser.web.jobs.utils import (
    eregs_site_api_url,
    file_url,
    status_url
)
from regparser.web.jobs.views import FileUploadView as PatchedFileUploadView
from rest_framework.test import APITestCase
from string import hexdigits
from tempfile import NamedTemporaryFile

import pytest
import settings

try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse

fake_pipeline_id = "f726e1e0-d43c-4eb7-9274-681ddaba427a"
fake_email_id = "4774f0f6-b53e-4b34-821e-fc8ae5e113fe"


def fake_getter(attrname):
    return attrname


def fake_add_redis_data_to_job_data(job_data):
    return job_data


def fake_delete_eregs_job(job_id):
    return None


def fake_redis_job(args, timeout=60*30, result_ttl=-1):
    return type("FakeRedisJob", (object, ), {"id": fake_pipeline_id})


def fake_queue_email(job, statusurl, email_address):
    return fake_email_id


# Even though these functions are in the ``utils`` module, the code paths we're
# following mean we're encountering them in the ``views`` namespace:
@patch("regparser.web.jobs.views.add_redis_data_to_job_data",
       fake_add_redis_data_to_job_data)
@patch("regparser.web.jobs.views.delete_eregs_job", fake_delete_eregs_job)
@patch("regparser.web.jobs.views.queue_eregs_job", fake_redis_job)
@patch("regparser.web.jobs.views.queue_notification_email", fake_queue_email)
class PipelineJobTestCase(APITestCase):

    defaults = {
        "clear_cache": False,
        "destination": eregs_site_api_url,
        "use_uploaded_metadata": None,
        "use_uploaded_regulation": None,
        "regulation_url": "",
        "status": "received"
    }

    def _postjson(self, data):
        return self.client.post("/rp/job/pipeline/", data, format="json")

    def _stock_response_check(self, expected, actual):
        """
        Since we're using a lot of fake values, the tests for them will always
        be the same.<commit_msg>Web API: per CM's suggestion, move some class properties to instance properties.<commit_after>from hashlib import md5
from mock import patch
from os import path as ospath
from random import choice
from regparser.web.jobs.models import job_status_values
from regparser.web.jobs.utils import (
    eregs_site_api_url,
    file_url,
    status_url
)
from regparser.web.jobs.views import FileUploadView as PatchedFileUploadView
from rest_framework.test import APITestCase
from string import hexdigits
from tempfile import NamedTemporaryFile

import pytest
import settings

try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse

fake_pipeline_id = "f726e1e0-d43c-4eb7-9274-681ddaba427a"
fake_email_id = "4774f0f6-b53e-4b34-821e-fc8ae5e113fe"


def fake_getter(attrname):
    return attrname


def fake_add_redis_data_to_job_data(job_data):
    return job_data


def fake_delete_eregs_job(job_id):
    return None


def fake_redis_job(args, timeout=60*30, result_ttl=-1):
    return type("FakeRedisJob", (object, ), {"id": fake_pipeline_id})


def fake_queue_email(job, statusurl, email_address):
    return fake_email_id


# Even though these functions are in the ``utils`` module, the code paths we're
# following mean we're encountering them in the ``views`` namespace:
@patch("regparser.web.jobs.views.add_redis_data_to_job_data",
       fake_add_redis_data_to_job_data)
@patch("regparser.web.jobs.views.delete_eregs_job", fake_delete_eregs_job)
@patch("regparser.web.jobs.views.queue_eregs_job", fake_redis_job)
@patch("regparser.web.jobs.views.queue_notification_email", fake_queue_email)
class PipelineJobTestCase(APITestCase):

    def __init__(self, *args, **kwargs):
        self.defaults = {
            "clear_cache": False,
            "destination": eregs_site_api_url,
            "use_uploaded_metadata": None,
            "use_uploaded_regulation": None,
            "regulation_url": "",
            "status": "received"
        }
        super(PipelineJobTestCase, self).__init__(*args, **kwargs)

    def _postjson(self, data):
        return self.client.post("/rp/job/pipeline/", data, format="json")

    def _stock_response_check(self, expected, actual):
        """
        Since we're using a lot of fake values, the tests for them will always
        be the same.
{'fraction_non_alphanumeric': 0.08986486486486486, 'fraction_numerical': 0.01981981981981982, 'mean_word_length': 4.389563106796117, 'pattern_counts': {'":': 14, '<': 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': '2933859', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1446, 'n_words': 345}