forked from cos-archives/osf-ui-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
component_access_tests.py
188 lines (135 loc) · 5.3 KB
/
component_access_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import unittest
from selenium.webdriver import ActionChains
from base import ProjectSmokeTest
class ComponentAccessCase(ProjectSmokeTest):
@unittest.skip('Fails due to Selenium troubles')
def test_reorder_components(self):
self.add_component('hypothesis', 'first')
self.add_component('hypothesis', 'second')
self.driver.get(self.project_url)
# Second method: by element
ac = ActionChains(self.driver)
a = self.driver.find_element_by_css_selector('#Nodes li:first-child')
b = self.driver.find_element_by_css_selector('#Nodes li:last-child')
ac.drag_and_drop(a, b).perform()
self.driver.get(self.project_url)
self.assertEqual(
self.get_element('#Nodes li:first-child').text,
'second',
)
def test_public_component_of_private_project(self):
""" Test that a public component or a private project is accessible"""
title = 'Public Hypothesis'
component_url = self.add_component('hypothesis', title)
self.make_public(component_url)
self.log_out()
# navigate to the component as a non-logged-in user.
self.driver.get(component_url)
self.assertEqual(
self.get_element('.node-title').text,
title
)
# log back in so the teardown works.
self.log_in()
def test_private_component_of_public_project(self):
"""Test that a private component of a public project is not accessible
"""
# make the project public
self.make_public()
# create a component
title = "Private Hypothesis"
component_url = self.add_component('hypothesis', title)
# verify that the component is private
if self.is_public(component_url):
self.make_private(component_url)
# test that the component is not accessible to an anonymous user
self.log_out()
self.assert_not_authorized(component_url)
# test that the component is not accessible to a non-contributor
self.second_user = self.create_user()
self.log_in(self.second_user)
self.assert_forbidden(component_url)
# log back in so teardown doesn't fail.
self.log_out()
self.log_in()
def test_private_component_of_public_project_not_forked(self):
"""Test that a private components of public projects are not forked
when the project is forked
"""
# make the project public
self.make_public()
# create a private component
private_component_title = "Private-Component"
private_component_url = self.add_component(
'hypothesis',
private_component_title,
)
# verify that the component is private
if self.is_public(private_component_url):
self.make_private(private_component_url)
# create a public component
public_component_title = "Public-Component"
public_component_url = self.add_component(
'hypothesis',
public_component_title
)
# verify that the component is public
if not self.is_public(public_component_url):
self.make_public(public_component_url)
# Log out and make a new user
self.log_out()
self.second_user = self.create_user()
self.log_in(self.second_user)
# go to the project
self.goto('dashboard')
fork_url = self.create_fork()
self.driver.get(fork_url)
# Public component should be there
self.assertIn(
public_component_title,
self.get_element('#Nodes').text
)
# Private component should not be there
self.assertNotIn(
private_component_title,
self.get_element('#Nodes').text
)
# delete the forked project.
self.goto('settings', node_url=fork_url)
self.get_element('button[type="submit"]').click()
# log back in as the first user so teardown will work.
self.log_out()
self.log_in()
def test_files_of_private_component_of_public_project(self):
"""Test that a private component of a public project is not accessible
"""
# make the project public
self.make_public()
# create a component
title = "Private Hypothesis"
component_url = self.add_component('hypothesis', title)
# verify that the component is private
if self.is_public(component_url):
self.make_private(component_url)
# upload a file to the component
self.add_file(self.image_files['jpg']['path'])
# test that the component is not accessible to an anonymous user
self.log_out()
self.goto(
'file',
self.image_files['jpg']['filename'],
node_url=component_url,
)
self.assert_not_authorized()
# test that the component is not accessible to a non-contributor
self.second_user = self.create_user()
self.log_in(self.second_user)
self.goto(
'file',
self.image_files['jpg']['filename'],
node_url=component_url,
)
self.assert_forbidden()
# log back in so teardown doesn't fail.
self.log_out()
self.log_in()