|
17 | 17 | from rest_framework import status
|
18 | 18 | from rest_framework.test import APIClient
|
19 | 19 |
|
20 |
| -from readthedocs.builds.models import Build, Version |
| 20 | +from readthedocs.builds.models import Build, BuildCommandResult, Version |
21 | 21 | from readthedocs.integrations.models import Integration
|
22 | 22 | from readthedocs.oauth.models import RemoteOrganization, RemoteRepository
|
23 | 23 | from readthedocs.projects.models import Feature, Project
|
@@ -277,6 +277,140 @@ def test_make_build_commands(self):
|
277 | 277 | self.assertEqual(build['commands'][0]['run_time'], 5)
|
278 | 278 | self.assertEqual(build['commands'][0]['description'], 'foo')
|
279 | 279 |
|
| 280 | + def test_get_raw_log_success(self): |
| 281 | + build = get(Build, project_id=1, version_id=1, builder='foo') |
| 282 | + get( |
| 283 | + BuildCommandResult, |
| 284 | + build=build, |
| 285 | + command='python setup.py install', |
| 286 | + output='Installing dependencies...' |
| 287 | + ) |
| 288 | + get( |
| 289 | + BuildCommandResult, |
| 290 | + build=build, |
| 291 | + command='git checkout master', |
| 292 | + output='Switched to branch "master"' |
| 293 | + ) |
| 294 | + client = APIClient() |
| 295 | + |
| 296 | + api_user = get(User, user='test', password='test') |
| 297 | + client.force_authenticate(user=api_user) |
| 298 | + resp = client.get('/api/v2/build/{0}.txt'.format(build.pk)) |
| 299 | + self.assertEqual(resp.status_code, 200) |
| 300 | + |
| 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()) |
| 396 | + self.assertIn('[rtd-command-info]', resp.content.decode()) |
| 397 | + self.assertIn( |
| 398 | + 'python setup.py install\nInstalling dependencies...', |
| 399 | + resp.content.decode() |
| 400 | + ) |
| 401 | + self.assertIn( |
| 402 | + 'git checkout master\nSwitched to branch "master"', |
| 403 | + resp.content.decode() |
| 404 | + ) |
| 405 | + |
| 406 | + def test_get_invalid_raw_log(self): |
| 407 | + client = APIClient() |
| 408 | + |
| 409 | + api_user = get(User, user='test', password='test') |
| 410 | + client.force_authenticate(user=api_user) |
| 411 | + resp = client.get('/api/v2/build/{0}.txt'.format(404)) |
| 412 | + self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND) |
| 413 | + |
280 | 414 |
|
281 | 415 | class APITests(TestCase):
|
282 | 416 | fixtures = ['eric.json', 'test_data.json']
|
|
0 commit comments