From b02c77dd050075034b34d376e3670e2eddbc07c9 Mon Sep 17 00:00:00 2001 From: Prafful Date: Wed, 4 Dec 2024 20:08:42 +0530 Subject: [PATCH 01/25] added workflows and tests --- .github/workflows/test-plugin-integration.yml | 35 +++++++++++ {tests => camera/tests}/__init__.py | 0 .../tests}/test_camera_preset_apis.py | 58 ++++++++++++++++++- tests/test_onvif_validations.py | 52 ----------------- 4 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 .github/workflows/test-plugin-integration.yml rename {tests => camera/tests}/__init__.py (100%) rename {tests => camera/tests}/test_camera_preset_apis.py (67%) delete mode 100644 tests/test_onvif_validations.py diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml new file mode 100644 index 0000000..f5d129b --- /dev/null +++ b/.github/workflows/test-plugin-integration.yml @@ -0,0 +1,35 @@ +name: Run Tests with Docker + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - name: Checkout code + uses: actions/checkout@v3 + + # Modify ADDITIONAL_PLUGS in .local.env + - name: Update ADDITIONAL_PLUGS in .local.env + run: | + sed -i '/^ADDITIONAL_PLUGS=/c\ADDITIONAL_PLUGS=[{\"name\": \"camera\", \"package_name\": \"git+https://github.com/ohcnetwork/care_camera_asset.git\", \"version\": \"@main\", \"configs\": {}}]' ./docker/.local.env + + # Build and start containers + - name: Build and start Docker containers + run: | + make up docker_config_file='docker-compose.local.yaml' + + # Run tests using `make test` + - name: Run `make test` + run: make test + + # Run Django management command tests + - name: Run Django management command tests + run: | + docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" diff --git a/tests/__init__.py b/camera/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to camera/tests/__init__.py diff --git a/tests/test_camera_preset_apis.py b/camera/tests/test_camera_preset_apis.py similarity index 67% rename from tests/test_camera_preset_apis.py rename to camera/tests/test_camera_preset_apis.py index 8de1f4b..4492c32 100644 --- a/tests/test_camera_preset_apis.py +++ b/camera/tests/test_camera_preset_apis.py @@ -3,6 +3,7 @@ from care.utils.tests.test_utils import TestUtils from rest_framework.test import APITestCase from rest_framework import status +from camera.utils.onvif import OnvifAsset class AssetBedCameraPresetViewSetTestCase(TestUtils, APITestCase): @@ -30,7 +31,7 @@ def setUpTestData(cls): cls.asset_bed2 = cls.create_assetbed(cls.bed, cls.asset2) def get_base_url(self, asset_bed_id=None): - return f"/api/camera/assetbed/position_presets/?assetbed_external_id={asset_bed_id or self.asset_bed1.external_id}" + return f"/api/camera/position-presets/?assetbed_external_id={asset_bed_id or self.asset_bed1.external_id}" def test_create_camera_preset_without_position(self): res = self.client.post( @@ -108,14 +109,14 @@ def test_create_camera_preset_and_presence_in_various_preset_list_apis(self): # Check if preset in asset preset list res = self.client.get( - f"/api/camera/position_presets/?asset_external_id={asset_bed.asset.external_id}" + f"/api/camera/position-presets/?asset_external_id={asset_bed.asset.external_id}" ) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertContains(res, preset_external_id) # Check if preset in bed preset list res = self.client.get( - f"/api/camera/position_presets/?bed_external_id={asset_bed.bed.external_id}" + f"/api/camera/position-presets/?bed_external_id={asset_bed.bed.external_id}" ) self.assertEqual(res.status_code, status.HTTP_200_OK) self.assertContains(res, preset_external_id) @@ -136,3 +137,54 @@ def test_create_camera_preset_with_same_name_in_same_bed(self): self.get_base_url(self.asset_bed2.external_id), data, format="json" ) self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) + + + def test_meta_validations_for_onvif_asset(self): + valid_meta = { + "local_ip_address": "192.168.0.1", + "camera_access_key": "username:password:access_key", + "middleware_hostname": "middleware.local", + "insecure_connection": True, + } + onvif_asset = OnvifAsset(valid_meta) + self.assertEqual(onvif_asset.middleware_hostname, "middleware.local") + self.assertEqual(onvif_asset.host, "192.168.0.1") + self.assertEqual(onvif_asset.username, "username") + self.assertEqual(onvif_asset.password, "password") + self.assertEqual(onvif_asset.access_key, "access_key") + self.assertTrue(onvif_asset.insecure_connection) + + invalid_meta_cases = [ + # Invalid format for camera_access_key + { + "id": "123", + "local_ip_address": "192.168.0.1", + "middleware_hostname": "middleware.local", + "camera_access_key": "invalid_format", + }, + # Missing username/password in camera_access_key + { + "local_ip_address": "192.168.0.1", + "middleware_hostname": "middleware.local", + "camera_access_key": "invalid_format", + }, + # Missing middleware_hostname + { + "local_ip_address": "192.168.0.1", + "camera_access_key": "username:password:access_key", + }, + # Missing local_ip_address + { + "middleware_hostname": "middleware.local", + "camera_access_key": "username:password:access_key", + }, + # Invalid value for insecure_connection + { + "local_ip_address": "192.168.0.1", + "camera_access_key": "username:password:access_key", + "middleware_hostname": "middleware.local", + "insecure_connection": "invalid_value", + }, + ] + for meta in invalid_meta_cases: + self.validate_invalid_meta(OnvifAsset, meta) diff --git a/tests/test_onvif_validations.py b/tests/test_onvif_validations.py deleted file mode 100644 index 2ac7329..0000000 --- a/tests/test_onvif_validations.py +++ /dev/null @@ -1,52 +0,0 @@ -from camera.utils.onvif import OnvifAsset - - -def test_meta_validations_for_onvif_asset(self): - valid_meta = { - "local_ip_address": "192.168.0.1", - "camera_access_key": "username:password:access_key", - "middleware_hostname": "middleware.local", - "insecure_connection": True, - } - onvif_asset = OnvifAsset(valid_meta) - self.assertEqual(onvif_asset.middleware_hostname, "middleware.local") - self.assertEqual(onvif_asset.host, "192.168.0.1") - self.assertEqual(onvif_asset.username, "username") - self.assertEqual(onvif_asset.password, "password") - self.assertEqual(onvif_asset.access_key, "access_key") - self.assertTrue(onvif_asset.insecure_connection) - - invalid_meta_cases = [ - # Invalid format for camera_access_key - { - "id": "123", - "local_ip_address": "192.168.0.1", - "middleware_hostname": "middleware.local", - "camera_access_key": "invalid_format", - }, - # Missing username/password in camera_access_key - { - "local_ip_address": "192.168.0.1", - "middleware_hostname": "middleware.local", - "camera_access_key": "invalid_format", - }, - # Missing middleware_hostname - { - "local_ip_address": "192.168.0.1", - "camera_access_key": "username:password:access_key", - }, - # Missing local_ip_address - { - "middleware_hostname": "middleware.local", - "camera_access_key": "username:password:access_key", - }, - # Invalid value for insecure_connection - { - "local_ip_address": "192.168.0.1", - "camera_access_key": "username:password:access_key", - "middleware_hostname": "middleware.local", - "insecure_connection": "invalid_value", - }, - ] - for meta in invalid_meta_cases: - self.validate_invalid_meta(OnvifAsset, meta) From 6617db45cf1bbff2cd0ef0f7160955e848589935 Mon Sep 17 00:00:00 2001 From: Prafful Date: Wed, 4 Dec 2024 20:08:56 +0530 Subject: [PATCH 02/25] added workflows and tests2 --- .github/workflows/test-plugin-integration.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index f5d129b..c744b1f 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -23,11 +23,11 @@ jobs: # Build and start containers - name: Build and start Docker containers run: | - make up docker_config_file='docker-compose.local.yaml' + make up - # Run tests using `make test` - - name: Run `make test` - run: make test + # # Run tests using `make test` + # - name: Run `make test` + # run: make test # Run Django management command tests - name: Run Django management command tests From 0e5da56c898ba6627d8b57a5f50b9fd984d76269 Mon Sep 17 00:00:00 2001 From: Prafful Date: Wed, 4 Dec 2024 20:13:05 +0530 Subject: [PATCH 03/25] fix workflows --- .github/workflows/test-plugin-integration.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index c744b1f..5c09042 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -11,9 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout the repository - - name: Checkout code + # Clone the ohcnetwork/care repository + - name: Checkout ohcnetwork/care uses: actions/checkout@v3 + with: + repository: ohcnetwork/care # Modify ADDITIONAL_PLUGS in .local.env - name: Update ADDITIONAL_PLUGS in .local.env @@ -25,9 +27,9 @@ jobs: run: | make up - # # Run tests using `make test` - # - name: Run `make test` - # run: make test + # Run tests using `make test` + - name: Run `make test` + run: make test # Run Django management command tests - name: Run Django management command tests From dae2cc11881a8d3482786a1e7a6c9e38b9e09c8d Mon Sep 17 00:00:00 2001 From: Prafful Date: Wed, 4 Dec 2024 21:06:27 +0530 Subject: [PATCH 04/25] fix workflows 2 --- .github/workflows/test-plugin-integration.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 5c09042..13ef7c9 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -16,11 +16,14 @@ jobs: uses: actions/checkout@v3 with: repository: ohcnetwork/care + ref: # Modify ADDITIONAL_PLUGS in .local.env - name: Update ADDITIONAL_PLUGS in .local.env run: | - sed -i '/^ADDITIONAL_PLUGS=/c\ADDITIONAL_PLUGS=[{\"name\": \"camera\", \"package_name\": \"git+https://github.com/ohcnetwork/care_camera_asset.git\", \"version\": \"@main\", \"configs\": {}}]' ./docker/.local.env + branch_name=$(echo $GITHUB_REF_NAME) + sed -i '/^ADDITIONAL_PLUGS=/c\ADDITIONAL_PLUGS=[{"name": "camera", "package_name": "git+https://github.com/ohcnetwork/care_camera_asset.git", "version": "@$branch_name", "configs": {}}]' ./docker/.local.env + # Build and start containers - name: Build and start Docker containers From 1042ac3bf99bf8a73bdc2a0f0c071ed283ed43e6 Mon Sep 17 00:00:00 2001 From: Prafful Date: Wed, 4 Dec 2024 23:47:09 +0530 Subject: [PATCH 05/25] fix workflows 3 --- .github/workflows/test-plugin-integration.yml | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 13ef7c9..aee9410 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -11,25 +11,35 @@ jobs: runs-on: ubuntu-latest steps: - # Clone the ohcnetwork/care repository - - name: Checkout ohcnetwork/care + # Checkout the DraKen0009/care repository + - name: Checkout DraKen0009/care repository uses: actions/checkout@v3 with: - repository: ohcnetwork/care - ref: + repository: DraKen0009/care + ref: adding-camera-plugin - # Modify ADDITIONAL_PLUGS in .local.env - - name: Update ADDITIONAL_PLUGS in .local.env + # Update or Add ADDITIONAL_PLUGS in .local.env + - name: Update or Add ADDITIONAL_PLUGS in .local.env run: | - branch_name=$(echo $GITHUB_REF_NAME) - sed -i '/^ADDITIONAL_PLUGS=/c\ADDITIONAL_PLUGS=[{"name": "camera", "package_name": "git+https://github.com/ohcnetwork/care_camera_asset.git", "version": "@$branch_name", "configs": {}}]' ./docker/.local.env - - - # Build and start containers + branch_name=$(echo "$GITHUB_REF_NAME") + if grep -q "^ADDITIONAL_PLUGS=" ./docker/.local.env; then + # Replace the existing ADDITIONAL_PLUGS line + sed -i "s|^ADDITIONAL_PLUGS=.*|ADDITIONAL_PLUGS=[{\"name\": \"camera\", \"package_name\": \"git+https://github.com/DraKen0009/care_camera_asset.git\", \"version\": \"@$branch_name\", \"configs\": {}}]|" ./docker/.local.env + else + # Append the ADDITIONAL_PLUGS line + echo "ADDITIONAL_PLUGS=[{\"name\": \"camera\", \"package_name\": \"git+https://github.com/DraKen0009/care_camera_asset.git\", \"version\": \"@$branch_name\", \"configs\": {}}]" >> ./docker/.local.env + fi + + # Build and start Docker containers - name: Build and start Docker containers run: | make up + # Install plugins inside the backend container + - name: Run install_plugins.py + run: | + docker compose exec backend bash -c "python install_plugins.py" + # Run tests using `make test` - name: Run `make test` run: make test From 354d69fad229ac48514cf042fd34ab4adb2c4dbe Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 01:25:54 +0530 Subject: [PATCH 06/25] fix workflows 4 --- .github/workflows/test-plugin-integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index aee9410..7a96539 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v3 with: repository: DraKen0009/care - ref: adding-camera-plugin + ref: testing-for-workflows # Update or Add ADDITIONAL_PLUGS in .local.env - name: Update or Add ADDITIONAL_PLUGS in .local.env @@ -41,8 +41,8 @@ jobs: docker compose exec backend bash -c "python install_plugins.py" # Run tests using `make test` - - name: Run `make test` - run: make test + # - name: Run `make test` + # run: make test # Run Django management command tests - name: Run Django management command tests From fdab8310d5081e351b21a79b670cc3dd5eea38a1 Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 03:18:45 +0530 Subject: [PATCH 07/25] fixed tests and fixed migrations --- camera/migrations/0001_initial.py | 6 ++--- ...121_1505.py => 0002_auto_20241206_0242.py} | 5 ++-- ...er_positionpreset_created_date_and_more.py | 23 +++++++++++++++++++ camera/tests/test_camera_preset_apis.py | 5 ++++ 4 files changed, 34 insertions(+), 5 deletions(-) rename camera/migrations/{0002_auto_20241121_1505.py => 0002_auto_20241206_0242.py} (88%) create mode 100644 camera/migrations/0003_alter_positionpreset_created_date_and_more.py diff --git a/camera/migrations/0001_initial.py b/camera/migrations/0001_initial.py index 17690ec..0d4b746 100644 --- a/camera/migrations/0001_initial.py +++ b/camera/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2024-11-21 09:35 +# Generated by Django 5.1.3 on 2024-12-05 21:12 import care.utils.models.validators import django.db.models.deletion @@ -22,12 +22,12 @@ class Migration(migrations.Migration): fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('external_id', models.UUIDField(db_index=True, default=uuid.uuid4, unique=True)), - ('created_date', models.DateTimeField(auto_now_add=True, db_index=True, null=True)), - ('modified_date', models.DateTimeField(auto_now=True, db_index=True, null=True)), ('deleted', models.BooleanField(db_index=True, default=False)), ('name', models.CharField(max_length=255, null=True)), ('position', models.JSONField(validators=[care.utils.models.validators.JSONFieldSchemaValidator({'$schema': 'http://json-schema.org/draft-07/schema#', 'additionalProperties': False, 'properties': {'x': {'type': 'number'}, 'y': {'type': 'number'}, 'zoom': {'type': 'number'}}, 'required': ['x', 'y', 'zoom'], 'type': 'object'})])), ('is_migrated', models.BooleanField(default=False)), + ('created_date', models.DateTimeField()), + ('modified_date', models.DateTimeField()), ('asset_bed', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='camera_position_presets', to='facility.assetbed')), ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)), ('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to=settings.AUTH_USER_MODEL)), diff --git a/camera/migrations/0002_auto_20241121_1505.py b/camera/migrations/0002_auto_20241206_0242.py similarity index 88% rename from camera/migrations/0002_auto_20241121_1505.py rename to camera/migrations/0002_auto_20241206_0242.py index 856347f..83eba7e 100644 --- a/camera/migrations/0002_auto_20241121_1505.py +++ b/camera/migrations/0002_auto_20241206_0242.py @@ -1,8 +1,7 @@ -# Generated by Django 5.1.2 on 2024-11-21 09:35 +# Generated by Django 5.1.3 on 2024-12-05 21:12 from django.db import migrations - def migrate_camera_preset_to_position_preset(apps, schema_editor): try: CameraPreset = apps.get_model("facility", "CameraPreset") @@ -23,6 +22,8 @@ def migrate_camera_preset_to_position_preset(apps, schema_editor): created_by=preset.created_by, updated_by=preset.updated_by, is_migrated=preset.is_migrated, + created_date=preset.created_date, + modified_date=preset.modified_date ) for preset in camera_presets ] diff --git a/camera/migrations/0003_alter_positionpreset_created_date_and_more.py b/camera/migrations/0003_alter_positionpreset_created_date_and_more.py new file mode 100644 index 0000000..857cba7 --- /dev/null +++ b/camera/migrations/0003_alter_positionpreset_created_date_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 5.1.3 on 2024-12-05 21:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('camera', '0002_auto_20241206_0242'), + ] + + operations = [ + migrations.AlterField( + model_name='positionpreset', + name='created_date', + field=models.DateTimeField(auto_now_add=True, db_index=True, null=True), + ), + migrations.AlterField( + model_name='positionpreset', + name='modified_date', + field=models.DateTimeField(auto_now=True, db_index=True, null=True), + ), + ] diff --git a/camera/tests/test_camera_preset_apis.py b/camera/tests/test_camera_preset_apis.py index 4492c32..832c5ef 100644 --- a/camera/tests/test_camera_preset_apis.py +++ b/camera/tests/test_camera_preset_apis.py @@ -3,6 +3,7 @@ from care.utils.tests.test_utils import TestUtils from rest_framework.test import APITestCase from rest_framework import status +from rest_framework.exceptions import ValidationError from camera.utils.onvif import OnvifAsset @@ -33,6 +34,10 @@ def setUpTestData(cls): def get_base_url(self, asset_bed_id=None): return f"/api/camera/position-presets/?assetbed_external_id={asset_bed_id or self.asset_bed1.external_id}" + def validate_invalid_meta(self, asset_class, meta): + with self.assertRaises(ValidationError): + asset_class(meta) + def test_create_camera_preset_without_position(self): res = self.client.post( self.get_base_url(), From ee707c5fd49282fa0d511ca28d56a7f06a1afc1b Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 17:30:19 +0530 Subject: [PATCH 08/25] fixing workflows 5 --- .github/workflows/test-plugin-integration.yml | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 7a96539..e4d7ee3 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -12,23 +12,11 @@ jobs: steps: # Checkout the DraKen0009/care repository - - name: Checkout DraKen0009/care repository + - name: Checkout ohcnetwork/care repository uses: actions/checkout@v3 with: - repository: DraKen0009/care - ref: testing-for-workflows - - # Update or Add ADDITIONAL_PLUGS in .local.env - - name: Update or Add ADDITIONAL_PLUGS in .local.env - run: | - branch_name=$(echo "$GITHUB_REF_NAME") - if grep -q "^ADDITIONAL_PLUGS=" ./docker/.local.env; then - # Replace the existing ADDITIONAL_PLUGS line - sed -i "s|^ADDITIONAL_PLUGS=.*|ADDITIONAL_PLUGS=[{\"name\": \"camera\", \"package_name\": \"git+https://github.com/DraKen0009/care_camera_asset.git\", \"version\": \"@$branch_name\", \"configs\": {}}]|" ./docker/.local.env - else - # Append the ADDITIONAL_PLUGS line - echo "ADDITIONAL_PLUGS=[{\"name\": \"camera\", \"package_name\": \"git+https://github.com/DraKen0009/care_camera_asset.git\", \"version\": \"@$branch_name\", \"configs\": {}}]" >> ./docker/.local.env - fi + repository: ohcnetwork/care + ref: adding-camera-plugin # Build and start Docker containers - name: Build and start Docker containers @@ -40,9 +28,9 @@ jobs: run: | docker compose exec backend bash -c "python install_plugins.py" - # Run tests using `make test` - # - name: Run `make test` - # run: make test + Run tests using `make test` + - name: Run `make test` + run: make test # Run Django management command tests - name: Run Django management command tests From ddba8451ba1fba142191729a8fb715968401105b Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 17:31:17 +0530 Subject: [PATCH 09/25] fixing workflows 6 --- .github/workflows/test-plugin-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index e4d7ee3..4184771 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -28,7 +28,7 @@ jobs: run: | docker compose exec backend bash -c "python install_plugins.py" - Run tests using `make test` + # Run tests using `make test` - name: Run `make test` run: make test From 1813d209391551834b46c7b6f03a9ee289f620bb Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 17:38:47 +0530 Subject: [PATCH 10/25] fixing workflows 7 --- .github/workflows/test-plugin-integration.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 4184771..b05fe54 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -12,12 +12,13 @@ jobs: steps: # Checkout the DraKen0009/care repository - - name: Checkout ohcnetwork/care repository + - name: Checkout DraKen0009/care repository uses: actions/checkout@v3 with: - repository: ohcnetwork/care + repository: DraKen0009/care ref: adding-camera-plugin + # Build and start Docker containers - name: Build and start Docker containers run: | @@ -29,8 +30,8 @@ jobs: docker compose exec backend bash -c "python install_plugins.py" # Run tests using `make test` - - name: Run `make test` - run: make test + # - name: Run `make test` + # run: make test # Run Django management command tests - name: Run Django management command tests From 564ee30a8978c5301f3a95cd0e3d76a078fa7773 Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 20:13:39 +0530 Subject: [PATCH 11/25] fixing workflows 8 --- .github/workflows/test-plugin-integration.yml | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index b05fe54..9e5a460 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -15,23 +15,30 @@ jobs: - name: Checkout DraKen0009/care repository uses: actions/checkout@v3 with: - repository: DraKen0009/care - ref: adding-camera-plugin + repository: ohcnetwork/care + # Update the plug_config.py file with the required content + - name: Update plug_config.py + run: | + branch_name=$(echo "$GITHUB_REF_NAME") + echo "from plugs.manager import PlugManager +from plugs.plug import Plug + +camera_plugin = Plug( + name=\"camera\", + package_name=\"git+https://github.com/ohcnetwork/care_camera_asset.git\", + version=\"@$branch_name\", + configs={}, +) + +plugs = [camera_plugin] + +manager = PlugManager(plugs)" > ./plug_config.py # Build and start Docker containers - name: Build and start Docker containers run: | - make up - - # Install plugins inside the backend container - - name: Run install_plugins.py - run: | - docker compose exec backend bash -c "python install_plugins.py" - - # Run tests using `make test` - # - name: Run `make test` - # run: make test + make up # Run Django management command tests - name: Run Django management command tests From df66b07465051c3ac3499ca9e128acbaaa2e6c3d Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 20:15:40 +0530 Subject: [PATCH 12/25] fixing workflows 9 --- .github/workflows/test-plugin-integration.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 9e5a460..e093fec 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -11,8 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout the DraKen0009/care repository - - name: Checkout DraKen0009/care repository + # Checkout the ohcnetwork/care repository + - name: Checkout ohcnetwork/care repository uses: actions/checkout@v3 with: repository: ohcnetwork/care @@ -20,20 +20,22 @@ jobs: # Update the plug_config.py file with the required content - name: Update plug_config.py run: | - branch_name=$(echo "$GITHUB_REF_NAME") - echo "from plugs.manager import PlugManager + branch_name=${GITHUB_REF_NAME} + cat > ./plug_config.py < ./plug_config.py +manager = PlugManager(plugs) +EOL # Build and start Docker containers - name: Build and start Docker containers From 9d4eef1d7389ce3dca8820fc6b827c41004dd92c Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 20:17:13 +0530 Subject: [PATCH 13/25] fixing workflows 10 --- .github/workflows/test-plugin-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index e093fec..10102b0 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -21,7 +21,7 @@ jobs: - name: Update plug_config.py run: | branch_name=${GITHUB_REF_NAME} - cat > ./plug_config.py < ./plug_config.py << 'EOL' from plugs.manager import PlugManager from plugs.plug import Plug From fca599c5caa8b2a0bed6055a10b01f71c281f40e Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 20:18:36 +0530 Subject: [PATCH 14/25] fixing workflows 11 --- .github/workflows/test-plugin-integration.yml | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 10102b0..5a647d5 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -9,7 +9,6 @@ on: jobs: test: runs-on: ubuntu-latest - steps: # Checkout the ohcnetwork/care repository - name: Checkout ohcnetwork/care repository @@ -22,27 +21,24 @@ jobs: run: | branch_name=${GITHUB_REF_NAME} cat > ./plug_config.py << 'EOL' -from plugs.manager import PlugManager -from plugs.plug import Plug - -camera_plugin = Plug( - name="camera", - package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - version="@${branch_name}", - configs={}, -) - -plugs = [camera_plugin] - -manager = PlugManager(plugs) -EOL + from plugs.manager import PlugManager + from plugs.plug import Plug + camera_plugin = Plug( + name="camera", + package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", + version="@${branch_name}", + configs={}, + ) + plugs = [camera_plugin] + manager = PlugManager(plugs) + EOL # Build and start Docker containers - name: Build and start Docker containers run: | - make up + make up # Run Django management command tests - name: Run Django management command tests run: | - docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" + docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" \ No newline at end of file From 710403a52d9357e0d2b73fe23d4bfcdf9b5e730a Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 20:24:20 +0530 Subject: [PATCH 15/25] fixing workflows 12 --- .github/workflows/test-plugin-integration.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 5a647d5..e6ccdab 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -18,15 +18,16 @@ jobs: # Update the plug_config.py file with the required content - name: Update plug_config.py + env: + BRANCH_NAME: ${{ github.ref_name }} run: | - branch_name=${GITHUB_REF_NAME} cat > ./plug_config.py << 'EOL' from plugs.manager import PlugManager from plugs.plug import Plug camera_plugin = Plug( name="camera", package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - version="@${branch_name}", + version="@${BRANCH_NAME}", configs={}, ) plugs = [camera_plugin] From 956e0f4384c98bdb9aed6cd0ce2ca230877b5e84 Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 22:15:05 +0530 Subject: [PATCH 16/25] fixing workflows 13 --- .github/workflows/test-plugin-integration.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index e6ccdab..81576e5 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -18,8 +18,6 @@ jobs: # Update the plug_config.py file with the required content - name: Update plug_config.py - env: - BRANCH_NAME: ${{ github.ref_name }} run: | cat > ./plug_config.py << 'EOL' from plugs.manager import PlugManager @@ -27,7 +25,7 @@ jobs: camera_plugin = Plug( name="camera", package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - version="@${BRANCH_NAME}", + version="${{ github.ref_name }}" configs={}, ) plugs = [camera_plugin] From 7af33e39bd96b35adf0e56a870b082b1e28dfd1c Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 22:23:17 +0530 Subject: [PATCH 17/25] fixing workflows 14 --- .github/workflows/test-plugin-integration.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 81576e5..ddf0067 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -19,13 +19,14 @@ jobs: # Update the plug_config.py file with the required content - name: Update plug_config.py run: | + branch_name=$(basename ${{ github.ref }}) cat > ./plug_config.py << 'EOL' from plugs.manager import PlugManager from plugs.plug import Plug camera_plugin = Plug( name="camera", package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - version="${{ github.ref_name }}" + version="@${branch_name}" configs={}, ) plugs = [camera_plugin] From a3170157bf037b7baf6aa01dcf23622f70180134 Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 22:44:54 +0530 Subject: [PATCH 18/25] fixing workflows 15 --- .github/workflows/test-plugin-integration.yml | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index ddf0067..b14ddb6 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -10,35 +10,41 @@ jobs: test: runs-on: ubuntu-latest steps: - # Checkout the ohcnetwork/care repository - - name: Checkout ohcnetwork/care repository - uses: actions/checkout@v3 - with: - repository: ohcnetwork/care - - # Update the plug_config.py file with the required content - - name: Update plug_config.py + - name: Print branch name + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} run: | - branch_name=$(basename ${{ github.ref }}) - cat > ./plug_config.py << 'EOL' - from plugs.manager import PlugManager - from plugs.plug import Plug - camera_plugin = Plug( - name="camera", - package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - version="@${branch_name}" - configs={}, - ) - plugs = [camera_plugin] - manager = PlugManager(plugs) - EOL + echo "Branch name: $BRANCH_NAME" + shell: bash + # # Checkout the ohcnetwork/care repository + # - name: Checkout ohcnetwork/care repository + # uses: actions/checkout@v3 + # with: + # repository: ohcnetwork/care - # Build and start Docker containers - - name: Build and start Docker containers - run: | - make up + # # Update the plug_config.py file with the required content + # - name: Update plug_config.py + # run: | + # branch_name=$(basename ${{ github.ref }}) + # cat > ./plug_config.py << 'EOL' + # from plugs.manager import PlugManager + # from plugs.plug import Plug + # camera_plugin = Plug( + # name="camera", + # package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", + # version="@${branch_name}" + # configs={}, + # ) + # plugs = [camera_plugin] + # manager = PlugManager(plugs) + # EOL - # Run Django management command tests - - name: Run Django management command tests - run: | - docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" \ No newline at end of file + # # Build and start Docker containers + # - name: Build and start Docker containers + # run: | + # make up + + # # Run Django management command tests + # - name: Run Django management command tests + # run: | + # docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" \ No newline at end of file From 43c3b4ebcfce3a3776a487e8f74eb6b33a63f258 Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 22:50:32 +0530 Subject: [PATCH 19/25] fixing workflows 16 --- .github/workflows/test-plugin-integration.yml | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index b14ddb6..037809b 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -16,35 +16,37 @@ jobs: run: | echo "Branch name: $BRANCH_NAME" shell: bash - # # Checkout the ohcnetwork/care repository - # - name: Checkout ohcnetwork/care repository - # uses: actions/checkout@v3 - # with: - # repository: ohcnetwork/care - # # Update the plug_config.py file with the required content - # - name: Update plug_config.py - # run: | - # branch_name=$(basename ${{ github.ref }}) - # cat > ./plug_config.py << 'EOL' - # from plugs.manager import PlugManager - # from plugs.plug import Plug - # camera_plugin = Plug( - # name="camera", - # package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - # version="@${branch_name}" - # configs={}, - # ) - # plugs = [camera_plugin] - # manager = PlugManager(plugs) - # EOL + # Checkout the ohcnetwork/care repository + - name: Checkout ohcnetwork/care repository + uses: actions/checkout@v3 + with: + repository: ohcnetwork/care - # # Build and start Docker containers - # - name: Build and start Docker containers - # run: | - # make up + # Update the plug_config.py file with the required content + - name: Update plug_config.py + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + run: | + cat > ./plug_config.py << 'EOL' + from plugs.manager import PlugManager + from plugs.plug import Plug + camera_plugin = Plug( + name="camera", + package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", + version="@$BRANCH_NAME" + configs={}, + ) + plugs = [camera_plugin] + manager = PlugManager(plugs) + EOL - # # Run Django management command tests - # - name: Run Django management command tests - # run: | - # docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" \ No newline at end of file + # Build and start Docker containers + - name: Build and start Docker containers + run: | + make up + + # Run Django management command tests + - name: Run Django management command tests + run: | + docker compose exec backend bash -c "python manage.py test camera --keepdb --parallel --shuffle" \ No newline at end of file From 0219ed07c1d82099def6f145e9c9bc9fb175352a Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 22:58:38 +0530 Subject: [PATCH 20/25] fixing workflows 17 --- .github/workflows/test-plugin-integration.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 037809b..a0ca8e4 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -25,8 +25,6 @@ jobs: # Update the plug_config.py file with the required content - name: Update plug_config.py - env: - BRANCH_NAME: ${{ github.head_ref || github.ref_name }} run: | cat > ./plug_config.py << 'EOL' from plugs.manager import PlugManager @@ -34,7 +32,7 @@ jobs: camera_plugin = Plug( name="camera", package_name="git+https://github.com/ohcnetwork/care_camera_asset.git", - version="@$BRANCH_NAME" + version="@{{ github.head_ref || github.ref_name }}" configs={}, ) plugs = [camera_plugin] From b220d60845fb4e395f106742a87f3ab653120f3d Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 23:02:05 +0530 Subject: [PATCH 21/25] fixing workflows 18 --- .github/workflows/test-plugin-integration.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index a0ca8e4..0d1a604 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -25,16 +25,20 @@ jobs: # Update the plug_config.py file with the required content - name: Update plug_config.py + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} run: | - cat > ./plug_config.py << 'EOL' + cat > ./plug_config.py < Date: Fri, 6 Dec 2024 23:08:00 +0530 Subject: [PATCH 22/25] fixing workflows 19 --- setup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 41ec54d..b7bf113 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,9 @@ with open("HISTORY.rst") as history_file: history = history_file.read() -requirements = [] +requirements = [ + "requests" +] test_requirements = [] From 1dfa598aac3295b64f017d2aba6a222dd732db5e Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 23:18:46 +0530 Subject: [PATCH 23/25] fixing workflows 20 --- .github/workflows/test-plugin-integration.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index 0d1a604..d6039e8 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -21,7 +21,9 @@ jobs: - name: Checkout ohcnetwork/care repository uses: actions/checkout@v3 with: - repository: ohcnetwork/care + repository: DraKen0009/care + ref: :adding-camera-plugin + # Update the plug_config.py file with the required content - name: Update plug_config.py From ff48fea69cf3abd04c3fb30b41b509511b1a0ba1 Mon Sep 17 00:00:00 2001 From: Prafful Date: Fri, 6 Dec 2024 23:20:18 +0530 Subject: [PATCH 24/25] fixing workflows 21 --- .github/workflows/test-plugin-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-plugin-integration.yml b/.github/workflows/test-plugin-integration.yml index d6039e8..167714c 100644 --- a/.github/workflows/test-plugin-integration.yml +++ b/.github/workflows/test-plugin-integration.yml @@ -22,7 +22,7 @@ jobs: uses: actions/checkout@v3 with: repository: DraKen0009/care - ref: :adding-camera-plugin + ref: adding-camera-plugin # Update the plug_config.py file with the required content From b34ee6f0e388db5b4ab5ecf5885fc1efaafb81a3 Mon Sep 17 00:00:00 2001 From: Prafful Date: Sun, 15 Dec 2024 20:57:12 +0530 Subject: [PATCH 25/25] fixed changes from main repo for list api fix --- camera/api/viewsets/position_preset.py | 8 ++++-- camera/tests/test_camera_preset_apis.py | 37 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/camera/api/viewsets/position_preset.py b/camera/api/viewsets/position_preset.py index aa3fb4f..a899a45 100644 --- a/camera/api/viewsets/position_preset.py +++ b/camera/api/viewsets/position_preset.py @@ -98,10 +98,14 @@ def get_queryset(self): ) if asset_external_id: return queryset.filter( - asset_bed__asset=self.get_asset_obj(asset_external_id) + asset_bed__asset=self.get_asset_obj(asset_external_id), + asset_bed__deleted=False ) if bed_external_id: - return queryset.filter(asset_bed__bed=self.get_bed_obj(bed_external_id)) + return queryset.filter( + asset_bed__bed=self.get_bed_obj(bed_external_id), + asset_bed__deleted=False + ) if self.kwargs.get("external_id"): return queryset.filter(external_id=self.kwargs.get("external_id")) diff --git a/camera/tests/test_camera_preset_apis.py b/camera/tests/test_camera_preset_apis.py index 832c5ef..abfd5c2 100644 --- a/camera/tests/test_camera_preset_apis.py +++ b/camera/tests/test_camera_preset_apis.py @@ -143,7 +143,42 @@ def test_create_camera_preset_with_same_name_in_same_bed(self): ) self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) - + 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/camera/position-presets/?bed_external_id={self.bed.external_id}") + self.assertEqual(len(res.json()["results"]), 2) + + self.asset_bed1.delete() + self.asset_bed1.refresh_from_db() + res = self.client.get(f"/api/camera/position-presets/?bed_external_id={self.bed.external_id}") + self.assertEqual(len(res.json()["results"]), 1) + def test_meta_validations_for_onvif_asset(self): valid_meta = { "local_ip_address": "192.168.0.1",