コード例 #1
0
ファイル: test_views.py プロジェクト: JDeVos/atramhasis
def filter_by_mock_concept(**kwargs):
    filter_mock = Mock()
    concept_id = None
    conceptscheme_id = None
    if 'concept_id' in kwargs:
        concept_id = kwargs['concept_id']
    if 'conceptscheme_id' in kwargs:
        conceptscheme_id = kwargs['conceptscheme_id']
    if concept_id == '1':
        c = Concept(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        c.type = 'concept'
        filter_mock.one = Mock(return_value=c)
    elif concept_id == '3':
        c = Collection(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        c.type = 'collection'
        filter_mock.one = Mock(return_value=c)
    elif concept_id == '555':
        c = Thing(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        filter_mock.one = Mock(return_value=c)
    elif concept_id == '666':
        raise NoResultFound

    a_concept = Concept(concept_id=7895, conceptscheme_id=conceptscheme_id, type='concept')
    a_labels = [Label(label='De Paardekastanje', language_id='nl'), Label(label='The Chestnut', language_id='en'),
                Label(label='la châtaigne', language_id='fr')]
    a_concept.labels = a_labels
    b_concept = Concept(concept_id=9863, conceptscheme_id=conceptscheme_id, type='concept')
    b_labels = [Label(label='test', language_id='nl')]
    b_concept.labels = b_labels
    filter_mock.all = Mock(return_value=[a_concept, b_concept])
    return filter_mock
コード例 #2
0
def filter_by_mock_concept(**kwargs):
    filter_mock = Mock()
    concept_id = None
    conceptscheme_id = None
    if 'concept_id' in kwargs:
        concept_id = kwargs['concept_id']
    if 'conceptscheme_id' in kwargs:
        conceptscheme_id = kwargs['conceptscheme_id']
    if concept_id == '1':
        c = Concept(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        c.type = 'concept'
        label_mock = Mock()
        label_mock.label = 'test'
        c.label = Mock(return_value=label_mock)
        filter_mock.one = Mock(return_value=c)
    elif concept_id == '3':
        c = Collection(concept_id=concept_id,
                       conceptscheme_id=conceptscheme_id)
        c.type = 'collection'
        label_mock = Mock()
        label_mock.label = 'test'
        c.label = Mock(return_value=label_mock)
        filter_mock.one = Mock(return_value=c)
    elif concept_id == '555':
        c = Thing(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        filter_mock.one = Mock(return_value=c)
    elif concept_id == '666':
        raise NoResultFound

    a_concept = Concept(concept_id=7895,
                        conceptscheme_id=conceptscheme_id,
                        type='concept')
    a_labels = [
        Label(label='De Paardekastanje', language_id='nl'),
        Label(label='The Chestnut', language_id='en'),
        Label(label='la châtaigne', language_id='fr')
    ]
    a_concept.labels = a_labels
    b_concept = Concept(concept_id=9863,
                        conceptscheme_id=conceptscheme_id,
                        type='concept')
    b_labels = [Label(label='test', language_id='nl')]
    b_concept.labels = b_labels
    filter_mock.all = Mock(return_value=[a_concept, b_concept])
    return filter_mock
コード例 #3
0
 def change_type(self, thing, concept_id, conceptscheme_id, new_type):
     self.delete_thing(thing)
     self.session.flush()
     thing = Concept() if new_type == 'concept' else Collection()
     thing.type = new_type
     thing.concept_id = concept_id
     thing.conceptscheme_id = conceptscheme_id
     self.save(thing)
     return thing
コード例 #4
0
def filter_by_mock_concept(concept_id, conceptscheme_id):
    concept = Concept(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
    concept.type = 'concept'
    if concept_id == 2:
        broader_concept = Concept(concept_id=1,
                                  conceptscheme_id=conceptscheme_id)
        broader_concepts = set()
        broader_concepts.add(broader_concept)
        concept.broader_concepts = broader_concepts
    if concept_id == 7:
        narrower_concept = Concept(concept_id=14,
                                   conceptscheme_id=conceptscheme_id)
        narrower_concepts = set()
        narrower_concepts.add(narrower_concept)
        concept.narrower_concepts = narrower_concepts
    if concept_id == 666:
        concept = Collection(concept_id=concept_id,
                             conceptscheme_id=conceptscheme_id)
        concept.type = 'collection'
    if concept_id == 667:
        concept = Collection(concept_id=concept_id,
                             conceptscheme_id=conceptscheme_id)
        concept.type = 'collection'
        memberof = Collection(concept_id=60, conceptscheme_id=conceptscheme_id)
        memberofs = set()
        memberofs.add(memberof)
        concept.member_of = memberofs
    if concept_id == 62:
        concept = Collection(concept_id=concept_id,
                             conceptscheme_id=conceptscheme_id)
        concept.type = 'collection'
        member = Collection(concept_id=666, conceptscheme_id=conceptscheme_id)
        members = set()
        members.add(member)
        concept.members = members
    if concept_id == 777:
        if conceptscheme_id != 3:
            raise NoResultFound()
    filter_mock = Mock()
    filter_mock.one = Mock(return_value=concept)
    return filter_mock
コード例 #5
0
def filter_by_mock_concept(concept_id, conceptscheme_id):
    concept = Concept(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
    concept.type = 'concept'
    if concept_id == 2:
        broader_concept = Concept(concept_id=1, conceptscheme_id=conceptscheme_id)
        broader_concepts = set()
        broader_concepts.add(broader_concept)
        concept.broader_concepts = broader_concepts
    if concept_id == 7:
        narrower_concept = Concept(concept_id=14, conceptscheme_id=conceptscheme_id)
        narrower_concepts = set()
        narrower_concepts.add(narrower_concept)
        concept.narrower_concepts = narrower_concepts
    if concept_id == 666:
        concept = Collection(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        concept.type = 'collection'
    if concept_id == 667:
        concept = Collection(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        concept.type = 'collection'
        memberof = Collection(concept_id=60, conceptscheme_id=conceptscheme_id)
        memberofs = set()
        memberofs.add(memberof)
        concept.member_of = memberofs
    if concept_id == 62:
        concept = Collection(concept_id=concept_id, conceptscheme_id=conceptscheme_id)
        concept.type = 'collection'
        member = Collection(concept_id=666, conceptscheme_id=conceptscheme_id)
        members = set()
        members.add(member)
        concept.members = members
    if concept_id == 777:
        if conceptscheme_id != 3:
            raise NoResultFound()
    filter_mock = Mock()
    filter_mock.one = Mock(return_value=concept)
    return filter_mock