Skip to content

Instantly share code, notes, and snippets.

@va3093
va3093 / easy_http_mock.py
Last active June 26, 2017 08:58
Convenient way to mock http requests in your tests by wrapping the functionality of httppretty.
import httpretty
import requests
def stub_http_request(method='GET', url=None, status=200, json={}):
def wrap(func):
@httpretty.activate
def wrapped_func(*args, **kwargs):
httpretty.register_uri(method, url,
body=f"{json}".replace("'", '"'),
# Create file logger for debugging
import logging
f_log = logging.getLogger('spam_application')
f_log.setLevel(logging.DEBUG)
fh = logging.FileHandler('/Users/wilhelm.vanderwalt/Desktop/file_logger.log')
fh.setLevel(logging.DEBUG)
f_log.addHandler(fh)
@va3093
va3093 / access.md
Created February 4, 2021 12:20
Access k8s example

Access K8s example

I played around with a few approaches and this seems to be the simplest. You can use this to experiment with the api.

This sets up an ubuntu box with curl pre-installed. It also creates a service account with permissions to see pods and jobs. The auth token created by this service account is stored at /var/run/secrets/kubernetes.io/serviceaccount/token

apiVersion: v1
kind: ServiceAccount
metadata:
  name: access-k8s-api
import csv
import datetime
import gzip
import logging
import os
import requests
import simplejson as json
import sys
import time
from typing import List