Skip to content

Commit

Permalink
fixes selenium tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Nov 15, 2024
1 parent 0e99abf commit b408d9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</form>
{% else %}
<div>Seems you have not been granted to any Office.</div>
<div>Seems you do not have any Office enabled.</div>
{% endif %}
</div>
</div>
Expand Down
19 changes: 10 additions & 9 deletions src/country_workspace/workspaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ def is_hq_active() -> bool:
return bool(get_selected_tenant() and get_selected_tenant().name == settings.TENANT_HQ)


# def set_selected_tenant(tenant: "Office") -> None:
# state.tenant = tenant
# signer = get_cookie_signer()
# state.add_cookies(conf.COOKIE_NAME, signer.sign(tenant.slug))
#
# def set_selected_program(program: "Program") -> None:
# state.program = program
# signer = get_cookie_signer()
# state.add_cookies(conf.COOKIE_NAME, signer.sign(program.id))
def set_selected_tenant(tenant: "Office") -> None:
state.tenant = tenant
signer = get_cookie_signer()
state.add_cookies(conf.TENANT_COOKIE_NAME, signer.sign(tenant.slug))


def set_selected_program(program: "Program") -> None:
state.program = program
signer = get_cookie_signer()
state.add_cookies(conf.PROGRAM_COOKIE_NAME, signer.sign(program.id))


def is_tenant_valid() -> bool:
Expand Down
65 changes: 6 additions & 59 deletions tests/functional/test_f_household.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def household(program):
def test_list_household(selenium, user, household: "CountryHousehold"):
from testutils.perms import user_grant_permissions

from country_workspace.workspaces.models import CountryHousehold

selenium.get(f"{selenium.live_server.url}")
with user_grant_permissions(
user,
Expand All @@ -55,71 +53,20 @@ def test_list_household(selenium, user, household: "CountryHousehold"):
# Login
selenium.find_by_css("input[name=username").send_keys(user.username)
selenium.find_by_css("input[name=password").send_keys(user._password)
selenium.find_by_css("input[type=submit").click()
selenium.find_by_css("button.primary").click()
# Select Tenant
Select(selenium.wait_for(By.CSS_SELECTOR, "select[name=tenant]")).select_by_visible_text(
household.program.country_office.name
)
selenium.find_by_css("input[type=submit").click()
selenium.wait_for(By.CSS_SELECTOR, "h1")
# Workspace
selenium.wait_for(By.LINK_TEXT, str(CountryHousehold._meta.verbose_name_plural)).click()
selenium.wait_for_url("/workspaces/countryhousehold/")
# Household changelist
assert "Please select a program on the left" in selenium.page_source
selenium.wait_for(
By.CSS_SELECTOR,
"#batch__program__exact_batch__program__isnull .select2-selection.select2-selection--single",
).click()
el = selenium.wait_for(By.CSS_SELECTOR, ".select2-search__field")
el.send_keys(household.program.name)
selenium.wait_for(
By.CSS_SELECTOR,
"li.select2-results__option.select2-results__option--highlighted",
).click()
Select(selenium.wait_for(By.CSS_SELECTOR, "select[name=program]")).select_by_visible_text(
household.program.name
)
selenium.wait_for(By.LINK_TEXT, "Households").click()

selenium.wait_for(By.LINK_TEXT, str(household.name)).click()
selenium.wait_for_url(household.get_change_url())
selenium.wait_for(
By.CSS_SELECTOR,
"a.closelink",
).click()
selenium.wait_for_url(f"/workspaces/countryhousehold/?batch__program__exact={household.program.pk}")


@pytest.mark.selenium
def test_edit_household(selenium, user, household: "CountryHousehold"):
from testutils.perms import user_grant_permissions
from testutils.selenium import force_login

with user_grant_permissions(
user,
[
"workspaces.view_countryhousehold",
"workspaces.view_countryindividual",
"workspaces.view_countryprogram",
"workspaces.change_countryhousehold",
"workspaces.change_countryindividual",
"workspaces.change_countryprogram",
],
household.program.country_office,
):
force_login(selenium, user, household.program.country_office)
selenium.get(f"{selenium.live_server.url}/workspaces/countryhousehold/")
assert "Please select a program on the left" in selenium.page_source

#
# selenium.wait_for(By.LINK_TEXT, "Close").click()
# selenium.wait_for(By.CSS_SELECTOR, "h1")
#
# selenium.wait_for(
# By.CSS_SELECTOR,
# "#program__exact_program__isnull .select2-selection.select2-selection--single",
# ).click()
# el = selenium.wait_for(By.CSS_SELECTOR, ".select2-search__field")
# el.send_keys(household.program.name)
# selenium.wait_for(
# By.CSS_SELECTOR,
# "li.select2-results__option.select2-results__option--highlighted",
# ).click()
# selenium.wait_for_url("/workspaces/countryhousehold/?&program__exact=1")
selenium.wait_for_url("/workspaces/countryhousehold/")
4 changes: 2 additions & 2 deletions tests/functional/test_f_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def test_login(selenium, user):
selenium.get(f"{selenium.live_server.url}")
selenium.find_by_css("input[name=username").send_keys(user.username)
selenium.find_by_css("input[name=password").send_keys(user._password)
selenium.find_by_css("input[type=submit").click()
assert "Seems you do not have any tenant enabled." in selenium.page_source
selenium.find_by_css("button.primary").click()
assert "Seems you do not have any Office enabled." in selenium.page_source

0 comments on commit b408d9c

Please sign in to comment.