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

Adding some additional query tests, as well as some options tests. #103

Merged
merged 5 commits into from
Oct 31, 2018

Conversation

jrbenny35
Copy link
Collaborator

Fixes #86, #87, #88, #89, #90, #91, #92.

@hackebrot hackebrot added the tests Tasks to implement UI tests label Oct 29, 2018
Copy link
Collaborator

@hackebrot hackebrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @jrbenny35! 👍

As discussed earlier, can you please check if the root_user change is strictly required? I left a few comments on code formatting, type annotations and comprehensibility.

@@ -103,10 +103,10 @@ def test_search_for_unpublished_query(
login_page: LoginPage,
server_url,
selenium,
user: User,
root_user: User,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please confirm that this is necessary and if so, might this be a regression in Redash?

pages/queries.py Outdated

@property
def description(self) -> typing.Any:
return self.find_element(*self._query_description_locator).text

def dropdown_menu(self, item=None) -> typing.Any:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest changing this method name as follow, so that it becomes clear that this performs a UI interaction and doesn't yield the dropdown menu element:

Suggested change
def dropdown_menu(self, item=None) -> typing.Any:
def click_dropdown_menu(self, item=None) -> typing.Any:

pages/queries.py Outdated
term.click()
self.find_element(*self._query_modal_archive_locator).click()
return
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what those if branches do from a users perspective? The first one forks a query and shows the detail page for that query, and the other one archives the query, but doesn't return an element?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As to the implementation, I suggest to rename the variables slightly and make use of a generator and returns.

def click_dropdown_menu(self, text=None) -> typing.Any:
    menu = self.find_element(*self._query_dropdown_menu_locator)
    items = menu.find_elements(*self._query_dropdown_menu_item_locator)

    menu.click()

    for item in (i for i in items if i.text in text):
        if text == "Fork":
            item.click()
            return QueryDetailPage(self.selenium, self.base_url)

        if text == "Archive":
            item.click()
            self.find_element(*self._query_modal_archive_locator).click()
            return

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Archive" just archives the query. There can be nothing done after you archive it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can return a Exception with a message?

pages/queries.py Outdated
except Exception:
self.find_element(*self._query_description_locator).click()
element = self.find_element(*self._query_description_edit_locator)
element.send_keys(" {}".format(description))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3.6! 🚀

Suggested change
element.send_keys(" {}".format(description))
element.send_keys(f" {description}")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old habits die hard!

pages/queries.py Outdated
element = self.find_element(*self._query_name_locator)
element.click()
element = self.find_element(*self._query_name_edit_locator)
element.send_keys(" {}".format(title))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
element.send_keys(" {}".format(title))
element.send_keys(f" {title}")

server_url,
selenium,
root_user: User,
variables,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add type annotations for all parameters that don't are not annotated yet in all tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I do this in a following PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but it would be best to add them along with the new code.

query = search.queries[0].click()
assert query.title == query_specs["name"]
query.edit_title("NEW")
assert query.title == query_specs["name"] + " NEW"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query_specs = variables["default"]["queries"]["edit-query"]
name = query_specs["name"]

search = page.search(name)
query = search.queries[0].click()
assert query.title == name

query.edit_title("NEW")
assert query.title == f"{name} NEW"

@jrbenny35
Copy link
Collaborator Author

I spoke to @jezdez on IRC today and was told that the usage of root_user was probably broken in the past, and we should have to use root_user in some of these tests, especially those that edit different things.

pages/queries.py Outdated
item.click()
self.find_element(*self._query_modal_archive_locator).click()
return
return Exception(f"{item} was not found within the dropdown menu.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to raise this Exception and can probably make this more specific.

Suggested change
return Exception(f"{item} was not found within the dropdown menu.")
raise ValueError(f"{item} was not found within the dropdown menu.")

pages/queries.py Outdated
def edit_source(self) -> typing.Any:
return self.find_element(*self._query_edit_source_locator)

def edit_title(self, title=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make title required, because a query title of " None" seems unlikely.

Suggested change
def edit_title(self, title=None):
def edit_title(self, title: str) -> None:

pages/queries.py Outdated
element.send_keys(Keys.ENTER)

@property
def edit_source(self) -> typing.Any:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the names of these methods slightly confusing: edit_description and edit_source suggests that they do similar things. However one is a method that performs UI actions and returns None, the other one is a property and returns the element.

I suggest to use verbs for methods edit_description() and nouns for properties edit_source_button.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense. I was literally calling it what the button was, but adding btn or button was what I had in mind I think, as it is a button.

tests/test_queries.py Outdated Show resolved Hide resolved
pages/queries.py Outdated Show resolved Hide resolved
pages/queries.py Show resolved Hide resolved
pages/queries.py Show resolved Hide resolved
Copy link
Collaborator

@hackebrot hackebrot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tests Tasks to implement UI tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants