Patch django form field for testing

2013-04-15 od romanb django, hacks, testing

In case you're wondering how to patch Django form field for testing purposes (like URLField that passes local uri: file://...) here's how:

from .forms import ThatForm
from django import forms

class MyTests(TestCase):
    def test_pass_url(self):
        orig_url = ThatForm.base_fields['url']
        ThatForm.base_fields['url'] = forms.CharField()

        # ... do your thing #

        # and just in case set original field back,
        # if other tests need it:
        ThatForm.base_fields['url'] = orig_url