Skip to content

Instantly share code, notes, and snippets.

@chfw
chfw / gist:ce131c95da283ede3256
Created December 16, 2015 16:46
How to mock django model's delete method
def do_it(token, logger):
try:
tm = AMODEL.objects.get(unique_id=token)
tm.delete()
except Exception as e:
logger.error("...")
class FakeLogger:
def __init__(self):
@chfw
chfw / gist:4ab8b8f74a1b41d4555f
Created January 25, 2016 17:12
how to mock a global variable in a python file
@patch("module.file.BASE_PATH", 'tests/fixtures')
def test_organisation_to_es_document():
# do the test normally
default_bar_format = '{desc}{percentage:3.0f}%|{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}]'
red_bar_format = '{desc}{percentage:3.0f}%|\033[91m{bar}\033[00m| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}]'
http://archive.is/6V2bl
@chfw
chfw / how to install ruby-compass on fedora 23 work station
Created February 25, 2016 11:20
how to install ruby-compass on fedora 23 work station
sympton:
[chfw@ gui]$ cat /home/chfw/.gem/ruby/extensions/x86-linux/ffi-1.9.10/gem_make.out
/usr/bin/ruby -r ./siteconf20160225-10482-1jrwbf5.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
@chfw
chfw / gist:708116e608cb84855d85
Created March 10, 2016 15:46
unit tests for angular 1.5.0 cannot be run inside phantomjs :'(
more details here https://github.com/angular/angular.js/issues/13794
@chfw
chfw / base64
Created March 15, 2016 10:52
inject base64 in karma
for test that has a dependency on base64
Error: [$injector:unpr] Unknown provider: $base64Provider <- $base64 <- <- Xcomponent
to get rid of it,
1) include bower_components/angular-base64/angular-base64.js in karma.conf.js
2) in the test case, put this along with others
it's been challenging to do that simple task, which is put a print statement in the emptied module file. when it comes to testing,
the first block is to how to test the output? one solution is to mock sys.stdout, the other is to wrap print in a function and patch it.
the second block is the module is already loaded and won't be loaded again. Hence you need to reload it. for reload, py2 and py3 had a
difference in where the reload comes from. here is the code to get around.
try:
reload
except NameError:
from imp import reload
@chfw
chfw / gist:e2e508f8b0183fda072ae11e8c4567a0
Created August 18, 2016 10:10
how to download static rpms for production centos
def production centos has no connection to internet except serving port
background production machine was not set up by you, hence you need to perform addtional setup.
1. get a replica of production centos and connect it to internet
2. `repotrack emacs -u |xargs wget`
exception:
if architecture differs, e.g. i386 local but x86_64 in production, you can do
@chfw
chfw / gist:b619f02436c339db66a175a29531994a
Created January 17, 2017 14:35
oracle insert into table with seq
INSERT INTO USER_TABLE VALUES (SEQ_USER.NEXTVAL, 's', 'x');