Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dj32 #69

Merged
merged 12 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,39 @@ jobs:
- name: Install test tools
run: pip install tox coverage

- name: Flake8
run: pip install flake8 && flake8

- name: Run SQLite tests
run: tox -e dj-31-db-sqlite
run: tox

- name: Run Postgres tests
env:
DATABASE_URL: postgres://postgres:changeme@localhost:5432/test
run: tox -e dj-31-db-pg
run: tox

- name: Run MariaDB tests
env:
DATABASE_URL: mysql://root:@127.0.0.1:13306/test
run: |
/usr/bin/mysql --host=127.0.0.1 --port=13306 --user=root --execute "SHOW DATABASES;"
tox -e dj-31-db-maria
tox

- name: Coverage report
run: coverage report -m
run: |
coverage report -m
coverage lcov -o ./coverage/lcov.info

- name: Coveralls Parallel
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.test_number }}
parallel: true

public-coveralls:
needs: test
runs-on: ubuntu-latest
steps:
- name: Publish to Coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
26 changes: 26 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
* Start the dev environment (including Postgres & MariaDB databases) with:

```
docker-compose up
```

* After you have started the dev stack, start the tests with:

```
docker-compose exec dev tox
```

* Relock with

```
docker-compose run dev poetry relock
```

* Testing using script and tox (so you don't have to remember the db urls):


-e is the tox environment to run - eg. dj-31, dj-32 or dj-40
-PSM are optional flags to run for Postgres, SQLite, MariaDB
```
./dev/local-test.sh -e dj-31 -PSM
```
1 change: 0 additions & 1 deletion dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ services:
environment:
- PYTHONPATH=/usr/src/app:/usr/src/app/tests/
- DJANGO_SETTINGS_MODULE=library_app.settings
image: python
# env_file:
# - default.env
# - .env
Expand Down
34 changes: 34 additions & 0 deletions dev/local-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# A little script to run on the different dev databases
RUN_PG=0
RUN_SQLITE=0
RUN_MARIA=0

while getopts e:PSM flag
do
case "${flag}" in
e) TOX_ENV=${OPTARG};;
P) RUN_PG=1;;
S) RUN_SQLITE=1;;
M) RUN_MARIA=1;;
esac
done

if [ $RUN_SQLITE -eq 1 ]
then
echo "Testing with SQLLite"
tox -e ${TOX_ENV} # Sqlite
fi

if [ $RUN_MARIA -eq 1 ]
then
echo "Testing with MariaDB"
DATABASE_URL=mysql://root:@maria_db:13306/test tox -e ${TOX_ENV}
fi

if [ $RUN_PG -eq 1 ]
then
echo "Testing with Postgres"
DATABASE_URL=postgres://postgres:changeme@postgres_db:5432/test tox -e ${TOX_ENV} # Sqlite
fi

12 changes: 5 additions & 7 deletions garnett/expressions.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
from django.db.models import F
from django.db.models.fields.json import KeyTextTransform

from garnett.utils import get_current_language
from garnett.utils import get_current_language_code
from garnett.fields import TranslatedField


# Based on: https://code.djangoproject.com/ticket/29769#comment:5
# Updated comment here
# https://code.djangoproject.com/ticket/31639
class LangF(F):
def resolve_expression(
self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False
):
rhs = super().resolve_expression(query, allow_joins, reuse, summarize, for_save)
def resolve_expression(self, *args, **kwargs):
rhs = super().resolve_expression(*args, **kwargs)
if isinstance(rhs.field, TranslatedField):
field_list = self.name.split("__")
# TODO: should this always lookup lang
if len(field_list) == 1:
# Lookup current lang for one field
field_list.extend([get_current_language()])
field_list.extend([get_current_language_code()])
for name in field_list[1:]:
# Perform key lookups along path
rhs = KeyTextTransform(name, rhs)
Expand All @@ -30,4 +28,4 @@ class L(KeyTextTransform):
"""Expression to return the current language"""

def __init__(self, *args, **kwargs):
super().__init__(get_current_language(), *args, **kwargs)
super().__init__(get_current_language_code(), *args, **kwargs)
2 changes: 1 addition & 1 deletion garnett/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def available_languages(ego):
langs = set()
for field in ego.translatable_fields:
langs |= getattr(ego, field.ts_name, {}).keys()
return [lang for lang in get_languages() if lang.language in langs]
return [lang for lang in get_languages() if lang.to_tag() in langs]

setattr(cls, "available_languages", available_languages)

Expand Down
2 changes: 1 addition & 1 deletion garnett/lookups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db.models import lookups
from django.db.models.fields import json, CharField
from django.db.models.functions import Cast
from django.contrib.postgres.fields.jsonb import KeyTextTransform
from django.db.models.fields.json import KeyTextTransform
from django.contrib.postgres.lookups import SearchLookup, TrigramSimilar
from django.contrib.postgres.search import TrigramSimilarity

Expand Down
Loading