Skip to content

Commit 6e836a3

Browse files
committed
todolists: port to pytest
1 parent 10b3175 commit 6e836a3

File tree

3 files changed

+46
-65
lines changed

3 files changed

+46
-65
lines changed

todolists/tests/conftest.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
3+
from main.models import Package
4+
from todolists.models import Todolist, TodolistPackage
5+
6+
7+
NAME = 'Boost rebuild'
8+
DESCRIPTION = 'Boost 1.66 rebuild'
9+
RAW = 'linux'
10+
11+
12+
@pytest.fixture
13+
def todolist(admin_user, arches, repos, package):
14+
todolist = Todolist.objects.create(name=NAME,
15+
description=DESCRIPTION,
16+
creator=admin_user,
17+
raw=RAW)
18+
yield todolist
19+
todolist.delete()
20+
21+
22+
@pytest.fixture
23+
def todolistpackage(admin_user, todolist):
24+
pkg = Package.objects.first()
25+
todopkg = TodolistPackage.objects.create(pkg=pkg, pkgname=pkg.pkgname,
26+
pkgbase=pkg.pkgbase, arch=pkg.arch,
27+
repo=pkg.repo, user=admin_user,
28+
todolist=todolist)
29+
yield todopkg
30+
todopkg.delete()

todolists/tests/test_models.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,19 @@
1-
from django.contrib.auth.models import User
2-
from django.test import TestCase
1+
def test_stripped_description(todolist):
2+
todolist.description = 'Boost rebuild '
3+
desc = todolist.stripped_description
4+
assert desc.endswith(' ') == False
35

46

5-
from main.models import Package
6-
from todolists.models import Todolist, TodolistPackage
7+
def test_get_absolute_url(todolist):
8+
assert '/todo/' in todolist.get_absolute_url()
79

810

9-
class TestTodolist(TestCase):
10-
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',
11-
'main/fixtures/package.json']
11+
def test_get_full_url(todolist):
12+
url = todolist.get_full_url()
13+
assert 'https://example.com/todo/' in url
1214

13-
def setUp(self):
14-
self.user = User.objects.create(username="joeuser", first_name="Joe",
15-
last_name="User", email="[email protected]")
16-
self.todolist = Todolist.objects.create(name='Boost rebuild',
17-
description='Boost 1.66 rebuid',
18-
creator=self.user,
19-
raw='linux')
2015

21-
def tearDown(self):
22-
self.todolist.delete()
23-
self.user.delete()
24-
25-
def test_stripped_description(self):
26-
self.todolist.description = 'Boost rebuild '
27-
desc = self.todolist.stripped_description
28-
self.assertFalse(desc.endswith(' '))
29-
30-
def test_get_absolute_url(self):
31-
self.assertIn('/todo/', self.todolist.get_absolute_url())
32-
33-
def test_get_full_url(self):
34-
url = self.todolist.get_full_url()
35-
self.assertIn('https://example.com/todo/', url)
36-
37-
def test_packages(self):
38-
pkg = Package.objects.first()
39-
todopkg = TodolistPackage.objects.create(pkg=pkg, pkgname=pkg.pkgname,
40-
pkgbase=pkg.pkgbase, arch=pkg.arch,
41-
repo=pkg.repo, user=self.user,
42-
todolist=self.todolist)
43-
pkgs = self.todolist.packages()
44-
self.assertEqual(len(pkgs), 1)
45-
self.assertEqual(pkgs[0], todopkg)
16+
def test_packages(admin_user, todolist, todolistpackage):
17+
pkgs = todolist.packages()
18+
assert len(pkgs) == 1
19+
assert pkgs[0] == todolistpackage
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
from django.contrib.auth.models import User
2-
from django.test import TestCase
3-
4-
5-
from main.models import Package
6-
from todolists.models import Todolist, TodolistPackage
71
from todolists.templatetags.todolists import todopkg_details_link
82

93

10-
class TestTodolist(TestCase):
11-
fixtures = ['main/fixtures/arches.json', 'main/fixtures/repos.json',
12-
'main/fixtures/package.json']
13-
14-
def setUp(self):
15-
self.user = User.objects.create(username="joeuser", first_name="Joe",
16-
last_name="User", email="[email protected]")
17-
self.todolist = Todolist.objects.create(name='Boost rebuild',
18-
description='Boost 1.66 rebuid',
19-
creator=self.user,
20-
raw='linux')
21-
22-
def test_details_link(self):
23-
pkg = Package.objects.first()
24-
todopkg = TodolistPackage.objects.create(pkg=pkg, pkgname=pkg.pkgname,
25-
pkgbase=pkg.pkgbase, arch=pkg.arch,
26-
repo=pkg.repo, user=self.user,
27-
todolist=self.todolist)
28-
link = todopkg_details_link(todopkg)
29-
self.assertIn('View package details for {}'.format(todopkg.pkg.pkgname), link)
4+
def test_details_link(todolistpackage):
5+
link = todopkg_details_link(todolistpackage)
6+
assert 'View package details for {}'.format(todolistpackage.pkg.pkgname) in link

0 commit comments

Comments
 (0)