Skip to content

Commit

Permalink
updstes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Nov 15, 2024
1 parent 3e3df9e commit f0cbd87
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 51 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ docs = [
]

distribution = [
"pytricia>=1.0.2",
"uwsgi>=2.0.27",
]

Expand Down
22 changes: 0 additions & 22 deletions src/country_workspace/utils/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from country_workspace.state import state

from .http import get_client_ip

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -70,23 +68,3 @@ def header_key(value: str, **kwargs: Any) -> bool:
else:
value = f"HTTP_{value.strip()}"
return value in state.request.META


try:
import pytricia

pyt = pytricia.PyTricia()

def client_ip(value: str, **kwargs: Any) -> bool:
remote = get_client_ip()
pyt.insert(value, "")
return remote in pyt

except ImportError:
logger.warning("pytricia not installed. 'client_ip' flag not registared ")

def client_ip(value: str, **kwargs: Any) -> bool:
return True


conditions.register("User IP", client_ip)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</form>
{% else %}
<div>Seems you do not have any Office enabled.</div>
<div>You do not have any Office enabled.</div>
{% endif %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_f_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def test_login(selenium, user):
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("button.primary").click()
assert "Seems you do not have any Office enabled." in selenium.page_source
assert "You do not have any Office enabled." in selenium.page_source
2 changes: 1 addition & 1 deletion tests/test_user_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_login(app, user, data: "list[Household]", settings: "SettingsWrapper"):
assert res.status_code == 302
assert res.location == reverse("workspace:select_tenant")
res = res.follow()
assert "Seems you have not been granted to any Office." in res.text
assert "You do not have any Office enabled." in res.text

with user_grant_permissions(
user, ["workspaces.view_countryhousehold", "workspaces.view_countryindividual"], program.country_office
Expand Down
18 changes: 1 addition & 17 deletions tests/utils/test_utils_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@
import pytest

from country_workspace.state import state
from country_workspace.utils.flags import client_ip, debug, env_var, header_key, hostname, superuser, validate_bool


@pytest.mark.parametrize(
"subnet, ip, result",
[
("192.168.1.0/24", "192.168.1.1", True),
("192.168.1.1/32", "192.168.1.1", True),
("192.168.1.1", "192.168.1.1", True),
("192.168.1.0/24", "192.168.66.1", False),
("192.168.0.0/16", "192.168.1.1", True),
],
)
def test_client_ip(rf: RequestFactory, subnet: str, ip: str, result: str) -> None:
request = rf.get("/", REMOTE_ADDR=ip)
with state.configure(request=request):
assert client_ip(subnet) == result
from country_workspace.utils.flags import debug, env_var, header_key, hostname, superuser, validate_bool


@pytest.mark.parametrize(
Expand Down
8 changes: 0 additions & 8 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0cbd87

Please sign in to comment.