commit
ca33960c44
3 changed files with 13 additions and 1 deletions
|
|
@ -3,13 +3,17 @@ import os
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
from .models import Post, Collection
|
from .models import Post, Collection
|
||||||
|
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
|
|
||||||
|
|
||||||
class TestModelTests(TestCase):
|
class TestModelTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.user = get_user_model().objects.create(email="someone@example.com")
|
||||||
with open(
|
with open(
|
||||||
os.path.join(os.path.dirname(__file__), "test_data", "test_img.png"),
|
os.path.join(os.path.dirname(__file__), "test_data", "test_img.png"),
|
||||||
mode="rb",
|
mode="rb",
|
||||||
|
|
@ -18,6 +22,7 @@ class TestModelTests(TestCase):
|
||||||
img=File(f, "somefile.png"),
|
img=File(f, "somefile.png"),
|
||||||
title="Foobar",
|
title="Foobar",
|
||||||
body="Some file",
|
body="Some file",
|
||||||
|
user=self.user,
|
||||||
)
|
)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
|
@ -27,5 +32,7 @@ class TestModelTests(TestCase):
|
||||||
self.assertIn("Foobar", str(self.post))
|
self.assertIn("Foobar", str(self.post))
|
||||||
|
|
||||||
def test_collection_has_sensible_str(self):
|
def test_collection_has_sensible_str(self):
|
||||||
col = Collection.objects.create(title="A collection", description="foobar")
|
col = Collection.objects.create(
|
||||||
|
title="A collection", description="foobar", user=self.user
|
||||||
|
)
|
||||||
self.assertIn("A collection", str(col))
|
self.assertIn("A collection", str(col))
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
pillow
|
pillow
|
||||||
django
|
django
|
||||||
|
coverage
|
||||||
|
|
|
||||||
4
run_coverage
Executable file
4
run_coverage
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
PYTHONPATH=. DJANGO_SETTINGS_MODULE=config.settings.development coverage run -m django test
|
||||||
|
coverage html
|
||||||
|
xdg-open ./htmlcov/index.html
|
||||||
Loading…
Add table
Reference in a new issue