Skip to content

Instantly share code, notes, and snippets.

Factory Trade Destine Port Shipper Modal Origin Port Transport Road Freight Shipper Freight
factory 0 Far East Hong Kong Shipper 0 Road Santos Third Party 6000 8000
factory 1 Mediterranean Barcelona Shipper 1 Train Santos Private 5000 9000
factory 2 North America Seattle Shipper 3 Road Santos Third Party 9000 5000
import datetime
import pandas_datareader as pdr
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
btc_data = pdr.get_data_yahoo(['BTC-USD'],
start=datetime.datetime(2018, 1, 1),
end=datetime.datetime(2020, 12, 3))['Close']
from django.apps import AppConfig
class TestappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'testapp'
def ready(self):
import djwto.tokens as tokens
#./djwto_project/settings.py
(...)
DJWTO_SIGNING_KEY = os.environ['DJWTO_SIGNING_KEY']
DJWTO_MODE = 'JSON'
DJWTO_REFRESH_COOKIE_PATH = 'api/token/refresh'
DJWTO_SAME_SITE = 'Lax'
import requests
sess = requests.Session()
sess.verify = False # For testing locally
sess.post('https://localhost:8002/login/',
data={'username': 'alice', 'password': 'pass'})
sess.headers.update({'X-CSRFToken': sess.cookies['csrftoken']})
r = sess.get('https://localhost:8002/protect/')
# ./testapp/urls.py
from django.urls import path
from .views import ProtectedView, PermsProtectedView
urlpatterns = [
path('protect/', ProtectedView.as_view(), name='protect'),
path('perms_protect/', PermsProtectedView.as_view(), name='perms_protect')
]
# ./testapp/views.py
import djwto.authentication as auth # type: ignore
from django.views import View
from django.utils.decorators import method_decorator
from django.http.response import HttpResponse
class ProtectedView(View):
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
import requests
sess = requests.Session()
sess.verify = False # For testing locally
sess.post('https://localhost:8002/login/',
data={'username': 'alice', 'password': 'pass'})
sess.headers.update({'X-CSRFToken': sess.cookies['csrftoken']})
r = sess.post('https://localhost:8002/api/token/refresh/validate_refresh/',
import requests
sess = requests.Session()
sess.verify = False # For testing locally
sess.post('https://localhost:8002/login/',
data={'username': 'alice', 'password': 'pass'})
sess.headers.update({'X-CSRFToken': sess.cookies['csrftoken']})
r = sess.post('https://localhost:8002/validate_access/',
import requests
sess = requests.Session()
sess.verify = False # For testing locally
r = sess.post('https://localhost:8002/login/',
data={'username': 'alice', 'password': 'pass'})
sess.headers.update({'AUTHORIZATION': f'Bearer {r.json()["access"]}'})