Skip to content

Commit

Permalink
Merge pull request #4166 from unicef/develop
Browse files Browse the repository at this point in the history
Staging 2.11.0
  • Loading branch information
johniak authored Aug 27, 2024
2 parents 956e5a2 + 0b67845 commit 409656e
Show file tree
Hide file tree
Showing 315 changed files with 13,714 additions and 2,931 deletions.
41 changes: 36 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,30 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Determine Branch Name
id: branch_name
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
fi
- name: Push dev
run: |
docker buildx create --use
tags="-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}-dev \
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-latest-dev"
if [ -n "${{ env.BRANCH_NAME }}" ]; then
tags="$tags -t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ env.BRANCH_NAME }}-latest-dev"
fi
docker buildx build \
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-${{ github.sha }}-dev \
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-latest-dev \
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-${{ github.sha }}-dev \
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-latest-dev \
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}-dev \
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-latest-dev \
$tags \
-f ./docker/Dockerfile \
--target dev \
--push \
Expand Down Expand Up @@ -160,10 +174,24 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Determine Branch Name
id: branch_name
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
fi
- name: Push dist
run: |
docker buildx create --use
tags="-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}-dist \
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}"
if [ -n "${{ env.BRANCH_NAME }}" ]; then
tags="$tags -t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ env.BRANCH_NAME }}-latest-dist"
fi
# Base part of the command
build_command="docker buildx build \
--progress=plain \
Expand All @@ -173,8 +201,7 @@ jobs:
--cache-from ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-latest-dist \
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-${{ github.sha }}-dist \
--cache-to ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:cache-core-latest-dist \
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}-dist \
-t ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }} \
$tags \
-f ./docker/Dockerfile \
--target dist \
--push ./"
Expand Down Expand Up @@ -226,8 +253,12 @@ jobs:

- name: E2E tests
run: |
compose_file=./deployment/docker-compose.selenium-night.yml
if [ "${{ github.event_name }}" = "pull_request" ]; then
compose_file=./deployment/docker-compose.selenium.yml
fi
dist_backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}-dist dev_backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-${{ github.sha }}-dev docker compose \
-f ./deployment/docker-compose.selenium.yml \
-f $compose_file \
run selenium
- name: Upload Artifact
uses: actions/upload-artifact@v4
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Nightly E2E Tests

on:
workflow_dispatch:
schedule:
# Run at 2:00 AM every day
- cron: '0 2 * * *'

