Skip to content

Commit

Permalink
Merge pull request #28 from openimis/develop
Browse files Browse the repository at this point in the history
1.3
  • Loading branch information
delcroip authored Oct 29, 2021
2 parents 8c2b2b7 + fcd7f38 commit a7e0c3c
Show file tree
Hide file tree
Showing 35 changed files with 3,324 additions and 6 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/openmis-module-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Automated CI testing
# This workflow run automatically for every commit on github it checks the syntax and launch the tests.
# | grep . | uniq -c filters out empty lines and then groups consecutive lines together with the number of occurrences
on:
pull_request:
workflow_dispatch:
inputs:
comment:
description: Just a simple comment to know the purpose of the manual build
required: false

jobs:
run_test:
runs-on: ubuntu-latest
services:
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: GitHub999
ports:
- 1433:1433
# needed because the mssql container does not provide a health check
options: --health-interval=10s --health-timeout=3s --health-start-period=10s --health-retries=10 --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -Q 'SELECT 1' || exit 1"

steps:
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: install linux packages
run: |
wget https://raw.githubusercontent.com/openimis/database_ms_sqlserver/main/Empty%20databases/openIMIS_ONLINE.sql -O openIMIS_ONLINE.sql
wget https://raw.githubusercontent.com/openimis/database_ms_sqlserver/main/Demo%20database/openIMIS_demo_ONLINE.sql -O openIMIS_demo_ONLINE.sql
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools build-essential dialog apt-utils unixodbc-dev -y
python -m pip install --upgrade pip
- name: pull openimis backend
run: |
rm ./openimis -rf
git clone --depth 1 --branch develop https://github.com/openimis/openimis-be_py.git ./openimis
- name: copy current branch
uses: actions/checkout@v2
with:
path: './current-module'
- name: Update the configuration
working-directory: ./openimis
run: |
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
echo "the local module called $MODULE_NAME will be injected in openIMIS .json"
jq --arg name "$MODULE_NAME" 'if [.modules[].name == ($name)]| max then (.modules[] | select(.name == ($name)) | .pip)|="../current-module" else .modules |= .+ [{name:($name), pip:"../current-module"}] end' openimis.json
echo $(jq --arg name "$MODULE_NAME" 'if [.modules[].name == ($name)]| max then (.modules[] | select(.name == ($name)) | .pip)|="../current-module" else .modules |= .+ [{name:($name), pip:"../current-module"}] end' openimis.json) > openimis.json
- name: Install openIMIS Python dependencies
working-directory: ./openimis
run: |
pip install -r requirements.txt
python modules-requirements.py openimis.json > modules-requirements.txt
cat modules-requirements.txt
pip install -r modules-requirements.txt
- name: Environment info
working-directory: ./openimis
run: |
pip list
- name: Initialize DB
run: |
/opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis'
/opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis'
/opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis -i openIMIS_ONLINE.sql | grep . | uniq -c
/opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis -i openIMIS_demo_ONLINE.sql | grep . | uniq -c
env:
SA_PASSWORD: GitHub999
ACCEPT_EULA: Y

# - name: Check formatting with black
# run: |
# black --check .

