|
4 | 4 | from django.test import TestCase
|
5 | 5 | from django.contrib.auth.models import User
|
6 | 6 | from django.contrib.messages import constants as message_const
|
| 7 | +from django.views.generic.base import ContextMixin |
7 | 8 | from django_dynamic_fixture import get
|
8 | 9 | from django_dynamic_fixture import new
|
9 | 10 |
|
10 | 11 | from readthedocs.core.models import UserProfile
|
11 | 12 | from readthedocs.rtd_tests.base import (WizardTestCase, MockBuildTestCase,
|
12 | 13 | RequestFactoryTestMixin)
|
13 | 14 | from readthedocs.projects.exceptions import ProjectSpamError
|
14 |
| -from readthedocs.projects.models import Project |
| 15 | +from readthedocs.projects.models import Project, Domain |
15 | 16 | from readthedocs.projects.views.private import ImportWizardView
|
| 17 | +from readthedocs.projects.views.mixins import ProjectRelationMixin |
16 | 18 |
|
17 | 19 |
|
18 | 20 | @patch('readthedocs.projects.views.private.trigger_build', lambda x, basic: None)
|
@@ -330,3 +332,26 @@ def test_delete_project(self):
|
330 | 332 | remove_dir.apply_async.assert_called_with(
|
331 | 333 | queue='celery',
|
332 | 334 | args=[project.doc_path])
|
| 335 | + |
| 336 | + |
| 337 | +class TestPrivateMixins(MockBuildTestCase): |
| 338 | + |
| 339 | + def setUp(self): |
| 340 | + self.project = get(Project, slug='kong') |
| 341 | + self.domain = get(Domain, project=self.project) |
| 342 | + |
| 343 | + def test_project_relation(self): |
| 344 | + """Class using project relation mixin class""" |
| 345 | + |
| 346 | + class FoobarView(ProjectRelationMixin, ContextMixin): |
| 347 | + model = Domain |
| 348 | + |
| 349 | + def get_project_queryset(self): |
| 350 | + # Don't test this as a view with a request.user |
| 351 | + return Project.objects.all() |
| 352 | + |
| 353 | + view = FoobarView() |
| 354 | + view.kwargs = {'project_slug': 'kong'} |
| 355 | + self.assertEqual(view.get_project(), self.project) |
| 356 | + self.assertEqual(view.get_queryset().first(), self.domain) |
| 357 | + self.assertEqual(view.get_context_data()['project'], self.project) |
0 commit comments