Exemplo n.º 1
0
 def test_node_not_allowed_from_registrations_endpoint(self):
     self.node = NodeFactory(creator=self.user, is_public=True)
     self.node_identifier = IdentifierFactory(referent=self.node)
     url = '/{}registrations/{}/identifiers/'.format(
         API_BASE, self.node._id)
     res = self.app.get(url, expect_errors=True)
     assert_equal(res.status_code, 404)
Exemplo n.º 2
0
def test_deidentify(mock_pims_session):
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_CREATE_JSONOUTPUT_TRUE)
    identifiers = [IdentifierFactory(), IdentifierFactory()]
    keys = connection.pseudonymize(key_file=KeyFileFactory(),
                                   identifiers=identifiers)
    assert len(keys) == 2
    assert str(keys[0].identifier) == str(identifiers[0])

    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_CREATE_JSONOUTPUT_TRUE_INVALID)

    with pytest.raises(PIMSSwaggerException) as e:
        connection.pseudonymize(key_file=KeyFileFactory(),
                                identifiers=identifiers)
Exemplo n.º 3
0
def test_typed_key_factory(value_type):
    """Creating typed keys for these value types should work"""
    key = Key(identifier=IdentifierFactory(source=value_type),
              pseudonym=PseudonymFactory())

    typed_key = KeyTypeFactory().create_typed_key(key)
    assert typed_key.value_type == value_type
Exemplo n.º 4
0
 def test_node_identifier_not_returned_from_registration_endpoint(self):
     self.node = NodeFactory(creator=self.user, is_public=True)
     self.node_identifier = IdentifierFactory(referent=self.node)
     res = self.app.get(self.url)
     assert_equal(res.status_code, 200)
     data = res.json['data']
     assert_equal(len(data), 1)
     assert_equal(self.identifier._id, data[0]['id'])
     assert_not_equal(self.node_identifier._id, data[0]['id'])
Exemplo n.º 5
0
    def setUp(self):
        super(TestIdentifierDetail, self).setUp()
        self.user = AuthUserFactory()

        self.registration = RegistrationFactory(creator=self.user, is_public=True)
        self.identifier = IdentifierFactory(referent=self.registration)
        self.url = '/{}identifiers/{}/'.format(API_BASE, self.identifier._id)

        self.res = self.app.get(self.url)
        self.data = self.res.json['data']
Exemplo n.º 6
0
def test_pimsconnection(mock_pims_session):
    connection = PIMSConnection(session=mock_pims_session)
    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.DEIDENTIFY_CREATE_JSONOUTPUT_TRUE)
    connection.pseudonymize(key_file=KeyFileFactory(),
                            identifiers=[IdentifierFactory()])

    mock_pims_session.session.set_response_tuple(
        RequestsMockResponseExamples.KEYFILES_PSEUDONYMS_REIDENTIFY_RESPONSE)
    connection.reidentify(key_file=KeyFileFactory(),
                          pseudonyms=[PseudonymFactory()])
Exemplo n.º 7
0
def test_typed_key_factory_exception():
    """Trying to create a typed key for an unknown type should fail"""
    key = Key(identifier=IdentifierFactory(source='UNKNOWN'),
              pseudonym=PseudonymFactory())

    with pytest.raises(TypedKeyFactoryException):
        KeyTypeFactory().create_typed_key(key)

    with pytest.raises(TypedKeyFactoryException):
        KeyTypeFactory().create_typed_pseudonym(PseudonymFactory(),
                                                value_type='UNKNOWN')
Exemplo n.º 8
0
    def setUp(self):
        super(TestNodeIdentifierList, self).setUp()
        self.user = AuthUserFactory()
        self.user_two = AuthUserFactory()

        self.node = NodeFactory(creator=self.user, is_public=True)
        self.identifier = IdentifierFactory(referent=self.node)
        self.url = '/{}nodes/{}/identifiers/'.format(API_BASE, self.node._id)

        self.res = self.app.get(self.url)
        self.data = self.res.json['data']

        self.all_identifiers = Identifier.find()
Exemplo n.º 9
0
    def test_identifier_filter_by_category(self):
        IdentifierFactory(referent=self.node, category='nopeid')
        identifiers_for_node = Identifier.find(Q('referent', 'eq', self.node))
        assert_equal(len(identifiers_for_node), 2)
        assert_items_equal(
            [identifier.category for identifier in identifiers_for_node],
            ['carpid', 'nopeid'])

        filter_url = self.url + '?filter[category]=carpid'
        new_res = self.app.get(filter_url)

        carpid_total = len(Identifier.find(Q('category', 'eq', 'carpid')))

        total = new_res.json['links']['meta']['total']
        assert_equal(total, carpid_total)
Exemplo n.º 10
0
 def test_mixin_get_value(self):
     identifier = IdentifierFactory()
     node = identifier.referent
     assert_equal(node.get_identifier_value(identifier.category),
                  identifier.value)
Exemplo n.º 11
0
 def test_unique_constraint(self):
     node = RegistrationFactory()
     IdentifierFactory(referent=node)
     with assert_raises(KeyExistsException):
         IdentifierFactory(referent=node)
Exemplo n.º 12
0
 def test_mixin_set_update(self):
     identifier = IdentifierFactory(category='dogid', value='dog:1')
     node = identifier.referent
     assert_equal(node.get_identifier_value('dogid'), 'dog:1')
     node.set_identifier_value('dogid', 'dog:2')
     assert_equal(node.get_identifier_value('dogid'), 'dog:2')