Test Driven Development with Django & Django Rest Framework – Part 2

In case you missed it, check out part 1 of this series.

TDD – Models, Forms, and Serializers

Testing Tools docs

Django Forms – docs

Django ModelForms – docs

Serializers – docs

Test Objectives

# test fields of the forms

# test creation of form objects

# test output of rendered forms

# test form validators

# exclude unneeded values

from pprint import pprint as p
# get the meta fields for a model as a stringified list
def get_model_fields_as_list(model):
    fields_list = []
    for m in model._meta.get_fields():
    fields_string = json.dumps(fields_list)
    p('as list: '+str(fields_string))   # dump as string
    # p('as data: '+str(fields_list))   # dump as data

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>