comparison tests/e2e/libervia-web/test_libervia-web.py @ 3498:d78b5eae912a

tests: update following names change
author Goffi <goffi@goffi.org>
date Fri, 16 Apr 2021 18:32:34 +0200
parents tests/e2e/libervia/test_libervia.py@7550ae9cfbac
children 6c87c00b344a
comparison
equal deleted inserted replaced
3497:73e04040d577 3498:d78b5eae912a
1 #!/usr/bin/env python3
2
3 # Libervia: an XMPP client
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
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/>.
18
19 import os
20 import re
21 import pytest
22 from helium import (
23 go_to, write, press, click, drag_file, find_all, wait_until, S, Text, Link, Button,
24 get_driver, ENTER
25 )
26
27
28 if os.getenv("LIBERVIA_TEST_ENV_E2E_WEB") is None:
29 pytest.skip(
30 "skipping end-to-end tests, we are not in a test environment for Libervia",
31 allow_module_level=True
32 )
33
34 pytestmark = pytest.mark.usefixtures("test_profiles", "screenshot_on_failure")
35
36
37 class TestLogin:
38
39 def test_user_can_create_account(self, nobody_logged_in, sent_emails):
40 go_to("https://libervia-web.test:8443/login")
41 click("no account yet")
42 write("new_account", into="login")
43 write("some_email@example.net", into="email")
44 write("testtest", into="password")
45 click("register new account")
46 wait_until(lambda: get_driver().current_url.endswith("/login"))
47 write("testtest", into="password")
48 click("log in")
49 wait_until(Text("you are logged").exists)
50 wait_until(lambda: len(sent_emails) == 2)
51 if sent_emails[0].to == "admin@server1.test":
52 admin_email, user_email = sent_emails
53 else:
54 user_email, admin_email = sent_emails
55 assert admin_email.to == "admin@server1.test"
56 # profile name must be specified in admin email
57 assert "new_account" in admin_email.body
58 assert user_email.to == "some_email@example.net"
59 # user jid must be specified in the email
60 assert "new_account@server1.test" in user_email.body
61 # use can now log-in
62
63 def test_user_can_log_in(self, nobody_logged_in):
64 go_to("https://libervia-web.test:8443/login")
65 write("account1_s3", into="login")
66 write("test", into="password")
67 click("log in")
68 wait_until(Text("you are logged").exists)
69 assert Button("Disconnect").exists()
70
71 def test_wrong_password_fails(self, nobody_logged_in):
72 go_to("https://libervia-web.test:8443/login")
73 write("account1_s2", into="login")
74 write("wrong_password", into="password")
75 click("log in")
76 assert Text("Your login and/or password is incorrect. Please try again.")
77
78
79 class TestPhotos:
80 ACCOUNT1_ALBUMS_URL = (
81 "https://libervia-web.test:8443/photos/album/account1@files.server1.test/albums"
82 )
83 TEST_ALBUM_URL = f"{ACCOUNT1_ALBUMS_URL}/test%20album"
84
85 @pytest.mark.dependency(name="create_album")
86 def test_user_can_create_album(self, log_in_account1):
87 go_to("https://libervia-web.test:8443/photos")
88 wait_until(Link("create").exists)
89 click("create")
90 write("test album", into="album name")
91 click("create")
92 album_link = Link("test album")
93 wait_until(album_link.exists)
94 click(album_link)
95 wait_until(lambda: S("#file_drop").exists())
96 wait_until(lambda: not S("#loading_screen").exists())
97 drag_file("/src/sat/tests/_files/test_1.jpg", "drop photos here")
98 wait_until(lambda: len(find_all(S("div.progress_finished")))==1)
99 drag_file("/src/sat/tests/_files/test_2.jpg", "drop photos here")
100 wait_until(lambda: len(find_all(S("div.progress_finished")))==2)
101 assert S('img[alt="test_1.jpg"]').exists()
102 assert S('img[alt="test_2.jpg"]').exists()
103
104 @pytest.mark.dependency(depends=["create_album"])
105 def test_user_can_slideshow(self, log_in_account1):
106 go_to(self.TEST_ALBUM_URL)
107 wait_until(lambda: not S("#loading_screen").exists())
108 thumb_1 = S("img[alt='test_1.jpg'].is-photo-thumbnail")
109 assert thumb_1.exists()
110 click(thumb_1)
111 assert S("div.slideshow").exists()
112 active_slide_1 = S("div.swiper-slide-active")
113 assert active_slide_1.exists()
114 # if we don't save the web_element here, the test in wait_until fails
115 # it seems that Helium is re-using the selector, i.e. we get the other
116 # slide in active_slide_1.
117 active_slide_1_elt = active_slide_1.web_element
118 click(S(".swiper-button-next"))
119 wait_until(
120 lambda:
121 "swiper-slide-active" not in active_slide_1_elt.get_attribute("class")
122 )
123 active_slide_2 = S("div.swiper-slide-active")
124 assert active_slide_2.exists()
125 active_slide_2_elt = active_slide_2.web_element
126 assert active_slide_1_elt != active_slide_2_elt
127 click(S(".click_to_close"))
128 assert not S("div.slideshow").exists()
129
130 @pytest.mark.dependency(name="ext_user_no_access", depends=["create_album"])
131 def test_external_user_cant_access_album(self, log_in_account1_s2):
132 go_to(self.TEST_ALBUM_URL)
133 assert Text("Unauthorized").exists()
134 assert "Error" in get_driver().title
135
136 @pytest.mark.dependency(name="invite_ext_user", depends=["create_album", "ext_user_no_access"])
137 def test_invitation_of_external_user(self, log_in_account1):
138 """User can invite somebody not in its roster by its full JID"""
139 go_to(self.TEST_ALBUM_URL)
140 wait_until(lambda: not S("#loading_screen").exists())
141 click("manage invitations")
142 assert Text("people who can access this page").exists()
143 contact_input = S("input[name='contact']")
144 write("account1@server2.test", into=contact_input)
145 press(ENTER)
146 assert contact_input.web_element.get_attribute("value") == ""
147 assert Text("account1@server2.test").exists()
148
149 @pytest.mark.dependency(depends=["create_album", "invite_ext_user"])
150 def test_invited_user_can_access_album(self, log_in_account1_s2):
151 go_to(self.TEST_ALBUM_URL)
152 assert not Text("Unauthorized").exists()
153 assert not "Error" in get_driver().title
154 assert len(find_all(S("img.is-photo-thumbnail"))) == 2
155
156 @pytest.mark.dependency(name="invite_by_email", depends=["create_album"])
157 def test_invitation_by_email(self, log_in_account1, sent_emails, shared_data):
158 """User can invite somebody without XMPP account by email"""
159 go_to(self.TEST_ALBUM_URL)
160 wait_until(lambda: not S("#loading_screen").exists())
161 click("manage invitations")
162 assert Text("people who can access this page").exists()
163 click("invite by email")
164 wait_until(Text("Invite somebody by email").exists)
165 write("somebody@example.net", "email")
166 write("Some Guest", "name")
167 click("send invitation")
168 wait_until(lambda: len(sent_emails) == 1)
169 invitation_email = sent_emails[0]
170 assert "Welcome" in invitation_email.body
171 url_match = re.search(r"https:\/\/.+\/g\/\w+", sent_emails[0].body)
172 assert url_match is not None
173 shared_data["invitation_url"] = url_match.group()
174
175 @pytest.mark.dependency(depends=["invite_by_email"])
176 def test_email_guest_can_access_album(self, nobody_logged_in, shared_data):
177 go_to(shared_data["invitation_url"])
178 click("test album")
179 wait_until(lambda: not S("#loading_screen").exists())
180 assert len(find_all(S("img.is-photo-thumbnail"))) == 2