chore: simplify new permission class

This commit is contained in:
Anastasiya Semenkevich 2024-11-06 21:49:46 +03:00 committed by Anastasiya
parent ebbc55514e
commit 38b3e03fe5
12 changed files with 38 additions and 121 deletions

View File

@ -6,6 +6,7 @@ from gui.elements.button import Button
from gui.elements.check_box import CheckBox
from gui.elements.text_edit import TextEdit
from gui.objects_map import names
from gui.screens.community_settings import PermissionsSettingsView
class ChannelPopup(BasePopup):

View File

@ -42,10 +42,10 @@ class InviteContactsPopup(BasePopup):
selected = []
for member in driver.findAllObjects(self.member_checkbox.real_name):
if str(getattr(member, 'objectName', '')).split('-')[1] in contacts:
if str(getattr(member, 'objectName', '')).split('contactCheckbox-')[1] in contacts:
CheckBox(member).set(True)
assert member.checkState != 0, f"Member item checkbox is not checked"
selected.append(str(getattr(member, 'objectName', '')).split('-')[1])
selected.append(str(getattr(member, 'objectName', '')).split('contactCheckbox-')[1])
assert set(contacts) == set(selected), f'Selected contacts: {selected}, expected: {contacts}'

View File

@ -8,9 +8,10 @@ from gui.elements.check_box import CheckBox
from gui.elements.object import QObject
from gui.elements.text_edit import TextEdit
from gui.objects_map import communities_names
from gui.screens.community_settings import PermissionsSettingsView
class NewPermissionPopup(QObject):
class NewPermissionPopup(PermissionsSettingsView):
def __init__(self):
super(NewPermissionPopup, self).__init__()
self._who_holds_checkbox = CheckBox(communities_names.whoHoldsSwitch_StatusSwitch)
@ -25,89 +26,7 @@ class NewPermissionPopup(QObject):
self._who_holds_list_item = QObject(communities_names.who_holds_StatusItemSelector)
self._is_allowed_to_list_item = QObject(communities_names.is_allowed_to_StatusFlowSelector)
@allure.step('Wait until appears {0}')
def wait_until_appears(self, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_MSEC):
driver.waitForObjectExists(self._create_permission_button.real_name, timeout_msec)
return self
@allure.step('Set state of who holds checkbox')
def set_who_holds_checkbox_state(self, state):
if state is False:
self._who_holds_checkbox.set(state)
@allure.step('Open Who holds context menu')
def open_who_holds_context_menu(self, attempt: int = 2):
try:
for child in walk_children(self._who_holds_list_item.object):
if getattr(child, 'objectName', '') == 'addItemButton':
driver.mouseClick(child)
return self._who_holds_asset_field.wait_until_appears()
except AssertionError:
if attempt:
return self.open_who_holds_context_menu(attempt - 1)
else:
raise LookupError('Add button for who holds not found')
@allure.step('Open Is allowed to context menu')
def open_is_allowed_to_context_menu(self, attempt: int = 2):
try:
for child in walk_children(self._is_allowed_to_list_item.object):
if getattr(child, 'objectName', '') == 'addItemButton':
driver.mouseClick(child)
return
except LookupError:
if attempt:
return self.open_is_allowed_to_context_menu(attempt - 1)
else:
raise LookupError('Add button for allowed to not found')
@allure.step('Set asset and amount')
def set_who_holds_asset_and_amount(self, asset: str, amount: str):
if asset is not False:
self.open_who_holds_context_menu()
self._who_holds_asset_field.clear().text = asset
self._asset_item.click()
self._who_holds_asset_field.wait_until_hidden()
self._who_holds_amount_field.text = amount
self.click_add_button_who_holds()
return self
@allure.step('Choose option from Is allowed to context menu')
def set_is_allowed_to(self, name):
self.open_is_allowed_to_context_menu()
self._is_allowed_to_option_button.real_name['objectName'] = name
self._is_allowed_to_option_button.wait_until_appears().click()
self.click_add_button_is_allowed()
return self
@allure.step('Click add button for who holds')
def click_add_button_who_holds(self, attempt: int = 2):
self._add_button_who_holds.click()
try:
self._add_button_who_holds.wait_until_hidden()
except AssertionError as err:
if attempt:
self.click_add_button_who_holds(attempt - 1)
else:
raise err
@allure.step('Click add button is allowed')
def click_add_button_is_allowed(self, attempt: int = 2):
self._add_button_is_allowed_to.click()
try:
self._add_button_is_allowed_to.wait_until_hidden()
except AssertionError as err:
if attempt:
self.click_add_button_is_allowed(attempt - 1)
else:
raise err
@allure.step('Click create permission')
def create_permission(self):
self._create_permission_button.click()
self._create_permission_button.wait_until_hidden()
@allure.step('Switch hide permission checkbox')
def switch_hide_permission_checkbox(self, state):
self._hide_permission_checkbox.set(state)
return self

