comparison tests/e2e/libervia/test_libervia.py @ 3441:fdf56af87719

tests (e2e/libervia): more stable `test_user_can_log_in` + photos tests
author Goffi <goffi@goffi.org>
date Fri, 04 Dec 2020 12:39:44 +0100
parents d4558f3cbf13
children be6d91572633
comparison
equal deleted inserted replaced
3440:53da72a17139 3441:fdf56af87719
15 15
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import os 19 import os
20 import re
20 import pytest 21 import pytest
21 from helium import ( 22 from helium import (
22 go_to, write, click, drag_file, find_all, wait_until, S, Text, Link, get_driver 23 go_to, write, press, click, drag_file, find_all, wait_until, S, Text, Link, Button,
24 get_driver, ENTER
23 ) 25 )
24 26
25 27
26 if os.getenv("SAT_TEST_ENV_E2E_LIBERVIA") is None: 28 if os.getenv("SAT_TEST_ENV_E2E_LIBERVIA") is None:
27 pytest.skip( 29 pytest.skip(
58 assert "new_account@server1.test" in user_email.body 60 assert "new_account@server1.test" in user_email.body
59 # use can now log-in 61 # use can now log-in
60 62
61 def test_user_can_log_in(self, nobody_logged_in): 63 def test_user_can_log_in(self, nobody_logged_in):
62 go_to("https://libervia.test:8443/login") 64 go_to("https://libervia.test:8443/login")
63 write("account1_s2", into="login") 65 write("account1_s3", into="login")
64 write("test", into="password") 66 write("test", into="password")
65 click("log in") 67 click("log in")
66 assert Text("you are logged").exists() 68 wait_until(Text("you are logged").exists)
69 assert Button("Disconnect").exists()
67 70
68 def test_wrong_password_fails(self, nobody_logged_in): 71 def test_wrong_password_fails(self, nobody_logged_in):
69 go_to("https://libervia.test:8443/login") 72 go_to("https://libervia.test:8443/login")
70 write("account1_s2", into="login") 73 write("account1_s2", into="login")
71 write("wrong_password", into="password") 74 write("wrong_password", into="password")
72 click("log in") 75 click("log in")
73 assert Text("Your login and/or password is incorrect. Please try again.") 76 assert Text("Your login and/or password is incorrect. Please try again.")
74 77
75 78
76 class TestPhotos: 79 class TestPhotos:
80 ACCOUNT1_ALBUMS_URL = (
81 "https://libervia.test:8443/photos/album/account1@files.server1.test/albums"
82 )
83 TEST_ALBUM_URL = f"{ACCOUNT1_ALBUMS_URL}/test%20album"
77 84
85 @pytest.mark.dependency(name="create_album")
78 def test_user_can_create_album(self, log_in_account1): 86 def test_user_can_create_album(self, log_in_account1):
79 go_to("https://libervia.test:8443/photos") 87 go_to("https://libervia.test:8443/photos")
80 wait_until(Link("create").exists) 88 wait_until(Link("create").exists)
81 click("create") 89 click("create")
82 write("test album", into="album name") 90 write("test album", into="album name")
89 wait_until(lambda: len(find_all(S("div.progress_finished")))==1) 97 wait_until(lambda: len(find_all(S("div.progress_finished")))==1)
90 drag_file("/src/sat/tests/_files/test_2.jpg", "drop photos here") 98 drag_file("/src/sat/tests/_files/test_2.jpg", "drop photos here")
91 wait_until(lambda: len(find_all(S("div.progress_finished")))==2) 99 wait_until(lambda: len(find_all(S("div.progress_finished")))==2)
92 assert S('img[alt="test_1.jpg"]').exists() 100 assert S('img[alt="test_1.jpg"]').exists()
93 assert S('img[alt="test_2.jpg"]').exists() 101 assert S('img[alt="test_2.jpg"]').exists()
102
103 @pytest.mark.dependency(depends=["create_album"])
104 def test_user_can_slideshow(self, log_in_account1):
105 go_to(self.TEST_ALBUM_URL)
106 wait_until(lambda: not S("#loading_screen").exists())
107 thumb_1 = S("img[alt='test_1.jpg'].is-photo-thumbnail")
108 assert thumb_1.exists()
109 click(thumb_1)
110 assert S("div.slideshow").exists()
111 active_slide_1 = S("div.swiper-slide-active")
112 assert active_slide_1.exists()
113 # if we don't save the web_element here, the test in wait_until fails
114 # it seems that Helium is re-using the selector, i.e. we get the other
115 # slide in active_slide_1.
116 active_slide_1_elt = active_slide_1.web_element
117 click(S(".swiper-button-next"))
118 wait_until(
119 lambda:
120 "swiper-slide-active" not in active_slide_1_elt.get_attribute("class")
121 )
122 active_slide_2 = S("div.swiper-slide-active")
123 assert active_slide_2.exists()
124 active_slide_2_elt = active_slide_2.web_element
125 assert active_slide_1_elt != active_slide_2_elt
126 click(S(".click_to_close"))
127 assert not S("div.slideshow").exists()
128
129 @pytest.mark.dependency(name="ext_user_no_access", depends=["create_album"])
130 def test_external_user_cant_access_album(self, log_in_account1_s2):
131 go_to(self.TEST_ALBUM_URL)
132 assert Text("Unauthorized").exists()
133 assert "Error" in get_driver().title
134
135 @pytest.mark.dependency(name="invite_ext_user", depends=["create_album", "ext_user_no_access"])
136 def test_invitation_of_external_user(self, log_in_account1):
137 """User can invite somebody not in its roster by its full JID"""
138 go_to(self.TEST_ALBUM_URL)
139 wait_until(lambda: not S("#loading_screen").exists())
140 click("manage invitations")
141 assert Text("people who can access this album").exists()
142 contact_input = S("input[name='contact']")
143 write("account1@server2.test", into=contact_input)
144 press(ENTER)
145 assert contact_input.web_element.get_attribute("value") == ""
146 assert Text("account1@server2.test").exists()
147
148 @pytest.mark.dependency(depends=["create_album", "invite_ext_user"])
149 def test_invited_user_can_access_album(self, log_in_account1_s2):
150 go_to(self.TEST_ALBUM_URL)
151 assert not Text("Unauthorized").exists()
152 assert not "Error" in get_driver().title
153 assert len(find_all(S("img.is-photo-thumbnail"))) == 2
154
155 @pytest.mark.dependency(name="invite_by_email", depends=["create_album"])
156 def test_invitation_by_email(self, log_in_account1, sent_emails, shared_data):
157 """User can invite somebody without XMPP account by email"""
158 go_to(self.TEST_ALBUM_URL)
159 wait_until(lambda: not S("#loading_screen").exists())
160 click("manage invitations")
161 assert Text("people who can access this album").exists()
162 click("invite by email")
163 wait_until(Text("Invite somebody by email").exists)
164 write("somebody@example.net", "email")
165 write("Some Guest", "name")
166 click("send invitation")
167 wait_until(lambda: len(sent_emails) == 1)
168 invitation_email = sent_emails[0]
169 assert "Welcome" in invitation_email.body
170 url_match = re.search(r"https:\/\/.+\/g\/\w+", sent_emails[0].body)
171 assert url_match is not None
172 shared_data["invitation_url"] = url_match.group()
173
174 @pytest.mark.dependency(depends=["invite_by_email"])
175 def test_email_guest_can_access_album(self, nobody_logged_in, shared_data):
176 go_to(shared_data["invitation_url"])
177 click("test album")
178 wait_until(lambda: not S("#loading_screen").exists())
179 assert len(find_all(S("img.is-photo-thumbnail"))) == 2