Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Add tear_down for base Rocket.Chat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-popova committed May 16, 2019
1 parent 4041b9a commit 1342b97
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 99 deletions.
17 changes: 17 additions & 0 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,23 @@ def does_email_exist(self, email):

return result != []

def does_room_exist(self, room_name):
"""Checks if the specified room exists. """

response = self.rocket.rooms_get().json()

try:
rooms = response['update']
except KeyError:
raise APIError(response.get('error'))

rooms_existing_map = []

for room in rooms:
rooms_existing_map.append(room_name in room.get('name', []))

return True in rooms_existing_map

def create_user(self):
"""Creates a test user. """

Expand Down
192 changes: 94 additions & 98 deletions rc_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait

from base import RocketChatTestCase
from base import RocketChatTestCase, APIError


class GeneralRocketChatTestCase(RocketChatTestCase):
"""General tests for Rocket.Chat. """

def __init__(self, addr, username, password, **kwargs):
RocketChatTestCase.__init__(self, addr, username, password, **kwargs)
def __init__(self, addr, username, password, expected_rooms, **kwargs):
RocketChatTestCase.__init__(self, addr, username, password, expected_rooms, **kwargs)

self.make_connections('connect_to_rc_api')

Expand All @@ -61,100 +61,6 @@ def __init__(self, addr, username, password, **kwargs):
# Private methods
#

def _delete_channels(self):
options_btn = self.browser.driver.find_elements_by_css_selector(
'.sidebar__toolbar-button.rc-tooltip.rc-tooltip--down.js-button')

assert options_btn

self.browser.driver.execute_script('arguments[0].click();',
options_btn[-1])

administration_btn = self.browser.find_by_css('.rc-popover__item-text')
administration_btn.click()

rooms_btn = self.browser.driver.find_elements_by_css_selector(
'a.sidebar-item__link[aria-label="Rooms"]')

assert rooms_btn

self.browser.driver.execute_script("arguments[0].click();",
rooms_btn[0])

selected_room = self.browser.find_by_xpath(
'//td[@class="border-component-color"][text()="{0}"]'.format(
self._public_channel_name))

assert selected_room

selected_room.click()

delete_btn = self.browser.driver.find_element_by_class_name('button')

assert delete_btn

delete_btn.click()

confirm_btn = self.find_by_css('input[value="Yes, delete it!"]')

assert confirm_btn

confirm_btn.first.click()

WebDriverWait(self.browser.driver, 10).until(
lambda _: self._check_modal_window_visibility())

selected_room = self.browser.find_by_xpath(
'//td[@class="border-component-color"][text()="{0}"]'.format(
self._private_channel_name))

assert selected_room

selected_room.click()

delete_btn = self.browser.driver.find_element_by_class_name('button')

assert delete_btn

delete_btn.click()

confirm_btn = self.find_by_css('input[value="Yes, delete it!"]')

assert confirm_btn

confirm_btn.first.click()

WebDriverWait(self.browser.driver, 10).until(
lambda _: self._check_modal_window_visibility())

selected_room = self.browser.find_by_xpath(
'//td[@class="border-component-color"][text()="{0}"]'.format(
self._read_only_channel_name))

assert selected_room

selected_room.click()

delete_btn = self.browser.driver.find_element_by_class_name('button')

assert delete_btn

delete_btn.click()

confirm_btn = self.find_by_css('input[value="Yes, delete it!"]')

assert confirm_btn

confirm_btn.first.click()

close_btn = self.browser.driver.find_elements_by_css_selector(
'button[data-action="close"]')

assert close_btn

self.browser.driver.execute_script('arguments[0].click();',
close_btn[0])

@staticmethod
def _check_elem_disabled_state(elem):
act = elem._element.get_attribute('disabled') # pylint: disable=protected-access
Expand Down Expand Up @@ -193,6 +99,27 @@ def _copy_image_to_clipboard(self):
# Public methods
#

def tear_down(self):
"""Makes clean up of the testing environment. """

print('Tear down for Rocket.Chat base tests: "started"')
clean_methods = (
self.delete_all_extra_users,
self.delete_all_extra_rooms,
)

for clean_method in clean_methods:
print('Running {}'.format(clean_method.__name__))

try:
clean_method()

except APIError as error:
print('Tear down: finished with status "failed"')
raise error

print('Tear down: finished with status "done"')

def test_creating_user(self): # pylint: disable=too-many-locals
"""Tests if it's possible to create user. """

Expand Down Expand Up @@ -1080,6 +1007,71 @@ def test_recreating_channel_with_same_name(self): # pylint: disable=too-many-st
self.browser.driver.execute_script('arguments[0].click();',
close_btn[0])

def test_deleting_room(self):
""" Tests if it's possible to delete room in administration interface. """

does_public_channel_exist = self.check_with_retries(
self.does_room_exist,
self._public_channel_name
)

assert does_public_channel_exist

options_btn = self.browser.driver.find_elements_by_css_selector(
'.sidebar__toolbar-button.rc-tooltip.rc-tooltip--down.js-button')

assert options_btn

self.browser.driver.execute_script('arguments[0].click();',
options_btn[-1])

administration_btn = self.browser.find_by_css('.rc-popover__item-text')
administration_btn.click()

rooms_btn = self.browser.driver.find_elements_by_css_selector(
'a.sidebar-item__link[aria-label="Rooms"]')

assert rooms_btn

self.browser.driver.execute_script("arguments[0].click();",
rooms_btn[0])

selected_room = self.browser.find_by_xpath(
'//td[@class="border-component-color"][text()="{0}"]'.format(
self._public_channel_name))

assert selected_room

selected_room.click()

delete_btn = self.browser.driver.find_element_by_class_name('button')

assert delete_btn

delete_btn.click()

confirm_btn = self.find_by_css('input[value="Yes, delete it!"]')

assert confirm_btn

confirm_btn.first.click()

does_public_channel_exist = self.check_with_retries(
self.does_room_exist,
self._public_channel_name,
expected_res=False
)

assert not does_public_channel_exist

close_btn = self.browser.driver.find_elements_by_css_selector(
'button[data-action="close"]')

assert close_btn

self.browser.driver.execute_script('arguments[0].click();',
close_btn[0])

def test_pasting_string_from_clipboard(self):
"""Tests if it's possible to paste a string from the clipboard and send
it to the #general channel.
Expand Down Expand Up @@ -1277,8 +1269,12 @@ def main():
if not options.password:
parser.error('Password is not specified')

if not options.exp_rooms:
options.exp_rooms = 'hr,leave-coordination'

test_cases = GeneralRocketChatTestCase(options.host, options.username,
options.password)
options.password,
expected_rooms=options.exp_rooms,)
exit_code = test_cases.run()
sys.exit(exit_code)

Expand Down
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ for i in "${RUN[@]}"; do
case "${i}" in
# General tests for Rocket.Chat
rc)
${PYTHON} rc_tests.py --host="${HOST}" --username="${USERNAME}" --password="${PASSWORD}" || exit_code=$?
${PYTHON} rc_tests.py --host="${HOST}" --username="${USERNAME}" --password="${PASSWORD}" --rooms="${EXP_ROOMS}"|| exit_code=$?
;;
# Tests for different scripts
happy_birthder_script)
Expand Down

0 comments on commit 1342b97

Please sign in to comment.