16
16
from readthedocs .oauth .models import RemoteRepository , RemoteRepositoryRelation
17
17
from readthedocs .organizations .models import Organization
18
18
from readthedocs .projects .constants import PUBLIC
19
- from readthedocs .projects .exceptions import ProjectSpamError
20
19
from readthedocs .projects .models import Domain , Project , WebHook , WebHookEvent
21
20
from readthedocs .projects .views .mixins import ProjectRelationMixin
22
21
from readthedocs .projects .views .private import ImportWizardView
25
24
26
25
27
26
@mock .patch ('readthedocs.projects.tasks.update_docs_task' , mock .MagicMock ())
28
- class TestProfileMiddleware (RequestFactoryTestMixin , TestCase ):
27
+ class TestImportProjectBannedUser (RequestFactoryTestMixin , TestCase ):
29
28
30
29
wizard_class_slug = 'import_wizard_view'
31
30
url = '/dashboard/import/manual/'
@@ -50,26 +49,15 @@ def setUp(self):
50
49
for (k , v ) in list (data [key ].items ())})
51
50
self .data ['{}-current_step' .format (self .wizard_class_slug )] = 'extra'
52
51
53
- def test_profile_middleware_no_profile (self ):
52
+ def test_not_banned_user (self ):
54
53
"""User without profile and isn't banned."""
55
54
req = self .request (method = 'post' , path = '/projects/import' , data = self .data )
56
55
req .user = get (User , profile = None )
57
56
resp = ImportWizardView .as_view ()(req )
58
57
self .assertEqual (resp .status_code , 302 )
59
58
self .assertEqual (resp ['location' ], '/projects/foobar/' )
60
59
61
- @mock .patch ('readthedocs.projects.views.private.ProjectBasicsForm.clean' )
62
- def test_profile_middleware_spam (self , form ):
63
- """User will be banned."""
64
- form .side_effect = ProjectSpamError
65
- req = self .request (method = 'post' , path = '/projects/import' , data = self .data )
66
- req .user = get (User )
67
- resp = ImportWizardView .as_view ()(req )
68
- self .assertEqual (resp .status_code , 302 )
69
- self .assertEqual (resp ['location' ], '/' )
70
- self .assertTrue (req .user .profile .banned )
71
-
72
- def test_profile_middleware_banned (self ):
60
+ def test_banned_user (self ):
73
61
"""User is banned."""
74
62
req = self .request (method = 'post' , path = '/projects/import' , data = self .data )
75
63
req .user = get (User )
@@ -296,54 +284,6 @@ def test_remote_repository_is_added(self):
296
284
self .assertIsNotNone (proj )
297
285
self .assertEqual (proj .remote_repository , remote_repo )
298
286
299
- @mock .patch (
300
- 'readthedocs.projects.views.private.ProjectExtraForm.clean_description' ,
301
- create = True ,
302
- )
303
- def test_form_spam (self , mocked_validator ):
304
- """Don't add project on a spammy description."""
305
- self .user .date_joined = timezone .now () - timedelta (days = 365 )
306
- self .user .save ()
307
- mocked_validator .side_effect = ProjectSpamError
308
-
309
- with self .assertRaises (Project .DoesNotExist ):
310
- proj = Project .objects .get (name = 'foobar' )
311
-
312
- resp = self .post_step ('basics' )
313
- self .assertWizardResponse (resp , 'extra' )
314
- resp = self .post_step ('extra' , session = list (resp ._request .session .items ()))
315
- self .assertIsInstance (resp , HttpResponseRedirect )
316
- self .assertEqual (resp .status_code , 302 )
317
- self .assertEqual (resp ['location' ], '/' )
318
-
319
- with self .assertRaises (Project .DoesNotExist ):
320
- proj = Project .objects .get (name = 'foobar' )
321
- self .assertFalse (self .user .profile .banned )
322
-
323
- @mock .patch (
324
- 'readthedocs.projects.views.private.ProjectExtraForm.clean_description' ,
325
- create = True ,
326
- )
327
- def test_form_spam_ban_user (self , mocked_validator ):
328
- """Don't add spam and ban new user."""
329
- self .user .date_joined = timezone .now ()
330
- self .user .save ()
331
- mocked_validator .side_effect = ProjectSpamError
332
-
333
- with self .assertRaises (Project .DoesNotExist ):
334
- proj = Project .objects .get (name = 'foobar' )
335
-
336
- resp = self .post_step ('basics' )
337
- self .assertWizardResponse (resp , 'extra' )
338
- resp = self .post_step ('extra' , session = list (resp ._request .session .items ()))
339
- self .assertIsInstance (resp , HttpResponseRedirect )
340
- self .assertEqual (resp .status_code , 302 )
341
- self .assertEqual (resp ['location' ], '/' )
342
-
343
- with self .assertRaises (Project .DoesNotExist ):
344
- proj = Project .objects .get (name = 'foobar' )
345
- self .assertTrue (self .user .profile .banned )
346
-
347
287
348
288
@mock .patch ('readthedocs.core.utils.trigger_build' , mock .MagicMock ())
349
289
class TestPublicViews (TestCase ):
0 commit comments