Beispiel #1
0
from __future__ import annotations

from django.core.management import call_command
from django.test import TestCase

from mhd_data.models import StandardBool, StandardInt
from mhd_tests.utils import AssetPath

from ..models import Collection

from ..models import Property

Z3Z_V1_PATH = AssetPath(__file__, "res", "collection_v1.json")


class PropertyTest(TestCase):
    def setUp(self) -> None:
        """ Creates the demo collection using the upsert command """

        # create the collection
        call_command('upsert_collection', Z3Z_V1_PATH,
                     update=False, quiet=True)
        self.collection = Collection.objects.get(slug='z3zFunctions')

    def test_property_codec(self) -> None:
        """ Tests that the property can be used """

        # get the trace property
        trace = Property.objects.get(slug="f0")

        # checks that the codec_model exists
Beispiel #2
0
from __future__ import annotations

from django.test import TestCase
from rest_framework.test import APIClient

from django.core.management import call_command

from ..models import Collection

from mhd_tests.utils import LoadJSONAsset, AssetPath

COLLECTION_V0_PATH = AssetPath(__file__, "res", "collection_v0.json")
COLLECTION_V0_PATH_INLINE = AssetPath(__file__, "res",
                                      "collection_v0_inline_template.json")
COLLECTION_V0_ASSET = LoadJSONAsset(COLLECTION_V0_PATH)
COLLECTION_V0_TEMPLATE = open(
    AssetPath(__file__, "res", "simple_template.jinja2")).read()
COLLECTION_V0_ASSET["template"] = COLLECTION_V0_TEMPLATE


class CreateCollectionTest(TestCase):
    def setUp(self) -> None:
        """ Creates the demo collection using the upsert command """

        call_command('upsert_collection',
                     COLLECTION_V0_PATH,
                     update=False,
                     quiet=True)

        self.collection = Collection.objects.get(slug='z3zFunctions')
Beispiel #3
0
from __future__ import annotations

import json

from django.test import TestCase

from mhd_tests.utils import AssetPath, LoadJSONAsset

from .collection import insert_testing_data

JANE_COLLECTION_PATH = AssetPath(__file__, "res", "jane_collection.json")

JANE_DATA_PATH = AssetPath(__file__, "res", "jane_data.json")

JANE_PROVENANCE_PATH = AssetPath(__file__, "res", "jane_provenance.json")


class UpdateCountTest(TestCase):
    def setUp(self) -> None:
        """ Creates the demo collection using the upsert command """

        self.collection = insert_testing_data(
            JANE_COLLECTION_PATH, JANE_DATA_PATH, JANE_PROVENANCE_PATH, reset=True)

    def test_update_count(self) -> None:
        """ Checks that delete_collection actually deletes a collection """
        self.collection.count_frozen = False
        self.collection.save()

        # counting a collection gives the expected result
        self.assertIsNone(self.collection.count)
Beispiel #4
0
from __future__ import annotations

import json

from django.test import TestCase

from mhd_tests.utils import AssetPath, LoadJSONAsset

from .collection import insert_testing_data

from ..models import Item
from mhd_schema.models import Property

Z3Z_COLLECTION_PATH = AssetPath(__file__, "res", "z3z_collection.json")
Z3Z_PROVENANCE_PATH = AssetPath(__file__, "res", "z3z_provenance.json")
Z3Z_DATA_PATH = AssetPath(__file__, "res", "z3z_data.json")

Z3Z_ALL_PATH = AssetPath(__file__, "res", "z3z_query_all.json")
Z3Z_ALL_ASSET = LoadJSONAsset(Z3Z_ALL_PATH)


class ItemTest(TestCase):
    def setUp(self) -> None:
        self.collection = insert_testing_data(Z3Z_COLLECTION_PATH,
                                              Z3Z_DATA_PATH,
                                              Z3Z_PROVENANCE_PATH,
                                              reset=True)

    def test_annotate_property(self) -> None:
        """ Tests that we can annotate a property correctly """
Beispiel #5
0
from __future__ import annotations

import json

from django.test import TestCase

from mhd_tests.utils import AssetPath, LoadJSONAsset

