Skip to content

Commit

Permalink
Merge branch 'develop' into issues/dailyround-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak authored Dec 18, 2024
2 parents 078a876 + 7d3d958 commit a7f5a64
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
restore-keys: |
${{ runner.os }}-buildx-
- name: Create new cache
run: |
mkdir -p /tmp/.buildx-cache-new
- name: Bake docker images
uses: docker/bake-action@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion care/facility/api/viewsets/camera_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_serializer_context(self):

class CameraPresetViewSet(GenericViewSet, ListModelMixin):
serializer_class = CameraPresetSerializer
queryset = CameraPreset.objects.all().select_related(
queryset = CameraPreset.objects.filter(asset_bed__deleted=False).select_related(
"asset_bed", "created_by", "updated_by"
)
lookup_field = "external_id"
Expand Down
1 change: 1 addition & 0 deletions care/facility/api/viewsets/facility_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_queryset(self):
external_id=self.kwargs.get("facility_external_id"),
)
queryset = facility.users.filter(
is_active=True,
deleted=False,
).order_by("-last_login")
return queryset.prefetch_related(
Expand Down
36 changes: 36 additions & 0 deletions care/facility/tests/test_assetbed_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,42 @@ def setUpTestData(cls):
def get_base_url(self, asset_bed_id=None):
return f"/api/v1/assetbed/{asset_bed_id or self.asset_bed1.external_id}/camera_presets/"

def test_list_bed_with_deleted_assetbed(self):
res = self.client.post(
self.get_base_url(self.asset_bed1.external_id),
{
"name": "Preset with proper position",
"position": {
"x": 1.0,
"y": 1.0,
"zoom": 1.0,
},
},
format="json",
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)
res = self.client.post(
self.get_base_url(self.asset_bed2.external_id),
{
"name": "Preset with proper position 2",
"position": {
"x": 1.0,
"y": 1.0,
"zoom": 1.0,
},
},
format="json",
)
self.assertEqual(res.status_code, status.HTTP_201_CREATED)

res = self.client.get(f"/api/v1/bed/{self.bed.external_id}/camera_presets/")
self.assertEqual(len(res.json()["results"]), 2)

self.asset_bed1.delete()
self.asset_bed1.refresh_from_db()
res = self.client.get(f"/api/v1/bed/{self.bed.external_id}/camera_presets/")
self.assertEqual(len(res.json()["results"]), 1)

def test_create_camera_preset_without_position(self):
res = self.client.post(
self.get_base_url(),
Expand Down
23 changes: 23 additions & 0 deletions care/facility/tests/test_facilityuser_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,26 @@ def test_user_access_to_facility_on_user_type(self):
self.client.force_authenticate(user=district_lab_admin)
response = self.client.get(f"/api/v1/facility/{self.facility.external_id}/")
self.assertIs(response.status_code, status.HTTP_200_OK)

def test_user_is_not_listed_if_deleted(self):
# Testing FE's delete functionality (soft delete/is_active is set to false when user is deleted)
response = self.client.get(
f"/api/v1/facility/{self.facility.external_id}/get_users/"
)
response_json = response.json()
results = response_json["results"]
self.assertIs(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(results), 2)
self.assertIn(self.super_user.username, [user["username"] for user in results])
self.assertIn(self.user.username, [user["username"] for user in results])
self.user.is_active = False
self.user.save()
response = self.client.get(
f"/api/v1/facility/{self.facility.external_id}/get_users/"
)
response_json = response.json()
results = response_json["results"]
self.assertIs(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(results), 1)
self.assertIn(self.super_user.username, [user["username"] for user in results])
self.assertNotIn(self.user.username, [user["username"] for user in results])
5 changes: 3 additions & 2 deletions config/settings/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
# django-silk
# ------------------------------------------------------------------------------
# https://github.com/jazzband/django-silk#requirements
INSTALLED_APPS += ["silk"]
MIDDLEWARE += ["silk.middleware.SilkyMiddleware"]
if env("ENABLE_SILK", default=False):
INSTALLED_APPS += ["silk"]
MIDDLEWARE += ["silk.middleware.SilkyMiddleware"]
# https://github.com/jazzband/django-silk#profiling
SILKY_PYTHON_PROFILER = True

Expand Down
3 changes: 2 additions & 1 deletion docker/.local.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ DATABASE_URL=postgres://postgres:postgres@db:5432/care
REDIS_URL=redis://redis:6379
CELERY_BROKER_URL=redis://redis:6379/0

DJANGO_DEBUG=False
DJANGO_DEBUG=true
ATTACH_DEBUGGER=false

BUCKET_REGION=ap-south-1
BUCKET_KEY=key
Expand Down
4 changes: 2 additions & 2 deletions docker/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ RUN ARCH=$(dpkg --print-architecture) && \
rm -rf typst.tar.xz typst-${TYPST_ARCH}

# use pipenv to manage virtualenv
RUN pip install pipenv==2024.4.0

RUN python -m venv /.venv
RUN --mount=type=cache,target=/root/.cache/pip pip install pipenv==2024.4.0

COPY Pipfile Pipfile.lock $APP_HOME/
RUN --mount=type=cache,target=/root/.cache/pip pipenv install --system --categories "packages dev-packages docs"

Expand Down
6 changes: 3 additions & 3 deletions scripts/start-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ python manage.py collectstatic --noinput
python manage.py compilemessages -v 0

echo "starting server..."
if [[ "${DJANGO_DEBUG,,}" == "true" ]]; then
if [[ "${ATTACH_DEBUGGER}" == "true" ]]; then
echo "waiting for debugger..."
python -m debugpy --wait-for-client --listen 0.0.0.0:9876 manage.py runserver_plus 0.0.0.0:9000
python -m debugpy --wait-for-client --listen 0.0.0.0:9876 manage.py runserver_plus 0.0.0.0:9000 --print-sql
else
python manage.py runserver 0.0.0.0:9000
python manage.py runserver_plus 0.0.0.0:9000 --print-sql
fi

0 comments on commit a7f5a64

Please sign in to comment.