- name: Django tests
working-directory: ./openimis/openIMIS
run: |
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
python -V
ls -l
python manage.py migrate
python init_test_db.py | grep . | uniq -c
python manage.py test --keepdb $MODULE_NAME
env:
SECRET_KEY: secret
DEBUG: true
#DJANGO_SETTINGS_MODULE: hat.settings
DB_HOST: localhost
DB_PORT: 1433
DB_NAME: imis
DB_USER: sa
DB_PASSWORD: GitHub999
#DEV_SERVER: true
SITE_ROOT: api
REMOTE_USER_AUTHENTICATION: True
38 changes: 38 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
release:
types: [created]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: olegtarasov/get-tag@v2.1
id: tagName
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine jq
- name: update setup.py
run: |
echo "tag to use $GIT_TAG_NAME"
sed -i "s/version='.*'/version='$GIT_TAG_NAME'/g" setup.py
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{secrets.PYPI_TOKEN}}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
# openIMIS Backend Contribution Plan reference module
This repository holds the files of the openIMIS Backend ContributionPlan and ContributionPlanBundle reference module.
It is dedicated to be deployed as a module of [openimis-be_py](https://github.com/openimis/openimis-be_py).

## ORM mapping:
* tblContributionPlanBundle > ContributionPlanBundle
* tblContributionPlan > ContributionPlan
* tblContributionPlanBundleDetails > ContributionPlanBundleDetails

## GraphQl Queries
* contributionPlanBundle
* contributionPlan
* contributionPlanBundleDetails

## GraphQL Mutations - each mutation emits default signals and return standard error lists (cfr. openimis-be-core_py)
* createContributionPlanBundle
* updateContributionPlanBundle
* deleteContributionPlanBundle
* replaceContributionPlanBundle
* createContributionPlan
* updateContributionPlan
* deleteContributionPlan
* replaceContributionPlan
* createContributionPlanBundleDetails
* updateContributionPlanBundleDetails
* deleteContributionPlanBundleDetails

## Services
* ContributionPlanBundle - CRUD services, replace
* ContributionPlan - CRUD services, replace
* ContributionPlanBundleDetails - create, update, delete

## Configuration options (can be changed via core.ModuleConfiguration)
* gql_query_contributionplanbundle_perms: required rights to call contribution_plan_bundle GraphQL Query (default: ["151101"])
* gql_query_contributionplanbundle_admins_perms: required rights to call contribution_plan_bundle_admin GraphQL Query (default: [])

* gql_query_contributionplan_perms: required rights to call contribution_plan GraphQL Query (default: ["151201"])
* gql_query_contributionplan_admins_perms: required rights to call contribution_plan_admin GraphQL Query (default: [])

* gql_mutation_create_contributionplanbundle_perms: required rights to call createContributionPlanBundle GraphQL Mutation (default: ["151102"])
* gql_mutation_update_contributionplanbundle_perms: required rights to call updateContributionPlanBundle GraphQL Mutation (default: ["151103"])
* gql_mutation_delete_contributionplanbundle_perms: required rights to call deleteContributionPlanBundle GraphQL Mutation (default: ["151104"])
* gql_mutation_replace_contributionplanbundle_perms: required rights to call replaceContributionPlanBundle GraphQL Mutation (default: ["151106"])

* gql_mutation_create_contributionplan_perms: required rights to call createContributionPlan GraphQL Mutation (default: ["151202"])
* gql_mutation_update_contributionplan_perms: required rights to call updateContributionPlan GraphQL Mutation (default: ["151203"])
* gql_mutation_delete_contributionplan_perms: required rights to call deleteContributionPlan GraphQL Mutation (default: ["151204"])
* gql_mutation_replace_contributionplan_perms: required rights to call replaceContributionPlan GraphQL Mutation (default: ["151206"])
1 change: 1 addition & 0 deletions contribution_plan/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'contribution_plan.apps.ContributionPlanConfig'
83 changes: 82 additions & 1 deletion contribution_plan/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,86 @@
from django.apps import AppConfig


MODULE_NAME = "contribution_plan"


DEFAULT_CFG = {
"gql_query_contributionplanbundle_perms": ["151101"],
"gql_query_contributionplanbundle_admins_perms": [],
"gql_query_contributionplan_perms": ["151201"],
"gql_query_contributionplan_admins_perms": [],

"gql_mutation_create_contributionplanbundle_perms": ["151102"],
"gql_mutation_update_contributionplanbundle_perms": ["151103"],
"gql_mutation_delete_contributionplanbundle_perms": ["151104"],
"gql_mutation_replace_contributionplanbundle_perms": ["151106"],

"gql_mutation_create_contributionplan_perms": ["151202"],
"gql_mutation_update_contributionplan_perms": ["151203"],
"gql_mutation_delete_contributionplan_perms": ["151204"],
"gql_mutation_replace_contributionplan_perms": ["151206"],
}


class ContributionPlanConfig(AppConfig):
name = 'contribution_plan'
name = MODULE_NAME

gql_query_contributionplanbundle_perms = []
gql_query_contributionplanbundle_admins_perms = []

gql_query_contributionplan_perms = []
gql_query_contributionplan_admins_perms = []

gql_mutation_create_contributionplanbundle_perms = []
gql_mutation_update_contributionplanbundle_perms = []
gql_mutation_delete_contributionplanbundle_perms = []
gql_mutation_replace_contributionplanbundle_perms = []

gql_mutation_create_contributionplan_perms = []
gql_mutation_update_contributionplan_perms = []
gql_mutation_delete_contributionplan_perms = []
gql_mutation_replace_contributionplan_perms = []

def _configure_permissions(selfself, cfg):
ContributionPlanConfig.gql_query_contributionplanbundle_perms = cfg[
"gql_query_contributionplanbundle_perms"]
ContributionPlanConfig.gql_query_contributionplanbundle_admins_perms = cfg[
"gql_query_contributionplanbundle_admins_perms"
]

ContributionPlanConfig.gql_query_contributionplan_perms = cfg[
"gql_query_contributionplan_perms"]
ContributionPlanConfig.gql_query_contributionplan_admins_perms = cfg[
"gql_query_contributionplan_admins_perms"
]

ContributionPlanConfig.gql_mutation_create_contributionplanbundle_perms = cfg[
"gql_mutation_create_contributionplanbundle_perms"
]
ContributionPlanConfig.gql_mutation_update_contributionplanbundle_perms = cfg[
"gql_mutation_update_contributionplanbundle_perms"
]
ContributionPlanConfig.gql_mutation_delete_contributionplanbundle_perms = cfg[
"gql_mutation_delete_contributionplanbundle_perms"
]
ContributionPlanConfig.gql_mutation_replace_contributionplanbundle_perms = cfg[
"gql_mutation_replace_contributionplanbundle_perms"
]

ContributionPlanConfig.gql_mutation_create_contributionplan_perms = cfg[
"gql_mutation_create_contributionplan_perms"
]
ContributionPlanConfig.gql_mutation_update_contributionplan_perms = cfg[
"gql_mutation_update_contributionplan_perms"
]
ContributionPlanConfig.gql_mutation_delete_contributionplan_perms = cfg[
"gql_mutation_delete_contributionplan_perms"
]
ContributionPlanConfig.gql_mutation_replace_contributionplan_perms = cfg[
"gql_mutation_replace_contributionplan_perms"
]

def ready(self):
from core.models import ModuleConfiguration
cfg = ModuleConfiguration.get_or_default(MODULE_NAME, DEFAULT_CFG)
self._configure_permissions(cfg)
1 change: 1 addition & 0 deletions contribution_plan/gql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .gql_types import *
1 change: 1 addition & 0 deletions contribution_plan/gql/gql_mutations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .input_types import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from core.gql.gql_mutations import DeleteInputType
from core.gql.gql_mutations.base_mutation import BaseMutation, BaseDeleteMutation, BaseReplaceMutation, \
BaseHistoryModelCreateMutationMixin, BaseHistoryModelUpdateMutationMixin, \
BaseHistoryModelDeleteMutationMixin, BaseHistoryModelReplaceMutationMixin
from contribution_plan.gql.gql_mutations import ContributionPlanBundleDetailsInputType, \
ContributionPlanBundleDetailsUpdateInputType, ContributionPlanBundleDetailsReplaceInputType
from contribution_plan.models import ContributionPlanBundleDetails


class CreateContributionPlanBundleDetailsMutation(BaseHistoryModelCreateMutationMixin, BaseMutation):
_mutation_class = "ContributionPlanBundleDetailsMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundleDetails

class Input(ContributionPlanBundleDetailsInputType):
pass


class UpdateContributionPlanBundleDetailsMutation(BaseHistoryModelUpdateMutationMixin, BaseMutation):
_mutation_class = "ContributionPlanBundleDetailsMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundleDetails

class Input(ContributionPlanBundleDetailsUpdateInputType):
pass


class DeleteContributionPlanBundleDetailsMutation(BaseHistoryModelDeleteMutationMixin, BaseDeleteMutation):
_mutation_class = "ContributionPlanBundleDetailsMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundleDetails

class Input(DeleteInputType):
pass


class ReplaceContributionPlanBundleDetailsMutation(BaseHistoryModelReplaceMutationMixin, BaseReplaceMutation):
_mutation_class = "ContributionPlanBundleDetailsMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundleDetails

class Input(ContributionPlanBundleDetailsReplaceInputType):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from core.gql.gql_mutations import DeleteInputType
from core.gql.gql_mutations.base_mutation import BaseMutation, BaseDeleteMutation, BaseReplaceMutation, \
BaseHistoryModelCreateMutationMixin, BaseHistoryModelUpdateMutationMixin, \
BaseHistoryModelDeleteMutationMixin, BaseHistoryModelReplaceMutationMixin
from contribution_plan.gql.gql_mutations import ContributionPlanBundleInputType, ContributionPlanBundleUpdateInputType, \
ContributionPlanBundleReplaceInputType
from contribution_plan.models import ContributionPlanBundle


class CreateContributionPlanBundleMutation(BaseHistoryModelCreateMutationMixin, BaseMutation):
_mutation_class = "ContributionPlanBundleMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundle

class Input(ContributionPlanBundleInputType):
pass


class UpdateContributionPlanBundleMutation(BaseHistoryModelUpdateMutationMixin, BaseMutation):
_mutation_class = "ContributionPlanBundleMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundle

class Input(ContributionPlanBundleUpdateInputType):
pass


class DeleteContributionPlanBundleMutation(BaseHistoryModelDeleteMutationMixin, BaseDeleteMutation):
_mutation_class = "ContributionPlanBundleMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundle

class Input(DeleteInputType):
pass


class ReplaceContributionPlanBundleMutation(BaseHistoryModelReplaceMutationMixin, BaseReplaceMutation):
_mutation_class = "ContributionPlanBundleMutation"
_mutation_module = "contribution_plan"
_model = ContributionPlanBundle

class Input(ContributionPlanBundleReplaceInputType):
pass
Loading

0 comments on commit a7e0c3c

Please sign in to comment.