Skip to content

Commit

Permalink
chore: refactor community tests to use random community data
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiyaig committed Oct 18, 2024
1 parent 09524b9 commit f48eed2
Show file tree
Hide file tree
Showing 42 changed files with 251 additions and 332 deletions.
57 changes: 41 additions & 16 deletions test/e2e/constants/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from typing import Optional

import configs
from scripts.utils.generators import random_name_string, random_password_string
from constants import ColorCodes
from scripts.tools.image import Image
from scripts.utils.generators import random_name_string, random_password_string, random_community_name, \
random_community_description, random_community_introduction, random_community_leave_message, random_community_tags, \
random_color


@dataclass
Expand Down Expand Up @@ -34,28 +38,49 @@ def __init__(self, seed_phrase, status_address):
)


@dataclass
class CommunityChannel:
name: str = None
selected: bool = None
visible: bool = None


@dataclass
class CommunityData:
name: str = None
description: str = None
members: str = None
image: Image = None
logo: dict = field(default_factory=dict)
banner: dict = field(default_factory=dict)
color: Optional[str] = None
tags: list = field(default_factory=list)
introduction: str = None
leaving_message: str = None


class RandomCommunity(CommunityData):
def __init__(self):
super().__init__(
name=random_community_name(),
description=random_community_description(),
logo={'fp': configs.testpath.TEST_IMAGES / 'comm_logo.jpeg', 'zoom': None, 'shift': None},
banner={'fp': configs.testpath.TEST_IMAGES / 'comm_banner.jpeg', 'zoom': None, 'shift': None},
color=random_color(),
tags=random_community_tags(),
introduction=random_community_introduction(),
leaving_message=random_community_leave_message()

)


user_account_one = UserAccount('squisher', '0000000000', [
'rail', 'witness', 'era', 'asthma', 'empty', 'cheap', 'shed', 'pond', 'skate', 'amount', 'invite', 'year'
], '0x3286c371ef648fe6232324b27ee0515f4ded24d9')
user_account_two = UserAccount('athletic', '0000000000', [
'measure', 'cube', 'cousin', 'debris', 'slam', 'ignore', 'seven', 'hat', 'satisfy', 'frown', 'casino', 'inflict'
], '0x99C096bB5F12bDe37DE9dbee8257Ebe2a5667C46')

community_params = {
'name': ''.join(random.choices(string.ascii_letters +
string.digits, k=30)),
'description': ''.join(random.choices(string.ascii_letters +
string.digits, k=140)),
'logo': {'fp': configs.testpath.TEST_IMAGES / 'comm_logo.jpeg', 'zoom': None, 'shift': None},
'banner': {'fp': configs.testpath.TEST_IMAGES / 'comm_banner.jpeg', 'zoom': None, 'shift': None},
'intro': ''.join(random.choices(string.ascii_letters +
string.digits, k=200)),
'outro': ''.join(random.choices(string.ascii_letters +
string.digits, k=80))
}

UserCommunityInfo = namedtuple('CommunityInfo', ['name', 'description', 'members', 'image'])
UserChannel = namedtuple('Channel', ['name', 'selected', 'visible'])

account_list_item = namedtuple('AccountListItem', ['name', 'color', 'emoji'])
wallet_account_list_item = namedtuple('WalletAccountListItem', ['name', 'icon_color', 'icon_emoji', 'object'])
Expand Down
79 changes: 15 additions & 64 deletions test/e2e/gui/components/community/create_community_popups.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import configs
import driver
from constants import RandomCommunity, CommunityData
from gui.components.base_popup import BasePopup
from gui.components.community.color_select_popup import ColorSelectPopup
from gui.components.community.tags_select_popup import TagsSelectPopup
Expand Down Expand Up @@ -37,7 +38,7 @@ class CreateCommunityPopup(BasePopup):

