Skip to content

Commit 1415270

Browse files
committed
More tests
1 parent bd03a78 commit 1415270

File tree

1 file changed

+96
-7
lines changed

1 file changed

+96
-7
lines changed

readthedocs/rtd_tests/tests/test_api.py

+96-7
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def test_make_build_commands(self):
277277
self.assertEqual(build['commands'][0]['run_time'], 5)
278278
self.assertEqual(build['commands'][0]['description'], 'foo')
279279

280-
def test_get_raw_log(self):
280+
def test_get_raw_log_success(self):
281281
build = get(Build, project_id=1, version_id=1, builder='foo')
282282
get(
283283
BuildCommandResult,
@@ -298,12 +298,101 @@ def test_get_raw_log(self):
298298
resp = client.get('/api/v2/build/{0}.txt'.format(build.pk))
299299
self.assertEqual(resp.status_code, 200)
300300

301-
self.assertIn('RTD build information', resp.content.decode())
302-
self.assertIn('Build: {}'.format(build.id), resp.content.decode())
303-
self.assertIn('Project: {}'.format(build.project.id), resp.content.decode())
304-
self.assertIn('Version: {}'.format(build.commit), resp.content.decode())
305-
self.assertIn('State: {}'.format(build.state), resp.content.decode())
306-
self.assertIn('Success: {}'.format(build.success), resp.content.decode())
301+
self.assertIn('Read the Docs build information', resp.content.decode())
302+
self.assertIn('Build id: {}'.format(build.id), resp.content.decode())
303+
self.assertIn('Project: {}'.format(build.project.slug), resp.content.decode())
304+
self.assertIn('Version: {}'.format(build.version.slug), resp.content.decode())
305+
self.assertIn('Commit: {}'.format(build.commit), resp.content.decode())
306+
self.assertIn('Date: ', resp.content.decode())
307+
self.assertIn('State: finished', resp.content.decode())
308+
self.assertIn('Success: True', resp.content.decode())
309+
self.assertIn('[rtd-command-info]', resp.content.decode())
310+
self.assertIn(
311+
'python setup.py install\nInstalling dependencies...',
312+
resp.content.decode()
313+
)
314+
self.assertIn(
315+
'git checkout master\nSwitched to branch "master"',
316+
resp.content.decode()
317+
)
318+
319+
def test_get_raw_log_building(self):
320+
build = get(
321+
Build, project_id=1, version_id=1,
322+
builder='foo', success=False,
323+
exit_code=1, state='building',
324+
)
325+
get(
326+
BuildCommandResult,
327+
build=build,
328+
command='python setup.py install',
329+
output='Installing dependencies...',
330+
exit_code=1,
331+
)
332+
get(
333+
BuildCommandResult,
334+
build=build,
335+
command='git checkout master',
336+
output='Switched to branch "master"'
337+
)
338+
client = APIClient()
339+
340+
api_user = get(User, user='test', password='test')
341+
client.force_authenticate(user=api_user)
342+
resp = client.get('/api/v2/build/{0}.txt'.format(build.pk))
343+
self.assertEqual(resp.status_code, 200)
344+
345+
self.assertIn('Read the Docs build information', resp.content.decode())
346+
self.assertIn('Build id: {}'.format(build.id), resp.content.decode())
347+
self.assertIn('Project: {}'.format(build.project.slug), resp.content.decode())
348+
self.assertIn('Version: {}'.format(build.version.slug), resp.content.decode())
349+
self.assertIn('Commit: {}'.format(build.commit), resp.content.decode())
350+
self.assertIn('Date: ', resp.content.decode())
351+
self.assertIn('State: building', resp.content.decode())
352+
self.assertIn('Success: Unknow', resp.content.decode())
353+
self.assertIn('[rtd-command-info]', resp.content.decode())
354+
self.assertIn(
355+
'python setup.py install\nInstalling dependencies...',
356+
resp.content.decode()
357+
)
358+
self.assertIn(
359+
'git checkout master\nSwitched to branch "master"',
360+
resp.content.decode()
361+
)
362+
363+
def test_get_raw_log_failure(self):
364+
build = get(
365+
Build, project_id=1, version_id=1,
366+
builder='foo', success=False, exit_code=1
367+
)
368+
get(
369+
BuildCommandResult,
370+
build=build,
371+
command='python setup.py install',
372+
output='Installing dependencies...',
373+
exit_code=1,
374+
)
375+
get(
376+
BuildCommandResult,
377+
build=build,
378+
command='git checkout master',
379+
output='Switched to branch "master"'
380+
)
381+
client = APIClient()
382+
383+
api_user = get(User, user='test', password='test')
384+
client.force_authenticate(user=api_user)
385+
resp = client.get('/api/v2/build/{0}.txt'.format(build.pk))
386+
self.assertEqual(resp.status_code, 200)
387+
388+
self.assertIn('Read the Docs build information', resp.content.decode())
389+
self.assertIn('Build id: {}'.format(build.id), resp.content.decode())
390+
self.assertIn('Project: {}'.format(build.project.slug), resp.content.decode())
391+
self.assertIn('Version: {}'.format(build.version.slug), resp.content.decode())
392+
self.assertIn('Commit: {}'.format(build.commit), resp.content.decode())
393+
self.assertIn('Date: ', resp.content.decode())
394+
self.assertIn('State: finished', resp.content.decode())
395+
self.assertIn('Success: False', resp.content.decode())
307396
self.assertIn('[rtd-command-info]', resp.content.decode())
308397
self.assertIn(
309398
'python setup.py install\nInstalling dependencies...',

0 commit comments

Comments
 (0)