<commit_before># -*- coding: utf-8 -*-

from unittest import main
from json import loads

from qiita_pet.test.tornado_test_base import TestHandlerBase
from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_db.study import StudyPerson, Study
from qiita_db.util import get_count, check_count
from qiita_db.user import User
from qiita_pet.handlers.study_handlers.listing_handlers import (
    _get_shared_links_for_study, _build_study_info, _build_single_study_info,
    _build_single_proc_data_info)


class TestHelpers(TestHandlerBase):
    database = True

    def setUp(self):
        self.proc_data_exp = {
            'pid': 4,
            'processed_date': '2012-10-02 17:30:00',
            'data_type': '18S',
            'algorithm': 'sortmerna',
            'reference_name': 'Greengenes',
            'reference_version': '13_8',
            'taxonomy_filepath': 'GreenGenes_13_8_97_otu_taxonomy.txt',
            'sequence_filepath': 'GreenGenes_13_8_97_otus.fasta',
            'tree_filepath': 'GreenGenes_13_8_97_otus.tree',
            'similarity': 0.97,
            'sortmerna_max_pos': 10000,
            'sortmerna_e_value': 1,
            'sortmerna_coverage': 0.97,
            'threads': 1,
            'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
                        '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
                        '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
                        '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
                        '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
                        '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
                        '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
                        '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
                        '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']
        }
        self.single_exp = {
            'study_id': 1,
            'status': 'private',
            'study_abstract':
                'This is a preliminary study to examine the microbiota '
                'associated with the Cannabis plant. Soils samples '
                'from the bulk soil, soil associated with the roots, '
                'and the rhizosphere were extracted and the DNA '
                'sequenced. Roots from three independent plants of '
                'different strains were examined. These roots were '
                'obtained November 11, 2011 from plants that had been '
                'harvested in the summer. Future studies will attempt '
                'to analyze the soils and rhizospheres from the same '
                'location at different time points in the plant '
                'lifecycle.',
            'metadata_complete': True,
            'study_title':
                'Identification of the Microbiomes for Cannabis Soils',
            'num_raw_data': 1,
            'number_samples_collected': 27,
            'shared':
                '<a target="_blank" href="mailto:<EMAIL>">Shared</a>',
            'pmid': '<a target="_blank" href="http://www.ncbi.nlm.nih.gov/'
                    'pubmed/123456">123456</a>, <a target="_blank" href="http:'
                    '//www.ncbi.nlm.nih.gov/pubmed/7891011">7891011</a>',
            'pi': '<a target="_blank" href="mailto:<EMAIL>">'
                  'PIDude</a>',
            'proc_data_info': [self.proc_data_exp]
        }
        self.exp = [self.single_exp]
        super(TestHelpers, self).setUp()

    def test_get_shared_links_for_study(self):
        obs = _get_shared_links_for_study(Study(1))
        exp = '<a target="_blank" href="mailto:<EMAIL>">Shared</a>'
        self.assertEqual(obs, exp)

    def test_build_single_study_info(self):
        study_proc = {1: {'18S': [1]}}
        proc_samples = {1: self.proc_data_exp['samples']}
        study_info = {
            'study_id': 1,
            'email': '<EMAIL>',
            'principal_investigator_id': 3,
            'publication_doi': ['10.100/123456', '10.100/7891011'],
            'study_title':
                'Identification of the Microbiomes for Cannabis Soils',
            'metadata_complete': True,
            'number_samples_collected': 27,
            'study_abstract':
                'This is a preliminary study to examine the microbiota '
                'associated with the Cannabis plant. Soils samples '
                'from the bulk soil, soil associated with the roots, '
                'and the rhizosphere were extracted and the DNA '
                'sequenced. Roots from three independent plants of '
                'different strains were examined. These roots were '
                'obtained November 11, 2011 from plants that had been '
                'harvested in the summer. Future studies will attempt '
                'to analyze the soils and rhizospheres from the same '
                'location at different time points in the plant '<commit_msg>Fixing test_build_single_study_info<commit_after># -*- coding: utf-8 -*-

from unittest import main
from json import loads

from qiita_pet.test.tornado_test_base import TestHandlerBase
from qiita_core.exceptions import IncompetentQiitaDeveloperError
from qiita_db.study import StudyPerson, Study
from qiita_db.util import get_count, check_count
from qiita_db.user import User
from qiita_pet.handlers.study_handlers.listing_handlers import (
    _get_shared_links_for_study, _build_study_info, _build_single_study_info,
    _build_single_proc_data_info)


class TestHelpers(TestHandlerBase):
    database = True

    def setUp(self):
        self.proc_data_exp = {
            'pid': 4,
            'processed_date': '2012-10-02 17:30:00',
            'data_type': '18S',
            'algorithm': 'sortmerna',
            'reference_name': 'Greengenes',
            'reference_version': '13_8',
            'taxonomy_filepath': 'GreenGenes_13_8_97_otu_taxonomy.txt',
            'sequence_filepath': 'GreenGenes_13_8_97_otus.fasta',
            'tree_filepath': 'GreenGenes_13_8_97_otus.tree',
            'similarity': 0.97,
            'sortmerna_max_pos': 10000,
            'sortmerna_e_value': 1,
            'sortmerna_coverage': 0.97,
            'threads': 1,
            'samples': ['1.SKB1.640202', '1.SKB2.640194', '1.SKB3.640195',
                        '1.SKB4.640189', '1.SKB5.640181', '1.SKB6.640176',
                        '1.SKB7.640196', '1.SKB8.640193', '1.SKB9.640200',
                        '1.SKD1.640179', '1.SKD2.640178', '1.SKD3.640198',
                        '1.SKD4.640185', '1.SKD5.640186', '1.SKD6.640190',
                        '1.SKD7.640191', '1.SKD8.640184', '1.SKD9.640182',
                        '1.SKM1.640183', '1.SKM2.640199', '1.SKM3.640197',
                        '1.SKM4.640180', '1.SKM5.640177', '1.SKM6.640187',
                        '1.SKM7.640188', '1.SKM8.640201', '1.SKM9.640192']
        }
        self.single_exp = {
            'study_id': 1,
            'status': 'private',
            'study_abstract':
                'This is a preliminary study to examine the microbiota '
                'associated with the Cannabis plant. Soils samples '
                'from the bulk soil, soil associated with the roots, '
                'and the rhizosphere were extracted and the DNA '
                'sequenced. Roots from three independent plants of '
                'different strains were examined. These roots were '
                'obtained November 11, 2011 from plants that had been '
                'harvested in the summer. Future studies will attempt '
                'to analyze the soils and rhizospheres from the same '
                'location at different time points in the plant '
                'lifecycle.',
            'metadata_complete': True,
            'study_title':
                'Identification of the Microbiomes for Cannabis Soils',
            'num_raw_data': 1,
            'number_samples_collected': 27,
            'shared':
                '<a target="_blank" href="mailto:<EMAIL>">Shared</a>',
            'publication_doi':
                '<a target="_blank" href="http://dx.doi.org/10.100/123456">'
                '10.100/123456</a>, <a target="_blank" '
                'href="http://dx.doi.org/10.100/7891011">10.100/7891011</a>',
            'pmid': '<a target="_blank" href="http://www.ncbi.nlm.nih.gov'
                    '/pubmed/7891011">7891011</a>, <a target="_blank" href='
                    '"http://www.ncbi.nlm.nih.gov/pubmed/123456">123456</a>',
            'pi': '<a target="_blank" href="mailto:<EMAIL>">'
                  'PIDude</a>',
            'proc_data_info': [self.proc_data_exp]
        }
        self.exp = [self.single_exp]
        super(TestHelpers, self).setUp()

    def test_get_shared_links_for_study(self):
        obs = _get_shared_links_for_study(Study(1))
        exp = '<a target="_blank" href="mailto:<EMAIL>">Shared</a>'
        self.assertEqual(obs, exp)

    def test_build_single_study_info(self):
        study_proc = {1: {'18S': [4]}}
        proc_samples = {4: self.proc_data_exp['samples']}
        study_info = {
            'study_id': 1,
            'email': '<EMAIL>',
            'principal_investigator_id': 3,
            'publication_doi': ['10.100/123456', '10.100/7891011'],
            'study_title':
                'Identification of the Microbiomes for Cannabis Soils',
            'metadata_complete': True,
            'number_samples_collected': 27,
            'study_abstract':
                'This is a preliminary study to examine the microbiota '
                'associated with the Cannabis plant. Soils samples '
                'from the bulk soil, soil associated with the roots, '
                'and the rhizosphere were extracted and the DNA '
                'sequenced. Roots from three independent plants of '
                'different strains were examined. These roots were '
                'obtained November 11, 2011 from plants that had been '
                'harvested in the summer. Future studies will attempt '
                'to analyze the soils and rhizospheres from the same '
                'location at different time points in the plant '
{'fraction_non_alphanumeric': 0.11520827236367184, 'fraction_numerical': 0.07082235879426398, 'mean_word_length': 1.979366463237431, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1994158', 'n_tokens_mistral': 3680, 'n_tokens_neox': 3198, 'n_words': 715}