def __init__(self):
super().__init__()
self._scroll = Scroll(names.generalView_StatusScrollView )
self._scroll = Scroll(names.generalView_StatusScrollView)
self._name_text_edit = TextEdit(names.createCommunityNameInput_TextEdit)
self._description_text_edit = TextEdit(names.createCommunityDescriptionInput_TextEdit)
self._add_logo_button = Button(names.addButton_StatusRoundButton2)
Expand Down Expand Up @@ -95,40 +96,6 @@ def set_description(self, value: str):
self._scroll.vertical_scroll_down(self._description_text_edit)
self._description_text_edit.text = value

@property
@allure.step('Get community logo')
def logo(self):
return NotImplementedError

def _open_logo_file_dialog(self, attempt: int = 2):
self._add_logo_button.click()
try:
return OpenFileDialog().wait_until_appears()
except Exception as err:
if attempt:
LOG.debug(err)
return self._open_logo_file_dialog(attempt - 1)
else:
raise err

@allure.step('Set community logo')
def logo(self, kwargs: dict):
self._open_logo_file_dialog().open_file(kwargs['fp'])
PictureEditPopup().wait_until_appears().set_zoom_shift_for_picture(kwargs.get('zoom', None),
kwargs.get('shift', None))

@property
@allure.step('Get community banner')
def banner(self):
raise NotImplementedError

@allure.step('Set community banner')
def banner(self, kwargs: dict):
self._add_banner_button.click()
OpenFileDialog().wait_until_appears().open_file(kwargs['fp'])
PictureEditPopup().wait_until_appears().set_zoom_shift_for_picture(kwargs.get('zoom', None),
kwargs.get('shift', None))

@allure.step('Set community logo without file upload dialog')
def set_logo_without_file_upload_dialog(self, path):
self._scroll.vertical_scroll_down(self._add_logo_button)
Expand Down Expand Up @@ -195,9 +162,9 @@ def verify_color(self, color: str):
assert self.get_color() == color

@allure.step('Select tags and verify they were set correctly')
def verify_tags(self, tags: typing.List[str]):
def verify_tags(self, tags: typing.List[str]):
actual_tags = self.get_tags()
assert tags == actual_tags
assert tags.sort(reverse=False) == actual_tags.sort(reverse=False)

@allure.step('Verify default values of checkboxes')
def verify_checkboxes_values(self):
Expand All @@ -206,37 +173,21 @@ def verify_checkboxes_values(self):
assert not self.is_pin_messages_checkbox_checked()

@allure.step('Verify community create popup fields and create community without file upload dialog usage')
def create_community(self, name: str, description: str, intro: str, outro: str, logo, banner, color: str,
tags_to_set: typing.List[str], tags):
self.set_name(name)
self.set_description(description)
self.set_logo_without_file_upload_dialog(logo)
def create_community(self, community_data: CommunityData):
self.set_name(community_data.name)
self.set_description(community_data.description)
self.set_logo_without_file_upload_dialog(community_data.logo['fp'])
PictureEditPopup().set_zoom_shift_for_picture(None, None)
self.set_banner_without_file_upload_dialog(banner)
self.set_banner_without_file_upload_dialog(community_data.banner['fp'])
PictureEditPopup().set_zoom_shift_for_picture(None, None)
self.set_color(color)
self.verify_color(color)
self.set_tags(tags_to_set)
self.verify_tags(tags)
self.set_color(community_data.color)
self.verify_color(community_data.color)
self.set_tags(community_data.tags)
self.verify_tags(community_data.tags)
self.verify_checkboxes_values()
self._next_button.click()
self.set_intro(intro)
self.set_outro(outro)
self._create_community_button.click()
self.wait_until_hidden()
return CommunityScreen().wait_until_appears()

