Skip to content

Instantly share code, notes, and snippets.

View tangorboyz's full-sized avatar

Vincent Dhawu tangorboyz

  • Denpasar, Indoesia
View GitHub Profile
@tangorboyz
tangorboyz / util.py
Last active October 28, 2017 10:00
Implement generic wait for element when testing with selenium instead of implicit wait
import time
import unittest
from hamcrest import assert_that, contains_string
from selenium.common.exceptions import WebDriverException
from selenium.webdriver import Chrome
def wait_for_element(browser, method_name, selector, max_wait=10):
start_time = time.time()
while True:
@tangorboyz
tangorboyz / forms.py
Last active October 27, 2017 17:33 — forked from fohlin/forms.py
A version of Django's UserCreationForm that uses email instead of username, with some nifty features. (Maybe not super robust yet, in terms of concurrency...)
import re
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
class UniqueUserEmailField(forms.EmailField):
"""
An EmailField which only is valid if no User has that email.
"""
def validate(self, value):
@tangorboyz
tangorboyz / flask_csrf_test_client.py
Created October 7, 2017 23:13 — forked from singingwolfboy/flask_csrf_test_client.py
Want to run your Flask tests with CSRF protections turned on, to make sure that CSRF works properly in production as well? Here's an excellent way to do it!
# Want to run your Flask tests with CSRF protections turned on, to make sure
# that CSRF works properly in production as well? Here's an excellent way
# to do it!
# First some imports. I'm assuming you're using Flask-WTF for CSRF protection.
import flask
from flask.testing import FlaskClient as BaseFlaskClient
from flask_wtf.csrf import generate_csrf
# Flask's assumptions about an incoming request don't quite match up with