View File

@ -350,16 +350,6 @@ class LeftPanel(QObject):
self._more_button.click()
return ContextMenu()
@allure.step('Get visibility state of delete item')
def is_delete_item_visible(self) -> bool:
return self._delete_category_item.is_visible
@allure.step('Get visibility state of edit item')
def is_edit_item_visible(self) -> bool:
return self.edit_category_item.is_visible
@allure.step('Open new channel popup inside category')
def open_new_channel_popup_in_category(self) -> NewChannelPopup:
self._arrow_button.click()
@ -376,16 +366,10 @@ class LeftPanel(QObject):
def right_click_on_panel(self):
super(LeftPanel, self).right_click()
@allure.step('Invite people to community')
def invite_people_to_community(self, contacts: typing.List[str], message: str, attempts: int = 2):
@allure.step('Open add members popup')
def open_add_members_popup(self):
self._add_members_button.click()
try:
InviteContactsPopup().wait_until_appears().invite(contacts, message)
except AssertionError as err:
if attempts:
self.invite_people_to_community(contacts, message, attempts - 1)
else:
raise err
return InviteContactsPopup().wait_until_appears()
class Chat(QObject):

View File

@ -76,3 +76,7 @@ def get_wallet_address_from_mnemonic(mnemonic_data) -> str:
child_w = w.get_child_for_path("m/44'/60'/0'/0/0")
address_from_mnemonic = child_w.address()
return address_from_mnemonic
def random_text_message():
return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(1, 141))

View File

@ -36,7 +36,7 @@ def test_member_role_cannot_add_edit_or_delete_category(main_screen: MainWindow)
with step('Verify that context menu does not appear'):
assert not ContextMenu().is_visible
with step('Verify that delete item is not present in more options context menu'):
assert not community_screen.left_panel.open_more_options().is_edit_item_visible()
assert not community_screen.left_panel.open_more_options().edit_category_item.is_visible
with step('Verify that member cannot delete category'):
with step('Right-click on category in the left navigation bar'):
@ -44,7 +44,7 @@ def test_member_role_cannot_add_edit_or_delete_category(main_screen: MainWindow)
with step('Verify that context menu does not appear'):
assert not ContextMenu().is_visible
with step('Verify that delete item is not present in more options context menu'):
assert not community_screen.left_panel.open_more_options().is_delete_item_visible()
assert not community_screen.left_panel.open_more_options().delete_category_item.is_visible
@allure.testcase('https://ethstatus.testrail.net/index.php?/cases/view/704622', 'Community category clicking')

View File

