* writes test for sharing using the API
* fixes bug on frontend form where an exception occured on generating a new API token if no token existed, yet
* adds permission constraint (default group) for using the api in general
* fixes default-group-only behaviour for sharing-API, so users can only add new users and not removing them, as long as they do not have any other group membership like registration or conservation office
* changes 'ksptoken' to 'Ksptoken' to match CGI standard for http header keys
This commit is contained in:
2022-01-27 14:48:42 +01:00
parent 6deff28389
commit 1b0ab1be07
8 changed files with 201 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ Created on: 26.10.21
"""
import datetime
from ema.models import Ema
from user.models import User
from django.contrib.auth.models import Group
from django.contrib.gis.geos import MultiPolygon, Polygon
@@ -52,6 +53,7 @@ class BaseTestCase(TestCase):
cls.intervention = cls.create_dummy_intervention()
cls.compensation = cls.create_dummy_compensation()
cls.eco_account = cls.create_dummy_eco_account()
cls.ema = cls.create_dummy_ema()
cls.create_dummy_states()
cls.create_dummy_action()
cls.codes = cls.create_dummy_codes()
@@ -168,6 +170,30 @@ class BaseTestCase(TestCase):
)
return eco_account
@classmethod
def create_dummy_ema(cls):
""" Creates an ema which can be used for tests
Returns:
"""
# Create dummy data
# Create log entry
action = UserActionLogEntry.get_created_action(cls.superuser)
geometry = Geometry.objects.create()
# Create responsible data object
responsible_data = Responsibility.objects.create()
# Finally create main object, holding the other objects
ema = Ema.objects.create(
identifier="TEST",
title="Test_title",
responsible=responsible_data,
created=action,
geometry=geometry,
comment="Test",
)
return ema
@classmethod
def create_dummy_states(cls):
""" Creates an intervention which can be used for tests