Skip to content

Instantly share code, notes, and snippets.

@gonzaloamadio
gonzaloamadio / test_unmanaged_models.md
Created May 27, 2021 18:40 — forked from raprasad/test_unmanaged_models.md
Ignoring migrations during Django testing (unmanaged databases, legacy databases, etc)

Scenario

  • Django 1.9 application with two databases:
    • Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to False
      • 'managed': False
    • Default database holding django specific tables (e.g. auth_user, django_content_type, etc)

Testing Woes

import uuid
from django.db import models
class UUIDField(
models.UUIDField
):
def __init__(self, *args, **kwargs):
self.version = kwargs.pop('version', 1)
#!/usr/bin/env bash
log() { echo -e "\e[0;33m${1}\e[0m"; }
# Ask for the administrator password upfront.
sudo -v
log 'Empty the Trash on all mounted volumes and the main HDD...'
sudo rm -rfv /Volumes/*/.Trashes
sudo rm -rfv ~/.Trash
@gonzaloamadio
gonzaloamadio / debugging_decorators.py
Last active November 5, 2019 21:45 — forked from chadgh/debugging_decorators.py
python decorators for; debugging, threading
def timeit(function):
'''Decorator used for debugging. Prints the call and how long it took.'''
def timed(*args, **kwargs):
ts = time.time()
result = function(*args, **kwargs)
te = time.time()
print("{0} ({1}, {2}) {3:.2} sec"
.format(function.__name__, args, kwargs, te - ts))