from .collection import insert_testing_data

from ..models import Item

AB_COLLECTION_PATH = AssetPath(__file__, "res", "ab_collection.json")

AB_DATA_PATH = AssetPath(__file__, "res", "ab_data.json")

AB_PROVENANCE_PATH = AssetPath(__file__, "res", "ab_provenance.json")

AB_ALL_PATH = AssetPath(__file__, "res", "ab_all.json")
AB_ALL_ASSET = LoadJSONAsset(AB_ALL_PATH)


class ABCollectionTest(TestCase):
    """
        Tests that the demo 'AB' collection can be inserted
        and queryied from the database.
        The AB collection is mathematically meaningful.
    """
    def setUp(self) -> None:
        self.collection = insert_testing_data(AB_COLLECTION_PATH,
                                              AB_DATA_PATH,
Beispiel #6
0
from __future__ import annotations

from ..query import FilterBuilder
from django.test import TestCase

from mhd_data.tests.collection import insert_testing_data

from mhd_tests.utils import AssetPath

Z3Z_COLLECTION_PATH = AssetPath(__file__, "..", "..", "mhd_data", "tests", "res", "z3z_collection.json")
Z3Z_PROVENANCE_PATH = AssetPath(__file__, "..", "..", "mhd_data", "tests", "res", "z3z_provenance.json")
Z3Z_DATA_PATH = AssetPath(__file__, "..", "..", "mhd_data", "tests", "res", "z3z_data.json")


class FilterBuilderTest(TestCase):
    def setUp(self) -> None:
        self.collection = insert_testing_data(
            Z3Z_COLLECTION_PATH, Z3Z_DATA_PATH, Z3Z_PROVENANCE_PATH, reset=True)

    def test_build_filters(self) -> None:
        # create a filter builder
        fb = FilterBuilder(self.collection)

        # simple logicals

        # left operand
        q1sql, q1args = fb("f1 <= 1")
        self.assertEqual(q1sql, '"property_value_f1" <= %s')
        self.assertListEqual(q1args, [1])

        # right operand
Beispiel #7
0
from __future__ import annotations

from django.test import TestCase

from django.core.management import call_command

from ..models import Collection, Property, PropertyCollectionMembership

from mhd_tests.utils import LoadJSONAsset, AssetPath

COLLECTION_V0_PATH = AssetPath(__file__, "res", "collection_v0.json")
COLLECTION_V0_ASSET = LoadJSONAsset(COLLECTION_V0_PATH)


class CreateCollectionTest(TestCase):
    def setUp(self) -> None:
        """ Creates the demo collection using the upsert command """

        call_command('upsert_collection',
                     COLLECTION_V0_PATH,
                     update=False,
                     quiet=True)

        self.collection = Collection.objects.get(slug='z3zFunctions')

    def test_delete_collection(self) -> None:
        """ Checks that delete_collection actually deletes a collection """

        self.collection.safe_delete()
        self.assertFalse(Collection.objects.exists(),
                         "Check that there are no more collections")
Beispiel #8
0
from __future__ import annotations

from django.test import TestCase
from rest_framework.test import APIClient
import json

from mhd_tests.utils import LoadJSONAsset, AssetPath

CODEC_LIST_PATH = AssetPath(__file__, "res", "codec_list.json")
CODEC_LIST_ASSET = LoadJSONAsset(CODEC_LIST_PATH)

CODEC_SI_PATH = AssetPath(__file__, "res", "codec_standardint.json")
CODEC_SI_ASSET = LoadJSONAsset(CODEC_SI_PATH)


class CodecAPITest(TestCase):
    def test_api_all_collections(self) -> None:
        """ Checks that the demo collection is the only item in the list of collections """

        response = APIClient().get('/api/schema/codecs/')

        # we got an http 200
        self.assertEqual(response.status_code, 200)

        GOT_JSON = response.json()
        GOT_NAMES = [c["name"] for c in GOT_JSON]
        for c in CODEC_LIST_ASSET:
            try:
                idx = GOT_NAMES.index(c["name"])
            except:
                idx = -1