<commit_before>#!/usr/bin/env python3
"""
Meerkat API Tests

Unit tests for the Meerkat API
"""
import os
import unittest
from datetime import datetime
import meerkat_api
from meerkat_abacus.task_queue import app as celery_app
from meerkat_api.test import db_util

# Check if auth requirements have been installed
try:
    # HACK: Test by importing package that will only ever be required in auth
    __import__('passlib')
    print("Authentication requirements installed.")
except ImportError:
    print("Authentication requirements not installed.  Installing them now.")
    os.system('pip install -r /var/www/meerkat_auth/requirements.txt')

from . import settings


def need_csv_representation(url):
    """
    Checks if the url has a csv_representation.

    All urls that need a csv representation needs to be added to
    csv_representations.

    Args:
       url: the url to check
    Returns:
       is_csv: True has csv representation
    """
    csv_representations = ["export/get"]
    for r in csv_representations:
        if r in url:
            return True
    return False


def valid_urls(app):
    """
    Return all urls with a semi "sensible" subsitutions for arguments.

    All arguments need to have a subsitituion in the list in this function.

    Args:
       app: meekrat_app
    Returns:
       urls: list of all urls
    """
    substitutions = {
        "location": "1",
        "location_id": "1",
        "device_id": "4",
        "start_date": datetime(2015, 1, 1).isoformat(),
        "end_date": datetime.now().isoformat(),
        "variable_id": "tot_1",
        "variable": "tot",
        "group_by1": "gender",
        "group_by2": "age",
        "group_by": "gender",
        "only_loc": "2",
        "year": "2016",
        "category": "gender",
        "download_name": "cd",
        "epi_week": "2",
        "number_per_week": "5",
        "clinic_type": "Hospital",
        "form": "demo_case",
        "date": datetime(2015, 1, 1).isoformat(),
        "link_def": "alert_investigation",
        "alert_id": "aaaaaa",
        "link_id": "1",
        "use_loc_ids": "1",
        "form_name": "demo_case",
        "weekend": "5,6",
        "use_loc_ids": "1",
        "lim_variable": "tot_1",
        "central_review": "crl_1",
        "mult_factor": "1000",
        "loc_id": "1",
        "level": "district",
        "uid": "1",
        "start_week": "1",
        "exclude": "mental",
        "non_reporting_variable": "reg_1",
        "data_type": "case",
        "weekly": "1",
        "identifier_id": 'tot_1',
        "include": "CTC",
        "num_weeks": "2",
        "require_case_report": "0",
        "restrict_by": "tot_1",
        "weeks": "1",
        "hard_date_limit": "2017-01-01"<commit_msg>Fixed tests<commit_after>#!/usr/bin/env python3
"""
Meerkat API Tests

Unit tests for the Meerkat API
"""
import os
import unittest
from datetime import datetime
import meerkat_api
from meerkat_abacus.task_queue import app as celery_app
from meerkat_api.test import db_util

# Check if auth requirements have been installed
try:
    # HACK: Test by importing package that will only ever be required in auth
    __import__('passlib')
    print("Authentication requirements installed.")
except ImportError:
    print("Authentication requirements not installed.  Installing them now.")
    os.system('pip install -r /var/www/meerkat_auth/requirements.txt')

from . import settings


def need_csv_representation(url):
    """
    Checks if the url has a csv_representation.

    All urls that need a csv representation needs to be added to
    csv_representations.

    Args:
       url: the url to check
    Returns:
       is_csv: True has csv representation
    """
    csv_representations = ["export/get"]
    for r in csv_representations:
        if r in url:
            return True
    return False


def valid_urls(app):
    """
    Return all urls with a semi "sensible" subsitutions for arguments.

    All arguments need to have a subsitituion in the list in this function.

    Args:
       app: meekrat_app
    Returns:
       urls: list of all urls
    """
    substitutions = {
        "location": "1",
        "location_id": "1",
        "device_id": "4",
        "start_date": datetime(2015, 1, 1).isoformat(),
        "end_date": datetime.now().isoformat(),
        "variable_id": "tot_1",
        "variable": "tot",
        "group_by1": "gender",
        "group_by2": "age",
        "group_by": "gender",
        "only_loc": "2",
        "year": "2016",
        "category": "gender",
        "download_name": "cd",
        "epi_week": "2",
        "number_per_week": "5",
        "clinic_type": "Hospital",
        "form": "demo_case",
        "date": datetime(2015, 1, 1).isoformat(),
        "link_def": "alert_investigation",
        "alert_id": "aaaaaa",
        "link_id": "1",
        "use_loc_ids": "1",
        "form_name": "demo_case",
        "weekend": "5,6",
        "use_loc_ids": "1",
        "lim_variable": "tot_1",
        "central_review": "crl_1",
        "mult_factor": "1000",
        "loc_id": "1",
        "level": "district",
        "uid": "1",
        "start_week": "1",
        "exclude": "mental",
        "non_reporting_variable": "reg_1",
        "data_type": "case",
        "weekly": "1",
        "identifier_id": 'tot_1',
        "include": "CTC",
        "num_weeks": "2",
        "require_case_report": "0",
        "restrict_by": "tot_1",
        "weeks": "1",
        "hard_date_limit": "2017-01-01",
        "monthly": "1"
{'fraction_non_alphanumeric': 0.1349493487698987, 'fraction_numerical': 0.02007959479015919, 'mean_word_length': 2.4949431099873576, 'pattern_counts': {'":': 89, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1853397', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1754, 'n_words': 496}