1
1
import json
2
2
from unittest import mock
3
3
4
+ from django .conf import settings
5
+ from django .contrib .auth .models import User
4
6
from django .test import TestCase
5
7
from django .urls import reverse
8
+ from django_dynamic_fixture import get
6
9
7
10
from readthedocs .builds .constants import BRANCH , LATEST , STABLE , TAG
8
11
from readthedocs .builds .models import (
9
12
RegexAutomationRule ,
10
13
Version ,
11
14
VersionAutomationRule ,
12
15
)
16
+ from readthedocs .organizations .models import Organization , OrganizationOwner
17
+ from readthedocs .projects .constants import PUBLIC
13
18
from readthedocs .projects .models import Project
14
19
15
20
@@ -18,8 +23,22 @@ class TestSyncVersions(TestCase):
18
23
fixtures = ['eric' , 'test_data' ]
19
24
20
25
def setUp (self ):
21
- self .client .login (username = 'eric' , password = 'test' )
26
+ self .user = User .objects .get (username = 'eric' )
27
+ self .client .force_login (self .user )
22
28
self .pip = Project .objects .get (slug = 'pip' )
29
+
30
+ # Run tests for .com
31
+ if settings .ALLOW_PRIVATE_REPOS :
32
+ self .org = get (
33
+ Organization ,
34
+ name = 'testorg' ,
35
+ )
36
+ OrganizationOwner .objects .create (
37
+ owner = self .user ,
38
+ organization = self .org ,
39
+ )
40
+ self .org .projects .add (self .pip )
41
+
23
42
Version .objects .create (
24
43
project = self .pip ,
25
44
identifier = 'origin/master' ,
@@ -908,9 +927,23 @@ class TestStableVersion(TestCase):
908
927
fixtures = ['eric' , 'test_data' ]
909
928
910
929
def setUp (self ):
911
- self .client .login (username = 'eric' , password = 'test' )
930
+ self .user = User .objects .get (username = 'eric' )
931
+ self .client .force_login (self .user )
912
932
self .pip = Project .objects .get (slug = 'pip' )
913
933
934
+ # Run tests for .com
935
+ if settings .ALLOW_PRIVATE_REPOS :
936
+ self .org = get (
937
+ Organization ,
938
+ name = 'testorg' ,
939
+ )
940
+ OrganizationOwner .objects .create (
941
+ owner = self .user ,
942
+ organization = self .org ,
943
+ )
944
+ self .org .projects .add (self .pip )
945
+
946
+
914
947
def test_stable_versions (self ):
915
948
version_post_data = {
916
949
'branches' : [
@@ -1403,8 +1436,22 @@ class TestLatestVersion(TestCase):
1403
1436
fixtures = ['eric' , 'test_data' ]
1404
1437
1405
1438
def setUp (self ):
1406
- self .client .login (username = 'eric' , password = 'test' )
1439
+ self .user = User .objects .get (username = 'eric' )
1440
+ self .client .force_login (self .user )
1407
1441
self .pip = Project .objects .get (slug = 'pip' )
1442
+
1443
+ # Run tests for .com
1444
+ if settings .ALLOW_PRIVATE_REPOS :
1445
+ self .org = get (
1446
+ Organization ,
1447
+ name = 'testorg' ,
1448
+ )
1449
+ OrganizationOwner .objects .create (
1450
+ owner = self .user ,
1451
+ organization = self .org ,
1452
+ )
1453
+ self .org .projects .add (self .pip )
1454
+
1408
1455
Version .objects .create (
1409
1456
project = self .pip ,
1410
1457
identifier = 'origin/master' ,
0 commit comments