This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from django_jenkins.runner import CITestSuiteRunner | |
from django.test import TestCase | |
from django.test.simple import reorder_suite | |
from django_jenkins import signals | |
class OrderedCITestSuiteRunner(CITestSuiteRunner): | |
""" | |
This particular test suite runner do Django test cases ordering, | |
putting TransactionTestCase to the end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume you have model ``Project`` with 1:M relation to ``Task`` | |
# here ``p`` instance of ``Project``, and it has some amount of tasks | |
# Following inline is creating global variable ``t<idx>`` for each task (e.g. t1, t2, ...) | |
[globals().update({'t%s' % (idx + 1): t}) for idx, t in enumerate(p.tasks.all())] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REPLACE_MAP = ( | |
('project_dir', project_dir), | |
('user', user) | |
) | |
TEMPLATE = '{{ %s }}' | |
for line in source.readlines(): | |
dest.write( | |
reduce( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update(instance, **kwargs): | |
"""Helper to update instance of the model with data from kwargs.""" | |
instance.__class__.objects.filter(pk=instance.pk).update(**kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def trafaret_tutorial(): | |
""" | |
So, you have some structure from wild. Say this will be some JSON over API. | |
But you cant change this JSON structure. | |
""" | |
sample_data = { | |
'userNameFirst': 'Adam', | |
'userNameSecond': 'Smith', | |
'userPassword': 'supersecretpassword', | |
'userEmail': 'adam@smith.math.edu', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FakeDatetimeFactory(object): | |
"""Factory to help testing logic depending on ``datetime.now()``. | |
""" | |
@classmethod | |
def now(self, *args, **kwargs): | |
class FakeDatetime(datetime): | |
"""Datetime class with overriden ``now()`` method.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1.s | |
# | |
# My first MIPS Assembly program | |
# This program let you input 2 numbers and output the result of addition | |
.data | |
prompt_msg: .asciiz "Enter two numbers to add:\n" | |
result_msg: .asciiz "Result: " | |
end_of_line: .asciiz "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script needs to be run from inside the project folder | |
# since it needs access to settings.py | |
# | |
# DISCLAMER: Use _only_ on local dev installation! | |
DB_NAME=`python -c "import settings; print settings.DATABASES['default']['NAME']"` | |
DB_USER=`python -c "import settings; print settings.DATABASES['default']['USER']"` | |
DB_PASS=`python -c "import settings; print settings.DATABASES['default']['PASSWORD\ | |
']"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SettingsContextManager(object): | |
"""Allow to change ``settings.*`` in ``with`` context.""" | |
def __init__(self, *settings_tuples): | |
self.settings = dict(settings_tuples) | |
self.orig_settings = dict([(key, getattr(settings, key)) | |
for key in self.settings]) | |
def __enter__(self, *args, **kwargs): | |
[setattr(settings, key, self.settings[key]) | |
for key in self.settings] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _Stub(object): | |
"""Class for creating stub object. | |
For internal use. | |
""" | |
def __getattribute__(self, *args, **kwargs): | |
return self | |
def next(self): | |
raise StopIteration |
OlderNewer