diff --git a/apis_core/apis_entities/api_renderers.py b/apis_core/apis_entities/api_renderers.py deleted file mode 100644 index 8026dd1ca..000000000 --- a/apis_core/apis_entities/api_renderers.py +++ /dev/null @@ -1,7 +0,0 @@ -from apis_core.utils.renderers.tei import TeiRenderer - - -class EntityToTEI(TeiRenderer): - def render(self, data, media_type=None, renderer_context=None): - self.template_name = f"apis_entities/tei/{data['entity_type']}.xml" - return super().render(data, media_type, renderer_context) diff --git a/apis_core/apis_entities/autocomplete3.py b/apis_core/apis_entities/autocomplete3.py index 9efdd7820..ed48b9071 100644 --- a/apis_core/apis_entities/autocomplete3.py +++ b/apis_core/apis_entities/autocomplete3.py @@ -14,62 +14,6 @@ from apis_core.utils.settings import get_entity_settings_by_modelname -class CustomEntityAutocompletes(object): - """A class for collecting all the custom autocomplete functions for one entity. - - Attributes: - - - self.entity: (string) entity types - - self.more: (boolean) if more results can be fetched (pagination) - - self.page_size: (integer) page size - - self.results: (list) results - - self.query: (string) query string - - Methods: - - self.more(): fetch more results - """ - - def __init__(self, entity, query, page_size=20, offset=0, *args, **kwargs): - """ - :param entity: (string) entity type to fetch additional autocompletes for - """ - func_list = {} - if entity not in func_list.keys(): - self.results = None - return None - res = [] - more = dict() - more_gen = False - for x in func_list[entity]: - res2 = x().query(query, page_size, offset) - if len(res2) == page_size: - more[x.__name__] = (True, offset + 1) - more_gen = True - res.extend(res2) - self.results = res - self.page_size = page_size - self.more = more_gen - self._more_dict = more - self.query = query - self.offset = offset - - def get_more(self): - """ - Function to retrieve more results. - """ - res4 = [] - for key, value in self._more_dict.items(): - if value[0]: - res3 = globals()[key](self.query, self.page_size, value[1]) - if len(res3) == self.page_size: - self._more_dict[key] = (True, value[1] + 1) - else: - self._more_dict[key] = (False, value[1]) - self.results.extend(res3) - res4.extend(res3) - return res4 - - # TODO RDF: Check if this should be removed or adapted class GenericNetworkEntitiesAutocomplete(autocomplete.Select2ListView): def get(self, request, *args, **kwargs): diff --git a/apis_core/apis_entities/test_api.py b/apis_core/apis_entities/test_api.py deleted file mode 100644 index 1425a559c..000000000 --- a/apis_core/apis_entities/test_api.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.contrib.auth.models import User -from django.test import TestCase -from rest_framework.authtoken.models import Token -from rest_framework.test import APIClient - - -class GetTestCase(TestCase): - @classmethod - def setUpTestData(cls): - # Set up data for the whole TestCase - user = User.objects.create_user(username="lauren", password="pas_1234$") - token = Token.objects.create(user=user) - client = APIClient() - client.credentials(HTTP_AUTHORIZATION="Token " + token.key) - cls.c = client diff --git a/apis_core/apis_entities/test_models.py b/apis_core/apis_entities/test_models.py deleted file mode 100644 index 0e09bdc3e..000000000 --- a/apis_core/apis_entities/test_models.py +++ /dev/null @@ -1,26 +0,0 @@ -from django.test import TestCase -from django.contrib.auth.models import User, Group -from rest_framework.authtoken.models import Token -from rest_framework.test import APIClient -from django.contrib.auth.models import Permission - - -class PermissionsModelTestCase(TestCase): - name = "test name" - first_name = "test first name" - col_name = "Test collection" - start_date = "1.3.1930" - end_date = "4.6.1960" - - @classmethod - def setUpTestData(cls): - # Set up data for the whole TestCase - cls.user = User.objects.create_user("testuser", "apisdev16") - pe = Permission.objects.get(name="Can change person") - cls.user.user_permissions.add(pe) - cls.token = Token.objects.create(user=cls.user).key - cls.group = Group.objects.create(name="testgroup") - cls.col.groups_allowed.add(cls.group) - cls.user.groups.add(cls.group) - cls.c = APIClient() - cls.c.credentials(HTTP_AUTHORIZATION="Token " + cls.token) diff --git a/apis_core/apis_entities/tests.py b/apis_core/apis_entities/tests.py deleted file mode 100644 index a39b155ac..000000000 --- a/apis_core/apis_entities/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/apis_core/apis_metainfo/api_renderers.py b/apis_core/apis_metainfo/api_renderers.py deleted file mode 100644 index ed109c150..000000000 --- a/apis_core/apis_metainfo/api_renderers.py +++ /dev/null @@ -1,25 +0,0 @@ -from django.template.loader import render_to_string -from rest_framework import renderers -from rest_framework_csv.renderers import CSVRenderer - - -class TEIBaseRenderer(renderers.BaseRenderer): - media_type = "application/xml+tei" - format = "xml" - - def render(self, data, media_type=None, renderer_context=None): - data = render_to_string( - "apis_metainfo/TEI_renderer.xml", - {"data": data, "renderer_context": renderer_context}, - ) - - return data - - -class PaginatedCSVRenderer(CSVRenderer): - results_field = "results" - - def render(self, data, *args, **kwargs): - if not isinstance(data, list): - data = data.get(self.results_field, []) - return super(PaginatedCSVRenderer, self).render(data, *args, **kwargs) diff --git a/apis_core/apis_metainfo/serializers.py b/apis_core/apis_metainfo/serializers.py index da0a65e0b..2d934e3cf 100644 --- a/apis_core/apis_metainfo/serializers.py +++ b/apis_core/apis_metainfo/serializers.py @@ -1,29 +1,10 @@ -from django.contrib.contenttypes.models import ContentType from rest_framework import serializers -from .models import Collection, Uri +from .models import Uri from apis_core.generic.serializers import GenericHyperlinkedModelSerializer -class CollectionSerializer(serializers.HyperlinkedModelSerializer): - url = serializers.HyperlinkedIdentityField( - view_name="apis:apis_api:text-detail", lookup_field="pk" - ) - collection_type = serializers.HyperlinkedRelatedField( - view_name="apis:apis_api:collectiontype-detail", - lookup_field="pk", - read_only=True, - ) - parent_class = serializers.HyperlinkedRelatedField( - view_name="apis:apis_api:collection-detail", lookup_field="pk", read_only=True - ) - - class Meta: - fields = ["url", "name", "description", "collection_type", "parent_class"] - model = Collection - - class UriSerializer(GenericHyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField( view_name="apis:apis_api:uri-detail", lookup_field="pk" @@ -32,13 +13,3 @@ class UriSerializer(GenericHyperlinkedModelSerializer): class Meta: fields = "__all__" model = Uri - - -class ContentTypeSerializer(serializers.HyperlinkedModelSerializer): - url = serializers.HyperlinkedIdentityField( - view_name="apis:apis_api:contenttype-detail", lookup_field="pk" - ) - - class Meta: - fields = "__all__" - model = ContentType diff --git a/apis_core/apis_relations/tests.py b/apis_core/apis_relations/tests.py deleted file mode 100644 index a39b155ac..000000000 --- a/apis_core/apis_relations/tests.py +++ /dev/null @@ -1 +0,0 @@ -# Create your tests here. diff --git a/apis_core/testrunners.py b/apis_core/testrunners.py deleted file mode 100644 index 6b9bf5d5c..000000000 --- a/apis_core/testrunners.py +++ /dev/null @@ -1,146 +0,0 @@ -import random -import string - -from django.test.runner import DiscoverRunner -from django.contrib.contenttypes.models import ContentType as ct -from django.db.models import fields as ft_dj - - -def create_data(ft, ln=5): - print(ft) - if ft == ft_dj.CharField or ft == ft_dj.TextField: - return "".join(random.choices(string.ascii_letters + " ", k=ln)) - elif ft == ft_dj.IntegerField or ft == ft_dj.PositiveIntegerField: - return int("".join(random.choices(string.digits, k=ln))) - elif ft == ft_dj.DateField: - return ( - f"{random.randint(1, 30)}.{random.randint(1, 12)}.{random.randint(1, 2020)}" - ) - elif ft == ft_dj.BooleanField: - return bool(random.getrandbits(1)) - else: - print("didnt find any matching dt") - - -class APISTestRunner(DiscoverRunner): - def setup_databases(self, **kwargs): - old_names = super().setup_databases(**kwargs) - - lst_cont = [ - x.model_class() - for x in ct.objects.filter( - app_label__in=[ - "apis_metainfo", - "apis_entities", - "apis_relations", - ] - ) - .exclude( - model__in=[ - "tempentityclass", - "texttype_collections", - "uricandidate", - ] - ) - .exclude(model__icontains="baseclass") - ] - lst_sort = [ - ct.objects.get(app_label="apis_metainfo", model="uri").model_class() - ] - len_lst_cont = len(lst_cont) - len_lst_sort = len(lst_sort) - - while len(lst_cont) > len(lst_sort): - for c in lst_cont: - if c in lst_sort: - continue - check = True - for fld in c._meta.get_fields() + c._meta.many_to_many: - if "_set" in fld.name or fld.name in [ - "parent_class", - "vocab_name", - "userAdded", - "groups_allowed", - ]: - continue - if fld.__class__.__name__ in ["ForeignKey", "ManyToManyField"]: - if fld.related_model not in lst_sort: - print(f"{c} / {fld}") - check = False - if check: - lst_sort.append(c) - if len_lst_cont == len(lst_cont) and len_lst_sort == len(lst_sort): - print(lst_cont) - print(lst_sort) - print(len(lst_cont), len(lst_sort)) - fails = [x for x in lst_cont if x not in lst_sort] - print(f"the following ents failed: {fails}") - raise ValueError("no change in figures") - len_lst_cont = len(lst_cont) - len_lst_sort = len(lst_sort) - dict_ents = {} - l2 = lst_sort.pop() - lst_sort.append(l2) - print(lst_sort) - for ent in lst_sort[1:]: - print(ent) - print(f"working on {ent}") - c_1 = {} - for fld in ent._meta.get_fields(): - print(f"working on field {fld.name}") - ck = False - for pn in ["_ptr", "set", "baseclass"]: - if pn in fld.name: - ck = True - break - if fld.__class__.__name__ == "DateField" or ck: - continue - elif fld.name in [ - "parent_class", - "userAdded", - "vocab_name", - "id", - "vocabsuri", - ]: - continue - elif "date_written" in fld.name: - c_1[fld.name] = create_data(ft_dj.DateField) - elif fld.__class__.__name__ == "ForeignKey": - c_1[fld.name] = dict_ents[fld.related_model.__name__][ - random.randint( - 0, len(dict_ents[fld.related_model.__name__]) - 1 - ) - ] - elif ( - fld.__class__.__name__ != "ManyToManyField" - and fld.__class__.__name__ != "ManyToOneRel" - ): - c_1[fld.name] = create_data( - fld.__class__, - random.randint( - 1, - (fld.max_length if fld.max_length else 3) - if hasattr(fld, "max_length") - else 3, - ), - ) - print(c_1) - c_1_obj = ent.objects.create(**c_1) - for fld in c._meta.many_to_many: - if "_set" in fld.name: - continue - getattr(c_1_obj, fld.name).add( - dict_ents[fld.related_model.__name__][ - random.randint( - 0, len(dict_ents[fld.related_model.__name__]) - 1 - ) - ] - ) - if ent.__class__.__name__ not in dict_ents.keys(): - dict_ents[ent.__name__] = [ - c_1_obj, - ] - else: - dict_ents[ent.__name__].append(c_1_obj) - print(f"created {c_1_obj}") - return old_names