Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest api version "v4" implementation #3429

Merged
merged 2 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aiida/backends/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
'plugins.factories': ['aiida.backends.tests.plugins.test_factories'],
'plugins.utils': ['aiida.backends.tests.plugins.test_utils'],
'query': ['aiida.backends.tests.test_query'],
'restapi.identifiers': ['aiida.backends.tests.restapi.test_identifiers'],
'restapi': ['aiida.backends.tests.test_restapi'],
'tools.data.orbital': ['aiida.backends.tests.tools.data.orbital.test_orbitals'],
'tools.importexport.common.archive': ['aiida.backends.tests.tools.importexport.common.test_archive'],
Expand Down
5 changes: 5 additions & 0 deletions aiida/backends/tests/orm/data/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def generate_class_instance(data_class):
instance = data_class(file=os.path.join(dirpath_fixtures, 'data', 'Si.cif'))
return instance

if data_class is orm.UpfData:
filename = os.path.join(dirpath_fixtures, 'pseudos', 'Ba.pbesol-spn-rrkjus_psl.0.2.3-tot-pslib030.UPF')
instance = data_class(file=filename)
return instance

if data_class is orm.StructureData:
instance = orm.CifData(file=os.path.join(dirpath_fixtures, 'data', 'Si.cif')).get_structure()
return instance
Expand Down
Empty file.
82 changes: 82 additions & 0 deletions aiida/backends/tests/restapi/test_identifiers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
"""Tests for the `aiida.restapi.common.identifiers` module."""
from __future__ import absolute_import
from aiida.backends.testbase import AiidaTestCase
from aiida.restapi.common.identifiers import get_full_type_filters, FULL_TYPE_CONCATENATOR, LIKE_OPERATOR_CHARACTER


class TestIdentifiers(AiidaTestCase):
"""Tests for the :py:mod:`~aiida.restapi.common.identifiers` module."""

def test_get_full_type_filters(self):
"""Test the `get_full_type_filters` function."""

with self.assertRaises(TypeError):
get_full_type_filters(10)

with self.assertRaises(ValueError):
get_full_type_filters('string_without_full_type_concatenator')

with self.assertRaises(ValueError):
get_full_type_filters(
'too_many_{like}{like}{concat}process_type'.format(
like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR
)
)

with self.assertRaises(ValueError):
get_full_type_filters(
'node_type{concat}too_many_{like}{like}'.format(
like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR
)
)

with self.assertRaises(ValueError):
get_full_type_filters(
'not_at_{like}_the_end{concat}process_type'.format(
like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR
)
)

with self.assertRaises(ValueError):
get_full_type_filters(
'node_type{concat}not_at_{like}_the_end'.format(
like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR
)
)

# Equals on both
filters = get_full_type_filters('node_type{concat}process_type'.format(concat=FULL_TYPE_CONCATENATOR))
self.assertEqual(filters['node_type'], 'node\\_type')
self.assertEqual(filters['process_type'], 'process\\_type')

# Like on `node_type`
filters = get_full_type_filters(
'node_type{like}{concat}process_type'.format(like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR)
)
self.assertEqual(filters['node_type'], {'like': 'node\\_type%'})
self.assertEqual(filters['process_type'], 'process\\_type')

# Like on `process_type`
filters = get_full_type_filters(
'node_type{concat}process_type{like}'.format(like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR)
)
self.assertEqual(filters['node_type'], 'node\\_type')
self.assertEqual(filters['process_type'], {'like': 'process\\_type%'})

# Like on both
filters = get_full_type_filters(
'node_type{like}{concat}process_type{like}'.format(
like=LIKE_OPERATOR_CHARACTER, concat=FULL_TYPE_CONCATENATOR
)
)
self.assertEqual(filters['node_type'], {'like': 'node\\_type%'})
self.assertEqual(filters['process_type'], {'like': 'process\\_type%'})
Loading