Skip to content

Instantly share code, notes, and snippets.

@chrisdev
Forked from qingfeng/models.py
Created March 4, 2013 10:23

Revisions

  1. qingfeng created this gist May 16, 2010.
    8 changes: 8 additions & 0 deletions models.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    from django.db import models

    class M1(models.Model):
    title = models.CharField(max_length=100)
    img1 = models.ImageField(upload_to="static/")

    def __unicode__(self):
    return self.title
    21 changes: 21 additions & 0 deletions tests.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    """
    This file demonstrates two different styles of tests (one doctest and one
    unittest). These will both pass when you run "manage.py test".
    Replace these with more appropriate tests for your application.
    """

    from django.test import TestCase
    from django.core.files import File
    from app1.models import M1

    class SimpleTest(TestCase):
    def test_basic_addition(self):
    m1 = M1()
    m1.title = "aaa"
    m1.img1 = File(open("/tmp/p5/twitter.jpg"))
    m1.save()

    p = M1.objects.get(id=1).img1.path

    self.failUnless(open(p), 'file not found')