Skip to content

Commit 3b00678

Browse files
committed
Tests
1 parent f88a09b commit 3b00678

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
from __future__ import division, print_function, unicode_literals
2+
3+
from django.test import TestCase
4+
from django_dynamic_fixture import get
5+
from mock import patch
6+
7+
from readthedocs.builds.models import Version
8+
from readthedocs.projects.models import Project
9+
from readthedocs.projects.tasks import sync_files
10+
11+
12+
class WebTasksTests(TestCase):
13+
14+
def setUp(self):
15+
self.project = get(Project)
16+
self.version = get(Version, project=self.project)
17+
18+
@patch('readthedocs.builds.syncers.Syncer.copy')
19+
@patch('readthedocs.projects.tasks.shutil.rmtree')
20+
def test_sync_files_clean_old_artifacts(self, rmtree, copy):
21+
sync_files(self.project.pk, self.version.pk, 'sphinx', html=True)
22+
pdf, epub = rmtree.call_args_list
23+
24+
# pdf and epub are cleaned
25+
args, _ = pdf
26+
self.assertIn('pdf', args[0])
27+
args, _ = epub
28+
self.assertIn('epub', args[0])
29+
30+
# Artifacts are copied to the rtd-builds directory
31+
copy.assert_called_once()
32+
args, _ = copy.call_args
33+
self.assertIn('artifacts', args[0])
34+
self.assertIn('sphinx', args[0])
35+
self.assertIn('rtd-builds', args[1])
36+
37+
@patch('readthedocs.builds.syncers.Syncer.copy')
38+
@patch('readthedocs.projects.tasks.shutil.rmtree')
39+
def test_sync_files_pdf(self, rmtree, copy):
40+
sync_files(
41+
self.project.pk, self.version.pk, 'sphinx', pdf=True
42+
)
43+
44+
# epub is cleaned
45+
rmtree.assert_called_once()
46+
args, _ = rmtree.call_args
47+
self.assertIn('epub', args[0])
48+
49+
# Artifacts are copied to the rtd-builds directory
50+
copy.assert_called_once()
51+
args, _ = copy.call_args
52+
self.assertIn('artifacts', args[0])
53+
self.assertIn('sphinx_pdf', args[0])
54+
self.assertIn('media/pdf', args[1])
55+
56+
@patch('readthedocs.builds.syncers.Syncer.copy')
57+
@patch('readthedocs.projects.tasks.shutil.rmtree')
58+
def test_sync_files_epub(self, rmtree, copy):
59+
sync_files(
60+
self.project.pk, self.version.pk, 'sphinx', epub=True
61+
)
62+
63+
# pdf is cleaned
64+
rmtree.assert_called_once()
65+
args, _ = rmtree.call_args
66+
self.assertIn('pdf', args[0])
67+
68+
# Artifacts are copied to the rtd-builds directory
69+
copy.assert_called_once()
70+
args, _ = copy.call_args
71+
self.assertIn('artifacts', args[0])
72+
self.assertIn('sphinx_epub', args[0])
73+
self.assertIn('media/epub', args[1])
74+
75+
@patch('readthedocs.builds.syncers.Syncer.copy')
76+
@patch('readthedocs.projects.tasks.shutil.rmtree')
77+
def test_sync_files_localmedia(self, rmtree, copy):
78+
sync_files(
79+
self.project.pk, self.version.pk, 'sphinx', localmedia=True
80+
)
81+
pdf, epub = rmtree.call_args_list
82+
83+
# pdf and epub are cleaned
84+
args, _ = pdf
85+
self.assertIn('pdf', args[0])
86+
args, _ = epub
87+
self.assertIn('epub', args[0])
88+
89+
# Artifacts are copied to the rtd-builds directory
90+
copy.assert_called_once()
91+
args, _ = copy.call_args
92+
self.assertIn('artifacts', args[0])
93+
self.assertIn('sphinx_localmedia', args[0])
94+
self.assertIn('media/htmlzip', args[1])

0 commit comments

Comments
 (0)