This document is a reference for common testing patterns in a Django/Python project using Pytest.
Contents:
#!/bin/bash | |
DEVICE=/dev/$(lsblk -n | awk '$NF != "/" {print $1}') | |
FS_TYPE=$(file -s $DEVICE | awk '{print $2}') | |
MOUNT_POINT=/data | |
# If no FS, then this output contains "data" | |
if [ "$FS_TYPE" = "data" ] | |
then | |
echo "Creating file system on $DEVICE" |
This document is a reference for common testing patterns in a Django/Python project using Pytest.
Contents:
# Python start-up file | |
# -------------------- | |
# Ensure a PYTHONSTARTUP environment variable points to the location of this file. | |
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP | |
# Always have pp available | |
from pprint import pprint as pp | |
# Pre-emptively import datetime as I use it a lot. | |
import datetime |
#!/usr/bin/env bash | |
# | |
# Get the value of a tag for a running EC2 instance. | |
# | |
# This can be useful within bootstrapping scripts ("user-data"). | |
# | |
# Note the EC3 instance needs to have an IAM role that lets it read tags. The policy | |
# JSON for this looks like: | |
# | |
# { |
import base64 | |
from django.http import HttpResponse | |
from django.contrib.auth import authenticate | |
from django.conf import settings | |
def view_or_basicauth(view, request, *args, **kwargs): | |
# Check for valid basic auth header | |
if 'HTTP_AUTHORIZATION' in request.META: |
#!/usr/bin/env bash | |
# | |
# Bootstrap script for setting up a new OSX machine | |
# | |
# This should be idempotent so it can be run multiple times. | |
# | |
# Some apps don't have a cask and so still need to be installed by hand. These | |
# include: | |
# | |
# - Twitter (app store) |
#!/usr/bin/python3 | |
# | |
# This script can be used as a Alfred Script Filter in a custom workflow for converting numbers to durations. | |
# To do so, create a new workflow, add a script filter with contents './convert "$@"', ensuring that the | |
# query is passed as "with input as argv". | |
# | |
# It's useful to connect a "Copy to Clipboard" output action to make it easier to paste the duration string somewhere. | |
import argparse | |
import json |
# Easier port forwarding - usage: | |
# | |
# $ portforward project-app1 5432 | |
# | |
# where 'project-app1' is an alias from ~/.ssh/config and 5432 is the remote | |
# port that you want to forward to. | |
function portforward() { | |
HOST=$1 | |
REMOTE_PORT=$2 | |
# Pick a random port and check it is free |
# Requires the requests library (install with 'pip install requests') | |
import requests | |
class APIClient(object): | |
BASE_URL = "https://api.octopus.energy/v1" | |
class DataUnavailable(Exception): | |
""" | |
Catch-all exception indicating we can't get data back from the API |