jobs:
e2e_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: DockerHub login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Pull Latest Docker Images
run: |
docker pull ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-develop-latest-dist
docker pull ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-develop-latest-dev
- name: Run Selenium Nightly E2E tests
run: |
dist_backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-develop-latest-dist \
dev_backend_image=${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images:core-develop-latest-dev \
docker compose \
-f ./deployment/docker-compose.selenium-night.yml \
run selenium
- name: Upload Nightly Test Artifacts
uses: actions/upload-artifact@v4
if: always()
continue-on-error: true
with:
name: nightly-e2e-report
path: ./backend/report/
retention-days: 5

- name: Upload Nightly Coverage to Codecov
uses: codecov/codecov-action@v4
if: always()
continue-on-error: true
with:
files: ./backend/coverage.xml
flags: nightly-e2e
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
15 changes: 8 additions & 7 deletions backend/.coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ concurrency=multiprocessing,thread
omit =
*/selenium_tests/**
*/tests/**
*/migrations/*,
*/apps.py,
*/migrations/*
*/apps.py
*/admin/*.py
*/admin.py
hct_mis_api/one_time_scripts/*,
hct_mis_api/libs/*,
hct_mis_api/settings/*,
hct_mis_api/settings.py,
hct_mis_api/conftest.py,
**/fixtures.py
hct_mis_api/one_time_scripts/*
hct_mis_api/libs/*
hct_mis_api/settings/*
hct_mis_api/settings.py
hct_mis_api/conftest.py
hct_mis_api/config/settings.py
hct_mis_api/apps/core/management/commands/*

Expand Down
9 changes: 9 additions & 0 deletions backend/hct_mis_api/api/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ def get_data(
version_key = f"{business_area_slug}:{business_area_version}:{program_id}:{self.specific_view_cache_key}"
version = get_or_create_cache_key(version_key, 1)
return str(version)


class ProgramKeyBit(KeyBitBase):
def get_data(
self, params: Any, view_instance: Any, view_method: Any, request: Any, args: tuple, kwargs: dict
) -> str:
program_id = decode_id_string(kwargs.get("program_id"))
version = get_or_create_cache_key(f"{program_id}:version", 1)
return str(version)
1 change: 1 addition & 0 deletions backend/hct_mis_api/api/endpoints/rdi/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Meta:
"sector",
"cash_plus",
"population_goal",
"data_collecting_type",
)


Expand Down
6 changes: 6 additions & 0 deletions backend/hct_mis_api/api/tests/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from hct_mis_api.api.models import APIToken, Grant
from hct_mis_api.api.tests.base import HOPEApiTestCase
from hct_mis_api.apps.account.fixtures import BusinessAreaFactory
from hct_mis_api.apps.core.fixtures import DataCollectingTypeFactory
from hct_mis_api.apps.program.fixtures import ProgramFactory
from hct_mis_api.apps.program.models import Program

Expand All @@ -31,6 +32,7 @@ def setUpTestData(cls) -> None:
cls.list_url = reverse("api:program-list", args=[cls.business_area.slug])

def test_create_program(self) -> None:
data_collecting_type = DataCollectingTypeFactory()
data = {
"name": "Program #1",
"start_date": "2022-09-27",
Expand All @@ -40,6 +42,7 @@ def test_create_program(self) -> None:
"sector": "CHILD_PROTECTION",
"cash_plus": True,
"population_goal": 101,
"data_collecting_type": data_collecting_type.id,
}
response = self.client.post(self.create_url, data, format="json")
assert response.status_code == 403
Expand Down Expand Up @@ -69,6 +72,7 @@ def test_create_program(self) -> None:
"population_goal": 101,
"sector": "CHILD_PROTECTION",
"start_date": "2022-09-27",
"data_collecting_type": data_collecting_type.id,
},
)

Expand Down Expand Up @@ -123,6 +127,7 @@ def test_list_program(self) -> None:
"population_goal": program1.population_goal,
"sector": program1.sector,
"start_date": program1.start_date.strftime("%Y-%m-%d"),
"data_collecting_type": program1.data_collecting_type_id,
},
response.json(),
)
Expand All @@ -137,6 +142,7 @@ def test_list_program(self) -> None:
"population_goal": program2.population_goal,
"sector": program2.sector,
"start_date": program2.start_date.strftime("%Y-%m-%d"),
"data_collecting_type": program2.data_collecting_type_id,
},
response.json(),
)
Expand Down
1 change: 1 addition & 0 deletions backend/hct_mis_api/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"targeting/",
include("hct_mis_api.apps.targeting.api.urls", namespace="targeting"),
),
path("", include("hct_mis_api.apps.program.api.urls", namespace="programs")),
]
),
),
Expand Down
20 changes: 20 additions & 0 deletions backend/hct_mis_api/apps/account/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,23 @@ class TargetingViewListPermission(BaseRestPermission):

class GeoViewListPermission(BaseRestPermission):
PERMISSIONS = [Permissions.GEO_VIEW_LIST]


class ProgramCycleViewListPermission(BaseRestPermission):
PERMISSIONS = [Permissions.PM_PROGRAMME_CYCLE_VIEW_LIST]


class ProgramCycleViewDetailsPermission(BaseRestPermission):
PERMISSIONS = [Permissions.PM_PROGRAMME_CYCLE_VIEW_DETAILS]


class ProgramCycleCreatePermission(BaseRestPermission):
PERMISSIONS = [Permissions.PM_PROGRAMME_CYCLE_CREATE]


class ProgramCycleUpdatePermission(BaseRestPermission):
PERMISSIONS = [Permissions.PM_PROGRAMME_CYCLE_UPDATE]


class ProgramCycleDeletePermission(BaseRestPermission):
PERMISSIONS = [Permissions.PM_PROGRAMME_CYCLE_DELETE]
Loading

0 comments on commit 409656e

Please sign in to comment.