Skip to content

Commit

Permalink
test get_group_urls
Browse files Browse the repository at this point in the history
  • Loading branch information
copelco committed Oct 27, 2024
1 parent 32cf120 commit 5bb91fe
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
3 changes: 1 addition & 2 deletions nc/prime_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"nc:arrests-percentage-of-searches-per-stop-purpose",
"nc:arrests-percentage-of-stops-per-contraband-type",
)
DEFAULT_CUTOFF_SECS = 4


def get_agencies_and_officers(by_officer: bool = False):
Expand Down Expand Up @@ -66,7 +65,7 @@ def get_agencies_and_officers(by_officer: bool = False):
return rows


def get_group_urls(agency_id: int, officer_id: int = None):
def get_group_urls(agency_id: int, officer_id: int = None) -> list[str]:
"""Return a list of endpoint URLs for an agency (and optionally an officer)"""
if settings.ALLOWED_HOSTS and settings.ALLOWED_HOSTS[0] != "*":
host = f"https://{settings.ALLOWED_HOSTS[0]}"
Expand Down
36 changes: 19 additions & 17 deletions nc/tests/test_prime_cache.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# from django.test import TestCase
import pytest

# from nc.prime_cache import run
# from nc.tests import factories
from nc import prime_cache


# class PrimeCacheTests(TestCase):
# """
# This merely gives the cache priming code a chance to blow up if silly
# changes are made. No results are verified.
# """
@pytest.fixture(autouse=True)
def group_urls():
"""Monkeypatch API_ENDPOINT_NAMES to return a single group URL for tests"""
prime_cache.API_ENDPOINT_NAMES = ("nc:arrests-percentage-of-stops",)

# databases = "__all__"

# def test_prime_cache(self):
# factories.AgencyFactory(id=-1) # Statewide data
def test_get_group_urls_empty_allowed_hosts(settings):
settings.ALLOWED_HOSTS = []
assert (
prime_cache.get_group_urls(agency_id=99)[0]
== "http://127.0.0.1:8000/api/agency/99/arrests-percentage-of-stops/"
)

# factories.ContrabandFactory()
# factories.ContrabandFactory()
# factories.ContrabandFactory()
# factories.ContrabandFactory()
# factories.ContrabandFactory()
# run()

def test_get_group_urls_allowed_hosts(settings):
settings.ALLOWED_HOSTS = ["nccopwatch.org"]
assert (
prime_cache.get_group_urls(agency_id=99)[0]
== "https://nccopwatch.org/api/agency/99/arrests-percentage-of-stops/"
)
5 changes: 5 additions & 0 deletions requirements/dev/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ cachetools==5.5.0
certifi==2020.6.20
# via
# -c requirements/dev/../base/base.txt
# -c requirements/dev/../test/test.txt
# kubernetes
# requests
cffi==1.17.1
Expand All @@ -60,6 +61,7 @@ cfn-flip==1.3.0
charset-normalizer==3.0.1
# via
# -c requirements/dev/../base/base.txt
# -c requirements/dev/../test/test.txt
# requests
click==8.1.7
# via
Expand Down Expand Up @@ -106,6 +108,7 @@ h11==0.14.0
idna==2.10
# via
# -c requirements/dev/../base/base.txt
# -c requirements/dev/../test/test.txt
# anyio
# requests
imagesize==1.4.1
Expand Down Expand Up @@ -226,6 +229,7 @@ referencing==0.35.1
requests==2.32.3
# via
# -c requirements/dev/../base/base.txt
# -c requirements/dev/../test/test.txt
# kubernetes
# requests-oauthlib
# sphinx
Expand Down Expand Up @@ -317,6 +321,7 @@ typing-extensions==4.12.2
urllib3==2.2.1
# via
# -c requirements/dev/../base/base.txt
# -c requirements/dev/../test/test.txt
# botocore
# kubernetes
# requests
Expand Down
1 change: 1 addition & 0 deletions requirements/test/test.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ isort
pytest
pytest-cov
pytest-django
requests-mock
factory_boy
coverage
# Linting
Expand Down
22 changes: 22 additions & 0 deletions requirements/test/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
#
black==24.10.0
# via -r requirements/test/test.in
certifi==2020.6.20
# via
# -c requirements/test/../base/base.txt
# requests
cfgv==3.4.0
# via pre-commit
charset-normalizer==3.0.1
# via
# -c requirements/test/../base/base.txt
# requests
click==8.1.7
# via
# -c requirements/test/../base/base.txt
Expand All @@ -30,6 +38,10 @@ flake8==7.1.1
# via -r requirements/test/test.in
identify==2.6.1
# via pre-commit
idna==2.10
# via
# -c requirements/test/../base/base.txt
# requests
iniconfig==2.0.0
# via pytest
isort==5.13.2
Expand Down Expand Up @@ -75,6 +87,12 @@ pyyaml==6.0.2
# via
# -r requirements/test/test.in
# pre-commit
requests==2.32.3
# via
# -c requirements/test/../base/base.txt
# requests-mock
requests-mock==1.12.1
# via -r requirements/test/test.in
six==1.15.0
# via
# -c requirements/test/../base/base.txt
Expand All @@ -88,5 +106,9 @@ typing-extensions==4.12.2
# via
# black
# faker
urllib3==2.2.1
# via
# -c requirements/test/../base/base.txt
# requests
virtualenv==20.27.0
# via pre-commit
2 changes: 1 addition & 1 deletion traffic_stops/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

CELERY_ALWAYS_EAGER = True
CELERY_ALWAYS_EAGER = os.getenv("CELERY_ALWAYS_EAGER", "True") == "True"
CELERY_EAGER_PROPAGATES_EXCEPTIONS = True

NC_AUTO_IMPORT_MONITORS = ("nc-monitor@example.com",)
Expand Down

0 comments on commit 5bb91fe

Please sign in to comment.