<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pytest
import uuid
from processors.base import helpers
import processors.nct.extractors as nct_extractors
from processors.base.processors.trial import process_trials


class TestTrialProcessor(object):
    def test_updates_which_record_is_primary(
        self,
        conn,
        extractors,
        trial,
        record,
        nct_record,
        euctr_source
    ):
        nct_record_attrs = conn['warehouse']['nct'].find_one(nct_id=nct_record)
        current_primary = conn['database']['records'].find_one(id=record)
        current_primary.update({
            'trial_id': trial,
            'is_primary': True,
            'source_id': euctr_source,
            'identifiers': {'nct': nct_record},
        })
        conn['database']['records'].update(current_primary, ['id'])

        process_trials(conn, 'nct', extractors)

        updated_current_primary = conn['database']['records'].find_one(id=record)
        new_record = conn['database']['records'].find_one(id=nct_record_attrs['meta_id'])

        assert updated_current_primary['is_primary'] == False
        assert new_record['is_primary'] ==  True


@pytest.fixture
def extractors():
    return helpers.get_variables(nct_extractors,
        lambda x: x.startswith('extract_'))<commit_msg>[#746] Add test guaranteeing we use meta_id and meta_source<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pytest
import uuid
from processors.base import helpers
import processors.nct.extractors as nct_extractors
from processors.base.processors.trial import process_trials


class TestTrialProcessor(object):
    def test_updates_which_record_is_primary(
        self,
        conn,
        extractors,
        trial,
        record,
        nct_record,
        euctr_source
    ):
        nct_record_attrs = conn['warehouse']['nct'].find_one(nct_id=nct_record)
        current_primary = conn['database']['records'].find_one(id=record)
        current_primary.update({
            'trial_id': trial,
            'is_primary': True,
            'source_id': euctr_source,
            'identifiers': {'nct': nct_record},
        })
        conn['database']['records'].update(current_primary, ['id'])

        process_trials(conn, 'nct', extractors)

        updated_current_primary = conn['database']['records'].find_one(id=record)
        new_record = conn['database']['records'].find_one(id=nct_record_attrs['meta_id'])

        assert updated_current_primary['is_primary'] == False
        assert new_record['is_primary'] ==  True

    def test_uses_warehouse_meta_id_and_meta_source_as_record_id_and_source_url(
        self,
        conn,
        extractors,
        nct_record
    ):
        nct_record_attrs = conn['warehouse']['nct'].find_one(nct_id=nct_record)

        process_trials(conn, 'nct', extractors)

        created_record = conn['database']['records'].find_one(id=nct_record_attrs['meta_id'])

        assert created_record is not None
        assert created_record['source_url'] == nct_record_attrs['meta_source']


@pytest.fixture
def extractors():
    return helpers.get_variables(nct_extractors,
        lambda x: x.startswith('extract_'))
{'fraction_non_alphanumeric': 0.10864553314121038, 'fraction_numerical': 0.001440922190201729, 'mean_word_length': 3.5077922077922077, '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': '6027331', 'n_tokens_mistral': 1057, 'n_tokens_neox': 1032, 'n_words': 194}