1
+ # -*- coding: utf-8 -*-
2
+
1
3
from __future__ import (
2
4
absolute_import , division , print_function , unicode_literals )
3
5
4
6
import mock
5
7
from django .contrib .auth .models import User
6
8
from django .test import TestCase
9
+ from django .test .utils import override_settings
7
10
from django_dynamic_fixture import get
8
11
from textclassifier .validators import ClassifierValidator
9
12
10
13
from readthedocs .projects .exceptions import ProjectSpamError
11
- from readthedocs .projects .forms import ProjectExtraForm , TranslationForm
14
+ from readthedocs .projects .forms import (
15
+ ProjectBasicsForm , ProjectExtraForm , TranslationForm )
12
16
from readthedocs .projects .models import Project
13
17
14
18
15
19
class TestProjectForms (TestCase ):
16
-
17
20
@mock .patch .object (ClassifierValidator , '__call__' )
18
21
def test_form_spam (self , mocked_validator ):
19
- """Form description field fails spam validation"""
22
+ """Form description field fails spam validation. """
20
23
mocked_validator .side_effect = ProjectSpamError
21
24
22
25
data = {
@@ -28,6 +31,67 @@ def test_form_spam(self, mocked_validator):
28
31
with self .assertRaises (ProjectSpamError ):
29
32
form .is_valid ()
30
33
34
+ def test_import_repo_url (self ):
35
+ """Validate different type of repository URLs on importing a Project."""
36
+
37
+ common_urls = [
38
+ # Invalid
39
+ ('./path/to/relative/folder' , False ),
40
+ ('../../path/to/relative/folder' , False ),
41
+ ('../../path/to/@/folder' , False ),
42
+ ('/path/to/local/folder' , False ),
43
+ ('/path/to/@/folder' , False ),
44
+ ('file:///path/to/local/folder' , False ),
45
+ ('file:///path/to/@/folder' , False ),
46
+ ('github.com/humitos/foo' , False ),
47
+ ('https://github.com/|/foo' , False ),
48
+ ('git://github.com/&&/foo' , False ),
49
+ # Valid
50
+ ('git://github.com/humitos/foo' , True ),
51
+ ('http://github.com/humitos/foo' , True ),
52
+ ('https://github.com/humitos/foo' , True ),
53
+ ('http://gitlab.com/humitos/foo' , True ),
54
+ ('http://bitbucket.com/humitos/foo' , True ),
55
+ ('ftp://ftpserver.com/humitos/foo' , True ),
56
+ ('ftps://ftpserver.com/humitos/foo' , True ),
57
+ ('lp:zaraza' , True ),
58
+ ]
59
+
60
+ public_urls = [
61
+ (
'[email protected] :humitos/foo' ,
False ),
62
+ (
'ssh://[email protected] /humitos/foo' ,
False ),
63
+ ('ssh+git://github.com/humitos/foo' , False ),
64
+ (
'[email protected] :strangeuser/readthedocs.git' ,
False ),
65
+ (
'[email protected] :22/_ssh/docs' ,
False ),
66
+ ] + common_urls
67
+
68
+ private_urls = [
69
+ (
'[email protected] :humitos/foo' ,
True ),
70
+ (
'ssh://[email protected] /humitos/foo' ,
True ),
71
+ ('ssh+git://github.com/humitos/foo' , True ),
72
+ (
'[email protected] :strangeuser/readthedocs.git' ,
True ),
73
+ (
'[email protected] :22/_ssh/docs' ,
True ),
74
+ ] + common_urls
75
+
76
+ for url , valid in public_urls :
77
+ initial = {
78
+ 'name' : 'foo' ,
79
+ 'repo_type' : 'git' ,
80
+ 'repo' : url ,
81
+ }
82
+ form = ProjectBasicsForm (initial )
83
+ self .assertEqual (form .is_valid (), valid , msg = url )
84
+
85
+ with override_settings (ALLOW_PRIVATE_REPOS = True ):
86
+ for url , valid in private_urls :
87
+ initial = {
88
+ 'name' : 'foo' ,
89
+ 'repo_type' : 'git' ,
90
+ 'repo' : url ,
91
+ }
92
+ form = ProjectBasicsForm (initial )
93
+ self .assertEqual (form .is_valid (), valid , msg = url )
94
+
31
95
32
96
class TestTranslationForm (TestCase ):
33
97
0 commit comments