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
from django.db import transaction | |
def before_all(context): | |
transaction.set_autocommit(False) | |
def before_scenario(context, scenario): | |
context._savepoint = transaction.savepoint() |
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
# retrieve webelement | |
input = driver.find_element_by_xpath("//*[@name='fieldname']") | |
# set attribute from js script referencing webelement found in python code | |
driver.execute_script("arguments[0].setAttribute('value', 'new value!')", input); | |
# or | |
driver.execute_script("arguments[0].setAttribute('value', arguments[1])", input, 'new value!'); | |
# Code for File Upload | |
file_input = driver.find_element_by_id("uploadBtn") | |
file_input.send_keys("/absolute/path/to/file") |
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
# Use a custom compare function that converts the strings into sub-lists of integers. Those will sort correctly without problems. | |
ls = ['1.1', '1.10', '1.2', '1.2.3', '1.2.1', '1.9'] | |
def section(s): | |
return [int(_) for _ in s.split(".")] | |
sorted(ls, key=section) | |
# ['1.1', '1.2', '1.2.1', '1.2.3', '1.9', '1.10'] |
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
driver = context.browser | |
# first set a long timeout for async scripts | |
driver.set_script_timeout(10) | |
# then prepare an async function | |
# eg. retrieve status of a jquery ajax GET | |
status_code = driver.execute_async_script(""" | |
var done = arguments[0]; | |
$.ajax({ |
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
# You can pass additional context to the template using keyword arguments: | |
{% include "name_snippet.html" with person="Jane" greeting="Hello" %} | |
# If you want to render the context only with the variables provided (or even no variables at all), use the only option. No other variables are available to the included template: | |
{% include "name_snippet.html" with greeting="Hi" only %} |
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
Use the fa-spin class to get any icon to rotate, and use fa-pulse to have it rotate with 8 steps. Works well with fa-spinner, fa-refresh, and fa-cog. | |
<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i> | |
<span class="sr-only">Loading...</span> | |
<i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i> | |
<span class="sr-only">Loading...</span> | |
<i class="fa fa-refresh fa-spin fa-3x fa-fw"></i> | |
<span class="sr-only">Loading...</span> |
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
@receiver(post_save, sender=Article) | |
def generate_thumbnails(sender, instance=None, created=False, **kwargs): | |
if not instance: | |
return | |
if hasattr(instance, '_dirty'): | |
return | |
do_something() |
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
// create | |
docker-machine create -d virtualbox --virtualbox-memory '2048' --virtualbox-cpu-count '2' default | |
// list and start | |
docker-machine ls | |
docker-machine start default | |
docker-machine env | |
eval $(docker-machine env) | |
// stop |
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
dict(map(list, (("a",1), ("b",2)))) | |
# {'a': 1, 'b': 2} | |
dict(map(reversed, (("a",1), ("b",2)))) | |
# {1: 'a', 2: 'b'} | |
# from function list, usable for eval | |
dict(map(lambda x: (x.__name__, x), [round, abs])) | |
# {'abs': <function abs>, 'round': <function round>} |
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 os | |
import socket | |
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = '0.0.0.0:8000' | |
class IntegrationTests(StaticLiveServerTestCase): | |
live_server_url = 'http://{}:8000'.format( | |
socket.gethostbyname(socket.gethostname()) | |
) |