Skip to content

Commit

Permalink
Merge pull request #45 from rodekruis/dev
Browse files Browse the repository at this point in the history
Routes & tests
  • Loading branch information
jmargutt authored Oct 31, 2024
2 parents 6786d94 + 34669bb commit 6df6c05
Show file tree
Hide file tree
Showing 28 changed files with 3,217 additions and 1,807 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
name: Run automated Tests

on:
push:
workflow_dispatch:
pull_request:

Expand All @@ -26,7 +25,15 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then pip install .; fi
- name: Set up environment variables
run: |
echo "APPLICATIONINSIGHTS_CONNECTION_STRING=${{ secrets.APPLICATIONINSIGHTS_CONNECTION_STRING }}" >> $GITHUB_ENV
echo "COSMOS_URL=${{ secrets.COSMOS_URL }}" >> $GITHUB_ENV
echo "COSMOS_KEY=${{ secrets.COSMOS_KEY }}" >> $GITHUB_ENV
echo "PORT=${{ secrets.PORT }}" >> $GITHUB_ENV
echo "TEST_KOBO_ASSETID=${{ secrets.TEST_KOBO_ASSETID }}" >> $GITHUB_ENV
echo "TEST_KOBO_TOKEN=${{ secrets.TEST_KOBO_TOKEN }}" >> $GITHUB_ENV
- name: Test with pytest
run: |
pytest
29 changes: 0 additions & 29 deletions .github/workflows/test-submission.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM python:3.11-slim
# copy files to the /app folder in the container
ADD clients /app/clients
ADD mappings /app/mappings
ADD routes /app/routes
ADD utils /app/utils
ADD tests /app/tests
COPY ./main.py /app/main.py
COPY ./pyproject.toml /app/pyproject.toml
COPY ./poetry.lock /app/poetry.lock
Expand Down
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Using the [`kobo-to-espocrm`](https://kobo-connect.azurewebsites.net/docs#/defau
```
https://kobo-connect.azurewebsites.net/kobo-to-espocrm
```
6. In Kobo REST Services, add under `Custom HTTP Headers`:
- In `Name` add `targeturl` with in the `Value` the EspoCRM URL (for example, https://espocrminstancex.com).
- In `Name` add `targetkey` with in the `Value` the (newly) created API Key (from EspoCRM API User).
9. For each question, add a `Custom HTTP Header` that specifies which Kobo questions responds to which entity and field EspoCRM:
- The header `Name` (left) must correspond to the Kobo question **name**. (You can check the Kobo question name by going into edit mode of the form, open 'Settings' of the specific question and inspect the `Data Column Name`. Also, the Kobo question names can be found in the 'Data' table with previous submissions. This Kobo question name is different from the [Kobo question label](https://support.kobotoolbox.org/getting_started_xlsform.html#adding-questions) and can not contain spaces or symbols (except the underscore).).
6. In Kobo REST Services, add a header under `Custom HTTP Headers`:
- Under `Name` insert `targeturl` and under `Value` the EspoCRM URL (for example, https://espocrminstancex.com).
- Under `Name` insert `targetkey` and under `Value` the (newly) created API Key (from EspoCRM API User).
9. For each question, add a header that specifies which Kobo questions corresponds to which entity and field EspoCRM:
- The header name (left) must correspond to the Kobo question **name**. (You can check the Kobo question name by going into edit mode of the form, open 'Settings' of the specific question and inspect the `Data Column Name`. Also, the Kobo question names can be found in the 'Data' table with previous submissions. This Kobo question name is different from the [Kobo question label](https://support.kobotoolbox.org/getting_started_xlsform.html#adding-questions) and can not contain spaces or symbols (except the underscore).).
- The header value (right) must correspond to the EspoCRM entity **name**, followed by a dot (`.`), followed by the specific field **name**. Example: `Contact.name`. (EspoCRM name is different from the EspoCRM label, similar to the difference between Kobo question name and Kobo question label).

> [!IMPORTANT]
Expand All @@ -40,23 +40,30 @@ https://kobo-connect.azurewebsites.net/kobo-to-espocrm
- If you have a question of type `Select Many` (`select_multiple`) in Kobo and you want to save it in a field of type `Multi-Enum` in EspoCRM, add `multi.` before the Kobo question name in the header name.
- Example header: `multi.multiquestion1`: `Entity.field1`
- If you have a **repeating group** of questions in Kobo:
- you will need to save each repeated question in a different field in EspoCRM;
- in the header name:
- add `repeat.`, followed by the repeating group name, followed by a dot (`.`);
- then add a number to specify the number of the repeated question (starting from 0), followed by a dot (`.`);
- then add the name of the repeated question after the number;
- in the header value:
- as before, use the entity name, followed by a dot (`.`), followed by the field name in EspoCRM.
- you will need to save each repeated question in a different field in EspoCRM, as specified by a different header;
- under each header name:
- insert `repeat.`, followed by the repeating group name, followed by a dot (`.`);
- then insert a number to specify the number of the repeated question (starting from 0), followed by a dot (`.`);
- then insert the name of the repeated question after the number;
- under each header value:
- as before, insert the entity name, followed by a dot (`.`), followed by the field name in EspoCRM.
- Example headers:
- `repeat.repeatedgroup.0.repeatedquestion`: `Entity.field1`
- `repeat.repeatedgroup.1.repeatedquestion`: `Entity.field2`
- Not all repeated questions need to be filled in nor saved to EspoCRM.
- If you need to **update** a pre-existing record:
- add a question of type `calculate` called `updaterecordby` in the Kobo form, which will contain the value of the field which you will use to identify the record;
- add a `Custom HTTP Header` called `updaterecordby` with the name of the field that you will use to identify the record.
- add a header with name `updaterecordby` and as value the name of the field that you will use to identify the record.
- If you need to **avoid sending specific submissions** to EspoCRM:
- add a question called `skipconnect` in the Kobo form;
- whenever its value is `1` (based on some condition), the submission will not be sent to EspoCRM.
- If you need to **link the new record with another pre-existing record in** EspoCRM:
- ensure that the API user has read-access to the related entity;
- under the header name insert the name of the Kobo question, as usual;
- under the header value insert the entity name, followed by a dot (`.`), followed by the field name of type `Link` (the one containing the related entity record), followed by a dot (`.`), followed by the field name of the related entity used to relate the two.
- Example headers:
- `pcode`: `Entity.AdminLevel1.pcode`
- `programCode`: `Entity.program.code`

## 121

Expand Down
Empty file added __init__.py
Empty file.
5 changes: 5 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
PORT=8000
COSMOS_URL =
COSMOS_KEY =
APPLICATIONINSIGHTS_CONNECTION_STRING =
TEST_KOBO_TOKEN =
TEST_KOBO_ASSETID =
Loading

0 comments on commit 6df6c05

Please sign in to comment.