@ -1,5 +1,6 @@
import random
import string
import time
import allure
import pytest
@ -149,13 +150,16 @@ def test_member_cannot_see_hidden_channel(multiple_instances, user_data_one, use
community_screen = main_screen.left_panel.select_community('Community with 2 users')
with step(f'User {user_two.name}, create hidden channel, verify that it is in the list'):
permission_popup = community_screen.left_panel.open_create_channel_popup().create(channel_name,
create_channel_popup = community_screen.left_panel.open_create_channel_popup().create(channel_name,
channel_description,
emoji=None)
permission_popup.add_permission().set_who_holds_asset_and_amount(asset, amount).set_is_allowed_to(
'viewOnly').switch_hide_permission_checkbox(True).create_permission()
permission_popup.hide_permission(True)
permission_popup.save_button.click()
permission_popup = create_channel_popup.add_permission()
time.sleep(3)
permission_popup.set_who_holds_asset_and_amount(asset, amount)
permission_popup.set_is_allowed_to('viewOnly')
permission_popup.switch_hide_permission_checkbox(True)
permission_popup.create_permission()
create_channel_popup.save_create_button.click()
channel = community_screen.left_panel.get_channel_parameters(channel_name)
assert driver.waitFor(lambda: channel in community_screen.left_panel.channels,
configs.timeouts.UI_LOAD_TIMEOUT_MSEC)

View File

@ -9,6 +9,7 @@ from constants import UserAccount, RandomUser, RandomCommunity, CommunityData
from constants.community import ToastMessages
from gui.screens.community import Members
from gui.screens.messages import MessagesScreen
from scripts.utils.generators import random_text_message
from . import marks
import configs.testpath
@ -69,7 +70,8 @@ def test_community_admin_ban_kick_member_and_delete_message(multiple_instances):
main_screen.create_community(community_data=community)
community_screen = main_screen.left_panel.select_community(community.name)
community_screen.left_panel.invite_people_to_community([user_one.name], 'Message')
add_members = community_screen.left_panel.open_add_members_popup()
add_members.invite([user_one.name], message=random_text_message())
main_screen.hide()
with step(f'User {user_one.name}, accept invitation from {user_two.name}'):

View File

@ -7,6 +7,7 @@ from allure_commons._allure import step
import driver
from gui.components.community.pinned_messages_popup import PinnedMessagesPopup
from gui.main_window import MainWindow
from scripts.utils.generators import random_text_message
from . import marks
import configs
from constants import ColorCodes, UserAccount, RandomUser, RandomCommunity
@ -70,7 +71,8 @@ def test_join_community_and_pin_unpin_message(multiple_instances):
community = RandomCommunity()
main_screen.create_community(community_data=community)
community_screen = main_screen.left_panel.select_community(community.name)
community_screen.left_panel.invite_people_to_community([user_one.name], 'Message')
add_members = community_screen.left_panel.open_add_members_popup()
add_members.invite([user_one.name], message=random_text_message())
main_screen.hide()
with step(f'User {user_one.name}, accept invitation from {user_two.name}'):

View File

@ -6,6 +6,7 @@ import driver
from gui.components.profile_popup import ProfilePopupFromMembers
from gui.components.remove_contact_popup import RemoveContactPopup
from gui.main_window import MainWindow
from scripts.utils.generators import random_text_message
from . import marks
import configs
from constants import UserAccount, RandomUser, RandomCommunity
@ -98,8 +99,8 @@ def test_communities_send_accept_decline_request_remove_contact_from_profile(mul
main_screen.create_community(community_data=community)
community_screen = main_screen.left_panel.select_community(community.name)
community_screen.left_panel.invite_people_to_community([user_one.name], 'Message')
community_screen.left_panel.invite_people_to_community([user_three.name], 'Message')
add_popup = community_screen.left_panel.open_add_members_popup()
add_popup.invite([user_one.name, user_three.name], message=random_text_message())
main_screen.hide()
with step(f'User {user_three.name}, accept invitation from {user_two.name}'):

View File

@ -16,6 +16,7 @@ from gui.screens.messages import MessagesScreen
import configs.testpath
from constants import RandomUser, UserAccount
from gui.main_window import MainWindow
from scripts.utils.generators import random_text_message
from scripts.utils.parsers import remove_tags
from . import marks
@ -196,8 +197,8 @@ def test_1x1_chat_add_contact_in_settings(multiple_instances):
f"There is no image in the last message"
with step(f'User {user_one.name}, reply to own message and verify that message displayed as a reply'):
chat_message_reply = \
''.join(random.choice(string.ascii_letters + string.digits) for _ in range(1, 21))
chat_message_reply = random_text_message()
message.hover_message().reply_own_message(chat_message_reply)
chat = main_window.left_panel.open_messages_screen().left_panel.click_chat_by_name(user_two.name)
message = chat.find_message_by_text(chat_message_reply, 0)

View File

@ -13,6 +13,7 @@ from constants import UserAccount, RandomUser
from constants.messaging import Messaging
from gui.main_window import MainWindow
from gui.screens.messages import MessagesScreen, ToolBar
from scripts.utils.generators import random_text_message
from . import marks
pytestmark = marks
@ -128,8 +129,7 @@ def test_group_chat_add_contact_in_ac(multiple_instances, community_name, domain
assert messages_screen.group_chat.group_name == group_chat_new_name
with step('Send message to group chat and verify it was sent'):
chat_message = ''.join(random.choices(string.ascii_letters +
string.digits, k=40))
chat_message = random_text_message()
messages_screen.group_chat.send_message_to_group_chat(chat_message)
message_objects = messages_screen.chat.messages('0')
message_items = [message.text for message in message_objects]
@ -166,8 +166,7 @@ def test_group_chat_add_contact_in_ac(multiple_instances, community_name, domain
assert len(messages_screen.right_panel.members) == 2
with step('Send message to group chat after user removal and verify it'):
chat_message_2 = ''.join(random.choices(string.ascii_letters +
string.digits, k=40))
chat_message_2 = random_text_message()
messages_screen.group_chat.send_message_to_group_chat(chat_message_2)
message_objects = messages_screen.chat.messages('1')
message_items = [message.text for message in message_objects]