Skip to content

Instantly share code, notes, and snippets.

@macndesign
Created October 4, 2012 18:02
Show Gist options
  • Save macndesign/3835322 to your computer and use it in GitHub Desktop.
Save macndesign/3835322 to your computer and use it in GitHub Desktop.
Como rodar esse tipo de test pelo django em arquivo ReestructuredText?

Doctest do model Client

Definindo imports necessários

>>> import os
>>> from django.conf import settings
>>> from django.core.files.images import ImageFile
>>> from core.models import Client

Load fixtures

>>> from django.core import management
>>> management.call_command("loaddata", "core/fixtures/client_testdata.json", verbosity=0)
>>> Client.objects.count()
8

Criando um objeto client

>>> IMAGE = os.path.join(settings.MEDIA_ROOT, 'clients', 'albalab.png')
>>> IMAGE_FILE = ImageFile(open(IMAGE, 'rb'))
>>> c1 = Client()
>>> c1.name = 'Test Client'
>>> c1.image = IMAGE_FILE
>>> c1.save()
>>> print c1.pk
9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment