This document is a reference for common testing patterns in a Django/Python project using Pytest.
Contents:
This document is a reference for common testing patterns in a Django/Python project using Pytest.
Contents:
"""A set of helpers for reversing urls, similar to Django ``reverse``. | |
Usage: | |
.. code:: python | |
@router.get("/class/{class_id}") | |
async def get_class(request: Request, class_id: int = Path(...)): | |
student_route = get_route(request.app, "list_students") | |
class_students_url = URLFactory(student_route).get_path(class_id=class_id) |
1 cd ~ | |
2 clear | |
3 sudo hostnamectl set-hostname k8s-master | |
4 hostname | |
5 sudo reboot | |
6 cd ~ | |
7 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
8 ls | |
9 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ | |
10 $(lsb_release -cs) \ |
{ | |
// Editor | |
// When enabled, the diff editor ignores changes in leading or trailing whitespace. | |
"diffEditor.ignoreTrimWhitespace": true, | |
// Timeout in milliseconds after which diff computation is cancelled. Use 0 for no timeout. | |
"diffEditor.maxComputationTime": 5000, | |
// Controls whether the diff editor shows +/- indicators for added/removed changes. |
This is the era of containerization and orchestration where majority of the application are following the trend of running on a container which are further deployed in a Kubernetes cluster. It’s sometimes necessary to prepare the main container which will be running our application or the main logic.
There can also be situations where we need to execute a particular utilities or setup scripts that are not present in our main image ( as it would make it heavy and we only need it once in the beginning ).
Kubernetes provides special type of containers that runs to completion before the main app's container and Kubernetes will repeatedly restarts the Pod until the init container succeeds. Some of its properties are :
from rest_framework.filters import OrderingFilter | |
class CustomOrderFilter(OrderingFilter): | |
allowed_custom_filters = ['user_city', 'user_country'] | |
fields_related = { | |
'user_city': 'user__city__name', # ForeignKey Field lookup for ordering | |
'user_country': 'user__country__name' | |
} | |
def get_ordering(self, request, queryset, view): |
package main | |
// This is an example of a resilient worker program written in Go. | |
// | |
// This program will run a worker, wait 5 seconds, and run it again. | |
// It exits when SIGINT or SIGTERM is received, while ensuring any ongoing work | |
// is finished before exiting. | |
// | |
// Unexpected panics are also handled: program won't crash if the worker panics. | |
// However, panics in goroutines started by the worker won't be handled and have |
We frequently use pydantic at Pluralsight to validate data at the edge of a well typed domain. I've been trying to sell my coworkers on using hypothesis for testing, and thought it might go easier if they could generate test data from existing pydantic schemas. I found that it was almost trivial for data classes, but BaseModel
subclasses (which are unfortunately much more common in our code) don't play as nicely, and deeply nested schemas can get you into trouble. If anyone has any advice on how to get around the errors that come from the last test, I'd be super greatful.
import inspect | |
from typing import Any, Callable, List, Type, TypeVar, Union, get_type_hints | |
from fastapi import APIRouter, Depends | |
from pydantic.typing import is_classvar | |
from starlette.routing import Route, WebSocketRoute | |
T = TypeVar("T") | |
CBV_CLASS_KEY = "__cbv_class__" |
version: "3" | |
services: | |
mongo1: | |
hostname: mongo1 | |
container_name: localmongo1 | |
image: mongo:4.0-xenial | |
expose: | |
- 27017 | |
ports: | |
- 27011:27017 |