@allure.step('Create simple community without verifications')
def create_simple_community(self, name: str, description: str, intro: str, outro: str, logo, banner):
self.set_name(name)
self.set_description(description)
self.set_logo_without_file_upload_dialog(logo)
PictureEditPopup().set_zoom_shift_for_picture(None, None)
self.set_banner_without_file_upload_dialog(banner)
PictureEditPopup().set_zoom_shift_for_picture(None, None)
self._next_button.click()
self.set_intro(intro)
self.set_outro(outro)
self.set_intro(community_data.introduction)
self.set_outro(community_data.leaving_message)
self._create_community_button.click()
self.wait_until_hidden()
return CommunityScreen().wait_until_appears()
14 changes: 8 additions & 6 deletions test/e2e/gui/components/community/tags_select_popup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import time
import typing

Expand Down Expand Up @@ -29,22 +30,23 @@ def select_tags(self, values: typing.List[str]):
tags = []
checked = []
unchecked = []
_values = copy.deepcopy(values)
for obj in driver.findAllObjects(self._tag_template.real_name):
name = str(obj.name)
tags.append(name)
if name in values:
if name in _values:
if not obj.removable:
driver.mouseClick(obj)
QObject(obj).click()
checked.append(name)
time.sleep(1)
values.remove(name)
_values.remove(name)
else:
# Selected and should be unselected
if obj.removable:
driver.mouseClick(obj)
QObject(obj).click()
time.sleep(1)
unchecked.append(name)
if values:
if _values:
raise LookupError(
f'Tags: {values} not found in {tags}. Checked tags: {checked}, Unchecked tags: {unchecked}')
f'Tags: {_values} not found in {tags}. Checked tags: {checked}, Unchecked tags: {unchecked}')
self._confirm_button.click()
10 changes: 5 additions & 5 deletions test/e2e/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import configs
import driver
from constants import UserAccount, RandomUser, ColorCodes
from constants import UserAccount, RandomUser, RandomCommunity, CommunityData
from gui.components.community.invite_contacts import InviteContactsPopup
from gui.components.onboarding.share_usage_data_popup import ShareUsageDataPopup
from gui.components.context_menu import ContextMenu
Expand Down Expand Up @@ -174,7 +174,7 @@ def prepare(self) -> 'Window':
return super().prepare()

@allure.step('Sign Up user')
def sign_up(self, user_account: UserAccount = RandomUser()):
def sign_up(self, user_account: UserAccount):
BeforeStartedPopUp().get_started()
welcome_screen = WelcomeToStatusView().wait_until_appears()
profile_view = welcome_screen.get_keys().generate_new_keys()
Expand Down Expand Up @@ -213,11 +213,11 @@ def authorize_user(self, user_account) -> 'MainWindow':
return self.sign_up(user_account)

@allure.step('Create community')
def create_community(self, name, description, intro, outro, logo, banner, tags_to_set, tags) -> CommunityScreen:
def create_community(self, community_data: CommunityData) -> CommunityScreen:
communities_portal = self.left_panel.open_communities_portal()
create_community_form = communities_portal.open_create_community_popup()
color = ColorCodes.ORANGE.value
app_screen = create_community_form.create_community(name, description, intro, outro, logo, banner, color, tags_to_set, tags)
assert isinstance(community_data, CommunityData)
app_screen = create_community_form.create_community(community_data)
return app_screen

