Skip to content

Commit

Permalink
Merge branch 'kobocat2.0-step5-new-docker-image' into kobocat2.0-step…
Browse files Browse the repository at this point in the history
…6-refactoring-settings
  • Loading branch information
noliveleger committed Mar 4, 2021
2 parents 81e1d52 + 314f492 commit ac1ce8c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 54 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,33 @@ To compile MO files and update live translations
$ django-admin.py compilemessages ;
$ for app in {main,viewer} ; do cd kobocat/apps/${app} && django-admin.py compilemessages && cd - ; done
```
## Testing in KoBoCAT

For kobo-install users, enter the folder for kobo-install and run this command

```
./run.py -cf exec kobocat bash
```

For all other users, enter the container using this command

``` sh
$ docker exec -it {{kobocat container}} /bin/bash
```

Run pip install the development dependancies

``` sh
$ pip install -r requirements/dev.pip
```
Install libsqlite3-mod-spatialite for the testing database

``` sh
$ apt-get update && apt-get install libsqlite3-mod-spatialite
```

Run pytest to run all automated tests

``` sh
$ pytest
```
20 changes: 13 additions & 7 deletions onadata/apps/restservice/services/kpi_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ class ServiceDefinition(RestServiceInterface):

def send(self, endpoint, data):

# Will be used internally by KPI to fetch data with KoBoCatBackend
post_data = {
"instance_id": data.get("instance_id") # Will be used internally by KPI to fetch data with KoboCatBackend
"instance_id": data.get("instance_id")
}
headers = {"Content-Type": "application/json"}

# Verify if endpoint starts with `/assets/` before sending the request to`kpi`
# Verify if endpoint starts with `/assets/` before sending
# the request to KPI
pattern = r'{}'.format(settings.KPI_HOOK_ENDPOINT_PATTERN.replace(
'{asset_uid}', '[^/]*'))

# Match v2 and v1 endpoints.
if re.match(pattern, endpoint) or re.match(pattern[7:], endpoint):
# Build the url in the service to avoid saving hardcoded domain name in the DB
# Build the url in the service to avoid saving hardcoded
# domain name in the DB
url = "{}{}".format(
settings.KOBOFORM_INTERNAL_URL,
endpoint
Expand All @@ -34,8 +37,11 @@ def send(self, endpoint, data):
response.raise_for_status()

# Save successful
Instance.objects.filter(pk=data.get("instance_id")).update(posted_to_kpi=True)
Instance.objects.filter(pk=data.get("instance_id")).update(
posted_to_kpi=True
)
else:
logging.warning('This endpoint: `{}` is not valid for `KPI Hook`'.format(
endpoint
))
logging.warning(
f'This endpoint: `{endpoint}` is not valid for `KPI Hook`'
)

2 changes: 1 addition & 1 deletion onadata/apps/viewer/models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __str__(self):
(XLS_EXPORT, 'Excel'),
(CSV_EXPORT, 'CSV'),
(ZIP_EXPORT, 'ZIP'),
(KML_EXPORT, 'kml')
(KML_EXPORT, 'kml'),
]

EXPORT_TYPE_DICT = dict(export_type for export_type in EXPORT_TYPES)
Expand Down
1 change: 0 additions & 1 deletion onadata/libs/serializers/metadata_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ def create(self, validated_data):
file_hash=file_hash,
from_kpi=from_kpi,
)

18 changes: 14 additions & 4 deletions onadata/libs/utils/logger_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,21 @@ def update_mongo_for_xform(xform, only_update_missing=True):
done = 0
for id_, instance in instances.items():
(pi, created) = ParsedInstance.objects.get_or_create(instance=instance)
if not pi.save(asynchronous=False):
print("\033[91m[ERROR] - Instance #{}/uuid:{} - Could not save the parsed instance\033[0m".format(
id_, instance.uuid))
try:
save_success = pi.save(asynchronous=False)
except InstanceEmptyError:
print(
"\033[91m[WARNING] - Skipping Instance #{}/uuid:{} because "
"it is empty\033[0m".format(id_, instance.uuid)
)
else:
done += 1
if not save_success:
print(
"\033[91m[ERROR] - Instance #{}/uuid:{} - Could not save "
"the parsed instance\033[0m".format(id_, instance.uuid)
)
else:
done += 1

progress = "\r%.2f %% done..." % ((float(done) / float(total)) * 100)
sys.stdout.write(progress)
Expand Down
23 changes: 0 additions & 23 deletions onadata/libs/utils/qrcode.py

This file was deleted.

18 changes: 0 additions & 18 deletions onadata/libs/utils/tests/test_qrcode.py

This file was deleted.

0 comments on commit ac1ce8c

Please sign in to comment.