<commit_before>"""Tests for plugin.py."""
import ckanext.jsoncatalog.plugin as plugin
from ckanext.jsoncatalog.mappers import Mappers
from ckanext.jsoncatalog.formaters import WildCards
from ckan.config.environment import config
from ckanext.jsoncatalog.controller import JsonCatalogController
from ckan.tests import factories
from nose.tools import *

"""

 Tests para clase Mappers.

"""


def test_load_mappers():
    """
    Test 1: Carga de mappers por default.

    """
    mappers = Mappers()
    assert_equal(mappers.load(schema='default', version='1.0'), True)


def test_mappers_class_load_not_exists_schema():
    """
    Test 2: No existe schema provisto para carga de mappers.

    """
    mappers = Mappers()
    try:
        mappers.load(schema='no_existe', version='1.0')
    except IOError:
        pass


def test_mappers_class_load_not_exists_version():
    """
    Test 3: No existe version del schema provisto para carga de mappers.

    """
    mappers = Mappers()
    try:
        mappers.load(schema='default', version='no.existe')
    except IOError:
        pass


def test_mappers_class_init_cls_load_not_exists_version():
    """
    Test 4: No existe version del schema provisto para
    carga de mappers pero desde la creacion de la clase.

    """
    try:
        mappers = Mappers(schema='default', version='no.existe')
    except IOError:
        pass


@raises(IOError)
def test_mappers_class_int_cls_load_not_exists_schema():
    """
    Test 5: No existe schema provisto para carga de mappers
    pero desde la creacion de la clase.

    """
    mappers = Mappers()
    mappers.load(schema='no_existe', version='1.0')


"""

 Tests para clase WindCards.

"""


def test_wildcards_class_instance():
    """
    Test 6: Crear una instancia de las clase WildCards
    """
    wildcards = WildCards()


def test_wildcards_apply_type():
    """
    Test 7: Aplicar una wildcard a una frase retorna una cadena.

    """
    wildcards = WildCards()
    assert wildcards.apply('__@site_url__'), str


def test_wildcards_apply():
    """
    Test 8: Aplicar una wildcard a una frase.

    """
    wildcards = WildCards()
    right_answers = [{'site_url': config.get('ckan.site_url', 'http://127.0.0.1:5000')},
                     {'site_title': config.get('ckan.site_title', 'No definido')},
                     {'site_description': config.get('ckan.site_description', 'No definido')}]
    test_this = []
    for windc_name, windc_value in wildcards.__dict__.items():
        test_this.append({windc_name: windc_value})
    print test_this
    print right_answers
    assert_equal(len(test_this), len(right_answers))


def test_wildcards_set_and_apply():
    """
    Test 9: Aplicar una wildcard a una frase.

    """
    wildcards = WildCards()
    for wildcard in wildcards.__dict__.keys():
        wildcards.__dict__[wildcard] = wildcard
    assert_equals(wildcards.apply('@site_url') == 'site_url', True)

"""

 Tests para clase Controller.

"""<commit_msg>Test: Listar WildCards, chequeo de tipo y contenido<commit_after>"""Tests for plugin.py."""
import ckanext.jsoncatalog.plugin as plugin
from ckanext.jsoncatalog.mappers import Mappers
from ckanext.jsoncatalog.formaters import WildCards
from ckan.config.environment import config
from ckanext.jsoncatalog.controller import JsonCatalogController
from ckan.tests import factories
from nose.tools import *

"""

 Tests para clase Mappers.

"""


def test_load_mappers():
    """
    Test 1: Carga de mappers por default.

    """
    mappers = Mappers()
    assert_equal(mappers.load(schema='default', version='1.0'), True)


def test_mappers_class_load_not_exists_schema():
    """
    Test 2: No existe schema provisto para carga de mappers.

    """
    mappers = Mappers()
    try:
        mappers.load(schema='no_existe', version='1.0')
    except IOError:
        pass


def test_mappers_class_load_not_exists_version():
    """
    Test 3: No existe version del schema provisto para carga de mappers.

    """
    mappers = Mappers()
    try:
        mappers.load(schema='default', version='no.existe')
    except IOError:
        pass


def test_mappers_class_init_cls_load_not_exists_version():
    """
    Test 4: No existe version del schema provisto para
    carga de mappers pero desde la creacion de la clase.

    """
    try:
        mappers = Mappers(schema='default', version='no.existe')
    except IOError:
        pass


@raises(IOError)
def test_mappers_class_int_cls_load_not_exists_schema():
    """
    Test 5: No existe schema provisto para carga de mappers
    pero desde la creacion de la clase.

    """
    mappers = Mappers()
    mappers.load(schema='no_existe', version='1.0')


"""

 Tests para clase WindCards.

"""


def test_wildcards_class_instance():
    """
    Test 6: Crear una instancia de las clase WildCards
    """
    wildcards = WildCards()


def test_wildcards_apply_type():
    """
    Test 7: Aplicar una wildcard a una frase retorna una cadena.

    """
    wildcards = WildCards()
    assert wildcards.apply('__@site_url__'), str


def test_wildcards_apply():
    """
    Test 8: Aplicar una wildcard a una frase.

    """
    wildcards = WildCards()
    right_answers = [{'site_url': config.get('ckan.site_url', 'http://127.0.0.1:5000')},
                     {'site_title': config.get('ckan.site_title', 'No definido')},
                     {'site_description': config.get('ckan.site_description', 'No definido')}]
    test_this = []
    for windc_name, windc_value in wildcards.__dict__.items():
        test_this.append({windc_name: windc_value})
    print test_this
    print right_answers
    assert_equal(len(test_this), len(right_answers))


def test_wildcards_set_and_apply():
    """
    Test 9: Aplicar una wildcard a una frase.

    """
    wildcards = WildCards()
    for wildcard in wildcards.__dict__.keys():
        wildcards.__dict__[wildcard] = wildcard
    assert_equals(wildcards.apply('@site_url') == 'site_url', True)


def test_wildcards_list():
    """
    Test 7: Aplicar una wildcard a una frase retorna una cadena.

    """
    wildcards = WildCards()
    assert_equals(sorted(wildcards.list()), sorted(['site_url', 'site_description', 'site_title']))

"""

 Tests para clase Controller.

"""
{'fraction_non_alphanumeric': 0.1140757309474357, 'fraction_numerical': 0.008148266496245407, 'mean_word_length': 3.3502432244614315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '962797', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2034, 'n_words': 506}