Django tool
Project description
shopcloud-django-toolbox
install
$ pip install shopcloud-django-toolbox
Models
Add the GID as identifier to all django models
from shopcloud_django_toolbox import GID
class FooBarModel(models.Model, GID):
pass
URL-Signing
generate or load encrypted data versioned and with expiration date for access-control
Usage
settings.py
SIGN_VERISON = "{SET SPECIFIC VERSION HERE}"
dump values dict:
from shopcloud django.toolbox import signer
signing_key = signer.dumps({"foo":"bar"}, expire_in_hours:12)
load values dict:
from shopcloud django.toolbox import signer
def get_request(request):
sign_str = request.GET.get("sign")
is_valid, data = signer.loads(sign_str)
if not is_valid(request):
return HttpResponseForbidden("Not allowed")
data.get("xxx")
...
alternative for a django Request:
from shopcloud django.toolbox import signer
def get_request(request):
is_valid, data = signer.loads_from_request(signing_str)
if not is_valid(request):
return HttpResponseForbidden("Not allowed")
data.get("xxx")
...
Testing
API standart tests
Standart template for the tests.py
file in all modules with admin and REST API`s
from shopcloud_django_toolbox.tests import BaseTestAPIEndpointDoc
from shopcloud_django_toolbox import TestAdminTestCase
from shopcloud_django_toolbox.tests import BaseTestApiAuthorization
from shopcloud_django_toolbox import SetupClass
class TestDocEntpoint(BaseTestAPIEndpointDoc):
pass
__
class TestAdminPages(TestAdminTestCase):
MODULE = 'url-name'
def test_admin_easylineitem(self):
self.run_for_model(
'url-model-name',
is_check_add=False, # deactivate when add function is deactivated
is_check_template=False, # deactivate generic template check
is_check_search=True, # activate searchbar check
)
class TestApiAuthorization(BaseTestApiAuthorization):
app_name = "url-module-name"
def test_model_foo(self):
self.run_test_endpoint("url-model-name")
def test_model_bar(self):
self.run_test_endpoint("url-model-name")
class YoutAPITest(SetupClass):
def test_api_endpint(self):
client = APIClient()
client.login(username=self.username, password=self.pwd)
r = client.get('/module/api/endpoint')
self.assertEqual(r.status_code, status.HTTP_201_CREATED)
Event
To fire events and run tasks in prarallel, need [PROJECT] to receive and run the output from log and call the API.
from shopcloud_django_toolbox import Event
class FooBarModel(models.Model):
...
def do_event(self):
event = Event(
name="de.talk-point.platform/module/model/sync",
model=self,
)
event.add_task(
queue="default",
url=f"moduke/api/model/{self.id}/action/",
json={}
)
event.fire()
deploy
# change version Number in setup.py ändern und dann erst releasen
# delete build and dist-directory
$ rm -rf build
$ rm -rf dist
$ pip3 install wheel twine
$ python3 setup.py sdist bdist_wheel
$ twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for shopcloud_django_toolbox-1.6.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e13dc08e7a0bbec95d2be96052a2b0f77fe26be5d42d4427fe301556f3bf2ce |
|
MD5 | 2d5a32191e2584eb4bc36d0e75791180 |
|
BLAKE2b-256 | d4e9c190f0408e018fb9b7fd64c6b1cb8996f52e33319b8fdf86223fbfb94feb |
Close
Hashes for shopcloud_django_toolbox-1.6.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 984c8658bfbdd5db0ede10331583ecc36c6f9c84fe0108822bb5659710e8e3f1 |
|
MD5 | d9f78b0800e675579267af9e92eaf9f7 |
|
BLAKE2b-256 | d028e4d1dbb41831611f46226ba05dbc834434c7a13b870e2b23f5f1e7673315 |