Skip to content

Instantly share code, notes, and snippets.

@ZQQ1024
ZQQ1024 / settings.py
Created July 15, 2019 02:38 — forked from ipmb/settings.py
Django logging example
import logging.config
import os
from django.utils.log import DEFAULT_LOGGING
# Disable Django's logging setup
LOGGING_CONFIG = None
LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper()
logging.config.dictConfig({
@ZQQ1024
ZQQ1024 / celery.py
Created May 15, 2019 07:44
Django with Celery
# Celery/celery.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('celery',
broker='redis://192.168.56.101',
backend='redis://192.168.56.101',
include=['Celery.tasks'])
# Optional configuration, see the application user guide.
@ZQQ1024
ZQQ1024 / short_circuit.py
Last active May 13, 2019 03:32
Python short-circuit evalution
def fun1():
print('this is fun1')
return True
def fun2():
print('this is fun2')
return False
if(fun1() or fun2()):
print("Logic Or: return value of fun1() is True, fun2() is never evaluated!")
@ZQQ1024
ZQQ1024 / tests.py
Created May 13, 2019 03:16
Django view unittest with mock
from django.test import TestCase
from unittest import mock
from django.urls import reverse
from pay.utils import invokeSum
class TestHello(TestCase):
@mock.patch('pay.views.invokeSum') # invokeSum is imported in hello view
def test_sum(self, mock_sum):
mock_sum.return_value = 30