Skip to content

Instantly share code, notes, and snippets.

@bennett39
bennett39 / test_my_command.py
Created September 27, 2021 10:54
Testing Django Admin Commands
from io import StringIO
from django.core.management import call_command
from django.test import TestCase
class MyCommandTest(TestCase):
def test_my_command(self):
out = StringIO() # <-- Use StringIO to capture the output of the command from stdout
args = [] # <-- Any command line arguments go here
kwargs = {'stdout': out} # <-- Any named command line options (e.g. --my-option) go here
alias foo="echo 'I pity the foo'"
{% load static %}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Testing Vue...</h1>
<div id="app"></div>
const path = require('path');
module.exports = {
publicPath: '/static/src/vue/dist/', // Should be STATIC_URL + path/to/build
outputDir: path.resolve(__dirname, '../static/src/vue/dist/'), // Output to a directory in STATICFILES_DIRS
filenameHashing: false, // Django will hash file names, not webpack
runtimeCompiler: true, // See: https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
devServer: {
writeToDisk: true, // Write files to disk in dev mode, so Django can serve the assets
},
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = 'var/static_root/'
STATICFILES_DIRS = ['static']
from django.contrib import admin
from django.urls import path
from myapp import views as myapp_views
urlpatterns = [
path('admin/', admin.site.urls),
path('vue-test', myapp_views.vue_test),
]
from django.shortcuts import render
def vue_test(request):
return render(request, 'myapp/vue-test.html')
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>Testing Vue...</h1>
<div id="app"></div>
</body>
</html>
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
def analyze_audit_history(self):
""" Parse audit history response and separate out deletes vs modifications/creations """
last_modified_by_type, modified_ids, deleted_ids = {}, set(), set()
last_modified_by_type['glbatch'] = arrow.now() # Always consider glbatches modified
for audit_trail in self._get_audit_trail():
for event in audit_trail.response.data.find_all('audithistory'):
object_type = event.objecttype.get_text()
# Consolidate journal and glbatch to be the same, since they hit the same endpoint