@allure.step('Wait for notification and get text')
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/gui/objects_map/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
communityColorPicker_ColorPicker = {"container": statusDesktop_mainWindow_overlay, "objectName": "communityColorPicker", "type": "ColorPicker", "visible": True}
StatusPickerButton = {"checkable": False, "container": communityColorPicker_ColorPicker, "type": "StatusPickerButton", "unnamed": 1, "visible": True}
communityTagsPicker_TagsPicker = {"container": statusDesktop_mainWindow_overlay, "objectName": "communityTagsPicker", "type": "TagsPicker", "visible": True}
choose_tags_StatusPickerButton = {"checkable": False, "container": communityTagsPicker_TagsPicker, "type": "StatusPickerButton", "unnamed": 1, "visible": True}
choose_tags_StatusPickerButton = {"checkable": False, "container": communityTagsPicker_TagsPicker, "id": "pickerButton", "type": "StatusPickerButton", "unnamed": 1, "visible": True}
archiveSupportToggle_StatusCheckBox = {"checkable": True, "container": statusDesktop_mainWindow_overlay, "id": "archiveSupportToggle", "type": "StatusCheckBox", "unnamed": 1, "visible": True}
requestToJoinToggle_StatusCheckBox = {"checkable": True, "container": statusDesktop_mainWindow_overlay, "id": "requestToJoinToggle", "type": "StatusCheckBox", "unnamed": 1, "visible": True}
pinMessagesToggle_StatusCheckBox = {"checkable": True, "container": statusDesktop_mainWindow_overlay, "id": "pinMessagesToggle", "type": "StatusCheckBox", "unnamed": 1, "visible": True}
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/gui/screens/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import configs
import driver
from constants import UserChannel, ColorCodes
from constants import CommunityChannel
from driver.objects_access import walk_children
from gui.components.community.community_category_popup import NewCategoryPopup, EditCategoryPopup, CategoryPopup
from gui.components.community.community_channel_popups import EditChannelPopup, NewChannelPopup
Expand Down Expand Up @@ -243,13 +243,13 @@ def is_join_community_visible(self) -> bool:

@property
@allure.step('Get channels')
def channels(self) -> typing.List[UserChannel]:
def channels(self) -> typing.List[CommunityChannel]:
time.sleep(0.5)
channels_list = []
for obj in driver.findAllObjects(self.chatListItemDropAreaItem.real_name):
container = driver.objectMap.realName(obj)
self._channel_icon_template.real_name['container'] = container
channels_list.append(UserChannel(
channels_list.append(CommunityChannel(
str(obj.objectName),
obj.item.selected,
obj.item.visible
Expand All @@ -267,7 +267,7 @@ def get_arrow_icon_rotation_value(self, category_name) -> int:
return int(category.get_arrow_icon_rotation_value())

@allure.step('Get channel params')
def get_channel_parameters(self, name) -> UserChannel:
def get_channel_parameters(self, name) -> CommunityChannel:
for channel in self.channels:
if channel.name == name:
return channel
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/gui/screens/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,11 @@ def click_hide_icon(self, index):

@allure.step('Set password in first field')
def set_password_in_first_field(self, value: str):
self._new_password_text_field.clear().text = value
self._new_password_text_field.text = value

@allure.step('Set password in confirmation field')
def set_password_in_confirmation_field(self, value: str):
self._confirm_password_text_field.clear().text = value
self._confirm_password_text_field.text = value

@allure.step('Set password and open Confirmation password view')
def create_password(self, value: str) -> 'ConfirmPasswordView':
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/gui/screens/settings_communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import configs.timeouts
import driver
from constants import UserCommunityInfo
from constants import CommunityData
from driver import objects_access
from gui.elements.button import Button
from gui.elements.object import QObject
Expand All @@ -29,7 +29,7 @@ def __init__(self):

@property
@allure.step('Get communities')
def communities(self) -> typing.List[UserCommunityInfo]:
def communities(self) -> typing.List[CommunityData]:
time.sleep(0.5)
_communities = []
for obj in driver.findAllObjects(self._community_item.real_name):
Expand All @@ -47,7 +47,7 @@ def communities(self) -> typing.List[UserCommunityInfo]:
members = str(name_members_labels[1].text)
image = self._community_template_image.image

_communities.append(UserCommunityInfo(name, description, members, image))
_communities.append(CommunityData(name, description, members, image))
return _communities

def _get_community_item(self, name: str):
Expand All @@ -59,7 +59,7 @@ def _get_community_item(self, name: str):

@allure.step('Open community info')
def get_community_info(
self, name: str, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_MSEC) -> UserCommunityInfo:
self, name: str, timeout_msec: int = configs.timeouts.UI_LOAD_TIMEOUT_MSEC) -> CommunityData:
started_at = time.monotonic()
while True:
communities = self.communities
Expand Down
Loading

0 comments on commit f48eed2

Please sign in to comment.