diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 3fe809f0..59b149cd 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation. Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting ## Our Responsibilities @@ -55,7 +55,7 @@ further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at behzad.public@gmail.com. All +reported by contacting the project team at bbmokhtari.global@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ae2286dc..097f7302 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contribution -[comment]: # (any changes to this module must also be reflected in /docs/contribution.rst) +[comment]: # "any changes to this module must also be reflected in /docs/contribution.rst" This module provides comprehensive information on how to contribute to Django Translations. @@ -19,7 +19,7 @@ requests](https://github.com/bbmokhtari/django-translations/pulls). Clone the repository of Django Translations: -``` bash +```bash $ git clone https://github.com/bbmokhtari/django-translations.git ``` @@ -28,7 +28,7 @@ environment) install the required libraries for working on it. To do this change directories into the root directory of the cloned repository and run the following command: -``` bash +```bash $ pip install -r requirements_dev.txt ``` @@ -46,7 +46,7 @@ from here on out run all the commands in that directory: To create the example project: -``` bash +```bash $ python create.py ``` @@ -55,26 +55,26 @@ repository. Run migrations: -``` bash +```bash $ python project/manage.py migrate ``` To populate some data for the Sample app: -``` bash +```bash $ python project/manage.py shell ``` Then in the python shell: -``` python +```python >>> from sample.utils import create_all >>> create_all() ``` To run the example project: -``` bash +```bash $ python project/manage.py runserver ``` @@ -92,7 +92,7 @@ and cities. The example project supports `German (de)` and `Turkish (tr)` languages. -Change the *language* settings in your browser and reload the API +Change the _language_ settings in your browser and reload the API endpoint, or if you are using a rest client like Postman change the `Accept-Language` header in your request. The API endpoint should show you the response in the requested language. @@ -105,7 +105,7 @@ To change the basic configurations of Django Translations edit the To generate the configurations file change directories into the root directory of the cloned repository and run the following command: -``` bash +```bash $ python config.py ``` @@ -116,7 +116,7 @@ cloned repository. To run the tests: (make sure you have created [The example project]()) -``` bash +```bash $ python project/manage.py test ``` @@ -126,13 +126,13 @@ To build the documentation: (make sure you have created [The example project](), also make sure to generate the [Configurations](#configurations)) -``` bash +```bash $ make --directory docs html ``` To run tests on the examples of the documentation: -``` bash +```bash $ make --directory docs doctest ``` @@ -142,23 +142,23 @@ Django Translations uses `flake8` for styling purposes. To lint the code: -``` bash +```bash $ flake8 ``` ## Releasing a version -Creating a git tag automatically causes Travis CI to: +Creating a git tag automatically causes CI to: - - Lint the code - - Run unit tests - - Run documentation tests +- Lint the code +- Run unit tests +- Run documentation tests And if all of the above pass: - - Generate the proper documentation with the git tag as the version - number and upload it to GitHub Pages. - - Generate the python package with the git tag as the version number - and upload it to PyPI. +- Generate the proper documentation with the git tag as the version + number and upload it to GitHub Pages. +- Generate the python package with the git tag as the version number + and upload it to PyPI. The tag **must** follow the `PEP 440` conventions. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 24e8a481..ef866d1f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -22,4 +22,5 @@ Please ensure the following steps have been taken: - [ ] Have you run the documentation tests? ## Note: -Please ensure that once the PR is submitted, you check Travis CI for build issues and submit an update to your PR as soon as possible. + +Please ensure that once the PR is submitted, you check CI for build issues and submit an update to your PR as soon as possible. diff --git a/.github/README.md b/.github/README.md index 71e20f55..a65e4875 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,8 +1,7 @@ # Django Translations -[![build](https://travis-ci.com/bbmokhtari/django-translations.svg?branch=master)](https://travis-ci.com/bbmokhtari/django-translations) -[![python](https://img.shields.io/badge/python-%3E%3D3.6%2C%20%3C4-0073b7)](https://pypi.org/project/django-translations/) -[![django](https://img.shields.io/badge/django-%3E%3D2.2%2C%20%3C4-0C4B33)](https://pypi.org/project/django-translations/) +[![django](https://img.shields.io/badge/django-%3E%3D2.2%2C%20%3C6.0-0C4B33)](https://pypi.org/project/django-translations/) +[![python](https://img.shields.io/badge/python-%3E%3D3.7%2C%20%3C4.0-0073b7)](https://pypi.org/project/django-translations/) Django model translation for perfectionists with deadlines. @@ -29,42 +28,42 @@ Currently, this project is incompatible with PostgreSQL. ## Requirements -- Python (\>=3.6, \<4) -- Django (\>=2.2, \<4) +- Python (\>=3.7, \<4) +- Django (\>=2.2, \<6) ## Installation 1. Install Django Translations using pip: - - ``` bash + + ```bash $ pip install django-translations ``` 2. Add `translations` to the `INSTALLED_APPS` in the settings of your project: - - ``` python + + ```python INSTALLED_APPS += [ 'translations', ] ``` 3. Run `migrate`: - - ``` bash + + ```bash $ python manage.py migrate ``` 4. Configure Django internationalization and localization settings: - - ``` python + + ```python USE_I18N = True # use internationalization USE_L10N = True # use localization - + MIDDLEWARE += [ # locale middleware 'django.middleware.locale.LocaleMiddleware', ] - + LANGUAGE_CODE = 'en-us' # default (fallback) language LANGUAGES = ( # supported languages ('en', 'English'), @@ -73,7 +72,7 @@ Currently, this project is incompatible with PostgreSQL. ('tr', 'Turkish'), ) ``` - + Please note that these settings are for Django itself. ## Basic Usage @@ -82,7 +81,7 @@ Currently, this project is incompatible with PostgreSQL. Inherit `Translatable` in any model you want translated: -``` python +```python from translations.models import Translatable class Continent(Translatable): @@ -100,7 +99,7 @@ No migrations needed afterwards. Use the admin extensions: -``` python +```python from translations.admin import TranslatableAdmin, TranslationInline class ContinentAdmin(TranslatableAdmin): @@ -115,7 +114,7 @@ This provides specialized translation inlines for the model. Use the queryset extensions: -``` python +```python >>> from sample.models import Continent >>> continents = Continent.objects.all( ... ).distinct( # familiar distinct @@ -146,7 +145,7 @@ This provides a powerful yet familiar interface to work with the querysets. Use the translation context: -``` python +```python >>> from translations.context import Context >>> from sample.models import Continent >>> continents = Continent.objects.all() @@ -157,12 +156,12 @@ Use the translation context: ... print(continents) ... print(continents[0].countries.all()) ... print(continents[0].countries.all()[0].cities.all()) -... +... ... continents[0].countries.all()[0].name = 'Change the name' ... context.update('de') # update the translations from the context -... +... ... context.delete('de') # delete the translations of the context -... +... ... context.reset() # reset the translations of the context ... print(':') # use the objects like before ... print(continents) @@ -202,6 +201,7 @@ For more interesting capabilities browse through the ## Support the project To support the project you can: + - ⭐️: [Star](http://github.com/bbmokhtari/django-translations/) it on GitHub. - 💻: [Contribute](https://bbmokhtari.github.io/django-translations/contribution.html) to the code base. - ☕️: [Buy](https://bbmokhtari.github.io/django-translations/donation.html) the maintainers coffee. diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..8e7cbcd9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,431 @@ +name: Main +on: + push: + branches: + - master + tags: + - "[0-9]+.[0-9]+.[0-9]+" + pull_request: +jobs: + lint: + name: Lint with Flake8 + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + flake8-version: ["5.0"] + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install --upgrade pip + pip install flake8~=${{ matrix.flake8-version }} + - name: Run Flake8 + run: flake8 + test-units: + name: Test units + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + django-version: + ["2.2", "3.0", "3.1", "3.2", "4.0", "4.1", "4.2", "5.0", "5.1"] + djangorestframework-version: ["3.1"] + exclude: + - python-version: "3.10" + django-version: "2.2" + - python-version: "3.11" + django-version: "2.2" + - python-version: "3.12" + django-version: "2.2" + - python-version: "3.13" + django-version: "2.2" + - python-version: "3.10" + django-version: "3.0" + - python-version: "3.11" + django-version: "3.0" + - python-version: "3.12" + django-version: "3.0" + - python-version: "3.13" + django-version: "3.0" + - python-version: "3.10" + django-version: "3.1" + - python-version: "3.11" + django-version: "3.1" + - python-version: "3.12" + django-version: "3.1" + - python-version: "3.13" + django-version: "3.1" + - python-version: "3.11" + django-version: "3.2" + - python-version: "3.12" + django-version: "3.2" + - python-version: "3.13" + django-version: "3.2" + - python-version: "3.7" + django-version: "4.0" + - python-version: "3.11" + django-version: "4.0" + - python-version: "3.12" + django-version: "4.0" + - python-version: "3.13" + django-version: "4.0" + - python-version: "3.7" + django-version: "4.1" + - python-version: "3.12" + django-version: "4.1" + - python-version: "3.13" + django-version: "4.1" + - python-version: "3.7" + django-version: "4.2" + - python-version: "3.13" + django-version: "4.2" + - python-version: "3.7" + django-version: "5.0" + - python-version: "3.8" + django-version: "5.0" + - python-version: "3.9" + django-version: "5.0" + - python-version: "3.13" + django-version: "5.0" + - python-version: "3.7" + django-version: "5.1" + - python-version: "3.8" + django-version: "5.1" + - python-version: "3.9" + django-version: "5.1" + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install --upgrade pip + pip install django~=${{ matrix.django-version }} + pip install djangorestframework~=${{ matrix.djangorestframework-version }} + - name: Create example project + run: python create.py + - name: Run and test units + run: python project/manage.py test -v 3 + test-docs: + name: Test documentations + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + django-version: + ["2.2", "3.0", "3.1", "3.2", "4.0", "4.1", "4.2", "5.0", "5.1"] + djangorestframework-version: ["3.1"] + sphinx-version: ["5.3", "7.4"] + exclude: + - python-version: "3.10" + django-version: "2.2" + - python-version: "3.11" + django-version: "2.2" + - python-version: "3.12" + django-version: "2.2" + - python-version: "3.13" + django-version: "2.2" + - python-version: "3.10" + django-version: "3.0" + - python-version: "3.11" + django-version: "3.0" + - python-version: "3.12" + django-version: "3.0" + - python-version: "3.13" + django-version: "3.0" + - python-version: "3.10" + django-version: "3.1" + - python-version: "3.11" + django-version: "3.1" + - python-version: "3.12" + django-version: "3.1" + - python-version: "3.13" + django-version: "3.1" + - python-version: "3.11" + django-version: "3.2" + - python-version: "3.12" + django-version: "3.2" + - python-version: "3.13" + django-version: "3.2" + - python-version: "3.7" + django-version: "4.0" + - python-version: "3.11" + django-version: "4.0" + - python-version: "3.12" + django-version: "4.0" + - python-version: "3.13" + django-version: "4.0" + - python-version: "3.7" + django-version: "4.1" + - python-version: "3.12" + django-version: "4.1" + - python-version: "3.13" + django-version: "4.1" + - python-version: "3.7" + django-version: "4.2" + - python-version: "3.13" + django-version: "4.2" + - python-version: "3.7" + django-version: "5.0" + - python-version: "3.8" + django-version: "5.0" + - python-version: "3.9" + django-version: "5.0" + - python-version: "3.13" + django-version: "5.0" + - python-version: "3.7" + django-version: "5.1" + - python-version: "3.8" + django-version: "5.1" + - python-version: "3.9" + django-version: "5.1" + - python-version: "3.7" + sphinx-version: "7.4" + - python-version: "3.8" + sphinx-version: "7.4" + - python-version: "3.9" + sphinx-version: "7.4" + - python-version: "3.10" + sphinx-version: "7.4" + - python-version: "3.11" + sphinx-version: "7.4" + - python-version: "3.12" + sphinx-version: "5.3" + - python-version: "3.13" + sphinx-version: "5.3" + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install --upgrade pip + pip install django~=${{ matrix.django-version }} + pip install djangorestframework~=${{ matrix.djangorestframework-version }} + pip install sphinx~=${{ matrix.sphinx-version }} + - name: Create example project + run: python create.py + - name: Create configurations file + run: python config.py + - name: Run and test documentations + run: make --directory docs doctest + build-docs: + name: Build documentations + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + django-version: + ["2.2", "3.0", "3.1", "3.2", "4.0", "4.1", "4.2", "5.0", "5.1"] + djangorestframework-version: ["3.1"] + sphinx-version: ["5.3", "7.4"] + exclude: + - python-version: "3.10" + django-version: "2.2" + - python-version: "3.11" + django-version: "2.2" + - python-version: "3.12" + django-version: "2.2" + - python-version: "3.13" + django-version: "2.2" + - python-version: "3.10" + django-version: "3.0" + - python-version: "3.11" + django-version: "3.0" + - python-version: "3.12" + django-version: "3.0" + - python-version: "3.13" + django-version: "3.0" + - python-version: "3.10" + django-version: "3.1" + - python-version: "3.11" + django-version: "3.1" + - python-version: "3.12" + django-version: "3.1" + - python-version: "3.13" + django-version: "3.1" + - python-version: "3.11" + django-version: "3.2" + - python-version: "3.12" + django-version: "3.2" + - python-version: "3.13" + django-version: "3.2" + - python-version: "3.7" + django-version: "4.0" + - python-version: "3.11" + django-version: "4.0" + - python-version: "3.12" + django-version: "4.0" + - python-version: "3.13" + django-version: "4.0" + - python-version: "3.7" + django-version: "4.1" + - python-version: "3.12" + django-version: "4.1" + - python-version: "3.13" + django-version: "4.1" + - python-version: "3.7" + django-version: "4.2" + - python-version: "3.13" + django-version: "4.2" + - python-version: "3.7" + django-version: "5.0" + - python-version: "3.8" + django-version: "5.0" + - python-version: "3.9" + django-version: "5.0" + - python-version: "3.13" + django-version: "5.0" + - python-version: "3.7" + django-version: "5.1" + - python-version: "3.8" + django-version: "5.1" + - python-version: "3.9" + django-version: "5.1" + - python-version: "3.7" + sphinx-version: "7.4" + - python-version: "3.8" + sphinx-version: "7.4" + - python-version: "3.9" + sphinx-version: "7.4" + - python-version: "3.10" + sphinx-version: "7.4" + - python-version: "3.11" + sphinx-version: "7.4" + - python-version: "3.12" + sphinx-version: "5.3" + - python-version: "3.13" + sphinx-version: "5.3" + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install --upgrade pip + pip install django~=${{ matrix.django-version }} + pip install djangorestframework~=${{ matrix.djangorestframework-version }} + pip install sphinx~=${{ matrix.sphinx-version }} + - name: Create example project + run: python create.py + - name: Create configurations file + run: python config.py + - name: Build documentations + run: make --directory docs html + upload-docs: + name: Upload documentations for GitHub Pages + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + django-version: ["4.2"] + djangorestframework-version: ["3.1"] + sphinx-version: ["5.3"] + needs: [lint, test-units, test-docs, build-docs] + if: startsWith(github.ref, 'refs/tags/') + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install --upgrade pip + pip install django~=${{ matrix.django-version }} + pip install djangorestframework~=${{ matrix.djangorestframework-version }} + pip install sphinx~=${{ matrix.sphinx-version }} + - name: Create example project + run: python create.py + - name: Create configurations file + run: python config.py + - name: Build documentations + run: make --directory docs html + - name: Upload built documentations as pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: docs/_build/html + deploy-pypi: + name: Build and deploy package to PyPI + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + needs: [upload-docs] + if: startsWith(github.ref, 'refs/tags/') + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + pip install --upgrade pip + python -m pip install --upgrade pip + pip install build + - name: Create configurations file + run: python config.py + - name: Build package + run: python -m build + - name: Publish package + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + deploy-docs: + name: Deploy documentations to GitHub Pages + runs-on: ubuntu-latest + needs: [deploy-pypi] + if: startsWith(github.ref, 'refs/tags/') + env: + EXAMPLE_ENGINE: sqlite3 + permissions: + pages: write + id-token: write + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fb5c5311..00000000 --- a/.travis.yml +++ /dev/null @@ -1,285 +0,0 @@ -language: python -dist: xenial - -git: - depth: 3 - -branches: - only: - - master - - /^(\d+\.\d+\.\d+)((a|b|rc|\.dev|\.post)(\d+))?$/ - -jobs: - include: - - stage: linting - name: "Flake8" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: pip install flake8~=3.0 - before_script: skip - script: flake8 - - stage: unit test - name: "Python 3.6, Django 2.2, SQLite - Unit Test" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.6, Django 3.0, SQLite - Unit Test" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.6, Django 3.1, SQLite - Unit Test" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.7, Django 2.2, SQLite - Unit Test" - python: 3.7 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.7, Django 3.0, SQLite - Unit Test" - python: 3.7 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.7, Django 3.1, SQLite - Unit Test" - python: 3.7 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.8, Django 2.2, SQLite - Unit Test" - python: 3.8 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.8, Django 3.0, SQLite - Unit Test" - python: 3.8 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.8, Django 3.1, SQLite - Unit Test" - python: 3.8 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.9, Django 2.2, SQLite - Unit Test" - python: 3.9 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.9, Django 3.0, SQLite - Unit Test" - python: 3.9 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - name: "Python 3.9, Django 3.1, SQLite - Unit Test" - python: 3.9 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - before_script: python create.py - script: python project/manage.py test -v 3 - - stage: doc test - name: "Python 3.6, Django 2.2, SQLite - Doc Test" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.6, Django 3.0, SQLite - Doc Test" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.6, Django 3.1, SQLite - Doc Test" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.7, Django 2.2, SQLite - Doc Test" - python: 3.7 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.7, Django 3.0, SQLite - Doc Test" - python: 3.7 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.7, Django 3.1, SQLite - Doc Test" - python: 3.7 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.8, Django 2.2, SQLite - Doc Test" - python: 3.8 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.8, Django 3.0, SQLite - Doc Test" - python: 3.8 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.8, Django 3.1, SQLite - Doc Test" - python: 3.8 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.9, Django 2.2, SQLite - Doc Test" - python: 3.9 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.9, Django 3.0, SQLite - Doc Test" - python: 3.9 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.0.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - name: "Python 3.9, Django 3.1, SQLite - Doc Test" - python: 3.9 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=3.1.0 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs doctest - - stage: deploy - name: "Generate Docs & Upload to GitHub Pages" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: - - pip install django~=2.2 - - pip install djangorestframework~=3.0 - - pip install sphinx - before_script: python create.py && python config.py - script: make --directory docs html - deploy: - provider: pages - skip-cleanup: true - local-dir: docs/_build/html - github-token: $GITHUB_TOKEN - keep-history: true - on: - tags: true - - name: "Build Dists & Upload to PyPI" - python: 3.6 - env: EXAMPLE_ENGINE=sqlite3 - before_install: skip - install: skip - before_script: python config.py - script: skip - deploy: - provider: pypi - skip-cleanup: true - user: bbmokhtari - password: $PYPI_PASSWORD - distributions: "sdist bdist_wheel" - on: - tags: true diff --git a/MANIFEST.in b/MANIFEST.in index 5386136a..2b69c4f2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,7 +7,6 @@ prune tests graft translations exclude .flake8 -exclude .travis.yml exclude beautifier.py exclude config.py exclude create.py diff --git a/config.py b/config.py index 8766b965..e6030a83 100644 --- a/config.py +++ b/config.py @@ -17,7 +17,7 @@ # author author = { 'name': 'Behzad B. Mokhtari', - 'email': 'behzad.public@gmail.com', + 'email': 'bbmokhtari.global@gmail.com', 'github': 'bbmokhtari', } @@ -47,8 +47,12 @@ # ------------------------------------------------------------ Dynamic Content +github_ref = os.environ.get('GITHUB_REF', '') +tag = github_ref.replace("refs/tags/", "") + release = { - 'name': os.environ.get('TRAVIS_TAG', ''), # e.g. `1.0.0rc2` + # e.g. `1.0.0rc2` + 'name': tag, 'version': '', # e.g. `1.0.0` 'status': '', # e.g. `rc` 'classifier': '', # e.g. `5 - Production/Stable` @@ -62,22 +66,24 @@ r'(?:(?Pa|b|rc|\.dev|\.post)(?P\d+))?' + r'$' ) - components = pattern.match(release['name']).groupdict() - release['version'] = components['version'] - release['status'] = components['status'] + components = pattern.match(release['name']) + if components: + components = components.groupdict() + release['version'] = components['version'] + release['status'] = components['status'] - if release['status'] == '.dev': - release['classifier'] = '2 - Pre-Alpha' - elif release['status'] == 'a': - release['classifier'] = '3 - Alpha' - elif release['status'] == 'b': - release['classifier'] = '4 - Beta' - elif release['status'] == 'rc': - release['classifier'] = '5 - Production/Stable' - elif release['status'] is None or release['status'] == '.post': - release['classifier'] = '6 - Mature' - else: - raise Exception('Release must have a development status.') + if release['status'] == '.dev': + release['classifier'] = '2 - Pre-Alpha' + elif release['status'] == 'a': + release['classifier'] = '3 - Alpha' + elif release['status'] == 'b': + release['classifier'] = '4 - Beta' + elif release['status'] == 'rc': + release['classifier'] = '5 - Production/Stable' + elif release['status'] is None or release['status'] == '.post': + release['classifier'] = '6 - Mature' + else: + raise Exception('Release must have a development status.') # --------------------------------------------------------------------- Output diff --git a/docs/contribution.rst b/docs/contribution.rst index 08a893c5..23adc958 100644 --- a/docs/contribution.rst +++ b/docs/contribution.rst @@ -171,7 +171,7 @@ To lint the code: Releasing a version ******************* -Creating a git tag automatically causes Travis CI to: +Creating a git tag automatically causes CI to: - Lint the code - Run unit tests diff --git a/requirements_dev.txt b/requirements_dev.txt index 8eb8190f..2af3ac1c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -Django~=2.2 -Sphinx~=1.0 -flake8~=3.0 -djangorestframework~=3.0 +Django~=4.2 +Sphinx~=5.3 +flake8~=5.0 +djangorestframework~=3.13 diff --git a/sample/models.py b/sample/models.py index 2df2c68e..32d09d7c 100644 --- a/sample/models.py +++ b/sample/models.py @@ -1,5 +1,8 @@ from django.db import models -from django.utils.translation import ugettext_lazy as _ +try: + from django.utils.translation import ugettext_lazy as _ +except ImportError: + from django.utils.translation import gettext_lazy as _ from translations.models import Translatable diff --git a/setup.py b/setup.py index 608195ba..cd3578c6 100644 --- a/setup.py +++ b/setup.py @@ -24,14 +24,23 @@ 'Framework :: Django :: 2.2', 'Framework :: Django :: 3.0', 'Framework :: Django :: 3.1', + 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.0', + 'Framework :: Django :: 4.1', + 'Framework :: Django :: 4.2', + 'Framework :: Django :: 5.0', + 'Framework :: Django :: 5.1', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Topic :: Software Development :: Internationalization', ], keywords=' '.join(info['keywords']), @@ -48,5 +57,5 @@ 'tests', ] ), - python_requires='>=3.6, <4', + python_requires='>=3.7, <4', ) diff --git a/tests/test_admin.py b/tests/test_admin.py index 5cb3a8f6..9d9623f1 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,4 +1,4 @@ -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.contrib.admin import site from sample.models import Timezone, Continent, City @@ -18,7 +18,7 @@ def has_perm(self, perm): request.user = MockSuperUser() -class TranslatableAdminMixinTest(TestCase): +class TranslatableAdminMixinTest(TranslationTestCase): """Tests for `TranslatableAdminMixin`.""" def test_prepare_translation_inlines_fields_automatic(self): diff --git a/tests/test_case.py b/tests/test_case.py new file mode 100644 index 00000000..24d2a4d5 --- /dev/null +++ b/tests/test_case.py @@ -0,0 +1,11 @@ +from django.test import TestCase + + +class TranslationTestCase(TestCase): + """TestCase for Translation.""" + + def assertQuerySetEqual(self, *args, **kwargs) -> None: + if hasattr(super(), "assertQuerySetEqual"): + super().assertQuerySetEqual(*args, **kwargs) + else: + super().assertQuerysetEqual(*args, **kwargs) diff --git a/tests/test_context.py b/tests/test_context.py index efdea6b3..14a841f6 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -1,4 +1,4 @@ -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.utils.translation import override from translations.context import Context @@ -7,7 +7,7 @@ from sample.utils import create_samples -class ContextTest(TestCase): +class ContextTest(TranslationTestCase): """Tests for `Context`.""" def test_init_instance_invalid_entity(self): diff --git a/tests/test_forms.py b/tests/test_forms.py index a5c343e8..fe115430 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -1,11 +1,12 @@ -from django.test import TestCase, override_settings +from django.test import override_settings +from tests.test_case import TranslationTestCase from translations.forms import generate_translation_form from sample.models import Timezone, Continent, City -class GenerateTranslationFormTest(TestCase): +class GenerateTranslationFormTest(TranslationTestCase): def test_field_choices_automatic(self): form = generate_translation_form(City) diff --git a/tests/test_languages.py b/tests/test_languages.py index 73e44a93..20b58baf 100644 --- a/tests/test_languages.py +++ b/tests/test_languages.py @@ -1,4 +1,5 @@ -from django.test import TestCase, override_settings +from django.test import override_settings +from tests.test_case import TranslationTestCase from django.utils.translation import override from translations.languages import _get_supported_language, \ @@ -9,7 +10,7 @@ translate, probe -class GetsupportedLanguageTest(TestCase): +class GetsupportedLanguageTest(TranslationTestCase): """Tests for `_get_supported_language`.""" def test_unaccented(self): @@ -40,7 +41,7 @@ def test_invalid(self): ) -class GetDefaultLanguageTest(TestCase): +class GetDefaultLanguageTest(TranslationTestCase): """Tests for `_get_default_language`.""" @override_settings(LANGUAGE_CODE='en') @@ -75,7 +76,7 @@ def test_invalid(self): ) -class GetActiveLanguageTest(TestCase): +class GetActiveLanguageTest(TranslationTestCase): """Tests for `_get_active_language`.""" @override(language='en', deactivate=True) @@ -110,7 +111,7 @@ def test_invalid(self): ) -class GetAllLanguagesTest(TestCase): +class GetAllLanguagesTest(TranslationTestCase): """Tests for `_get_all_languages`.""" def test_get_all_languages(self): @@ -125,7 +126,7 @@ def test_get_all_languages(self): ) -class GetAllChoicesTest(TestCase): +class GetAllChoicesTest(TranslationTestCase): """Tests for `_get_all_choices`.""" def test_get_all_choices(self): @@ -141,7 +142,7 @@ def test_get_all_choices(self): ) -class GetTranslationLanguagesTest(TestCase): +class GetTranslationLanguagesTest(TranslationTestCase): """Tests for `_get_translation_languages`.""" @override_settings(LANGUAGE_CODE='en') @@ -188,7 +189,7 @@ def test_invalid_default(self): ) -class GetTranslationChoicesTest(TestCase): +class GetTranslationChoicesTest(TranslationTestCase): """Tests for `_get_translation_choices`.""" @override_settings(LANGUAGE_CODE='en') @@ -238,7 +239,7 @@ def test_invalid_default(self): ) -class GetTranslateLanguageTest(TestCase): +class GetTranslateLanguageTest(TranslationTestCase): """Tests for `_get_translate_language`.""" @override(language='en', deactivate=True) @@ -300,7 +301,7 @@ def test_invalid_custom(self): ) -class GetProbeLanguageTest(TestCase): +class GetProbeLanguageTest(TranslationTestCase): """Tests for `_get_probe_language`.""" @override(language='en', deactivate=True) @@ -389,7 +390,7 @@ def test_invalid_custom_list(self): ) -class TranslateTest(TestCase): +class TranslateTest(TranslationTestCase): """Tests for `_TRANSLATE`.""" @override_settings(LANGUAGE_CODE='en') @@ -455,7 +456,7 @@ def test_active_invalid(self): ) -class ProbeTest(TestCase): +class ProbeTest(TranslationTestCase): """Tests for `_PROBE`.""" @override_settings(LANGUAGE_CODE='en') diff --git a/tests/test_management/test_commands/test_synctranslations.py b/tests/test_management/test_commands/test_synctranslations.py index 3134f474..dae2fbde 100644 --- a/tests/test_management/test_commands/test_synctranslations.py +++ b/tests/test_management/test_commands/test_synctranslations.py @@ -2,7 +2,7 @@ from contextlib import ContextDecorator from unittest.mock import patch -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.core.management import call_command from django.contrib.contenttypes.models import ContentType from django.contrib.auth.models import User @@ -67,7 +67,7 @@ def __exit__(self, exc_type, exc_value, traceback): delattr(self.model, '_cached_translatable_fields_names') -class CommandTest(TestCase): +class CommandTest(TranslationTestCase): """Tests for `Command`.""" def test_execute(self): @@ -182,9 +182,10 @@ def test_get_obsolete_translations_no_content_types_no_fields(self): ContentType.objects.none() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), - [] + [], + transform=repr ) def test_get_obsolete_translations_one_content_type_no_fields(self): @@ -203,9 +204,10 @@ def test_get_obsolete_translations_one_content_type_no_fields(self): ContentType.objects.get_for_models(Continent).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), - [] + [], + transform=repr ) def test_get_obsolete_translations_two_content_types_no_fields(self): @@ -224,9 +226,10 @@ def test_get_obsolete_translations_two_content_types_no_fields(self): ContentType.objects.get_for_models(Continent, Country).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), - [] + [], + transform=repr ) def test_get_obsolete_translations_all_content_types_no_fields(self): @@ -245,9 +248,10 @@ def test_get_obsolete_translations_all_content_types_no_fields(self): ContentType.objects.all() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), - [] + [], + transform=repr ) @override_tmeta(Continent, fields=['name']) @@ -269,9 +273,10 @@ def test_get_obsolete_translations_no_content_types_one_field(self): ContentType.objects.none() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), - [] + [], + transform=repr ) @override_tmeta(Continent, fields=['name']) @@ -293,14 +298,15 @@ def test_get_obsolete_translations_one_content_type_one_field(self): ContentType.objects.get_for_models(Continent).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', '', '', '' - ] + ], + transform=repr ) @override_tmeta(Continent, fields=['name']) @@ -322,7 +328,7 @@ def test_get_obsolete_translations_two_content_types_one_field(self): ContentType.objects.get_for_models(Continent, Country).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', @@ -333,7 +339,8 @@ def test_get_obsolete_translations_two_content_types_one_field(self): '', '', '' - ] + ], + transform=repr ) @override_tmeta(Continent, fields=['name']) @@ -355,7 +362,7 @@ def test_get_obsolete_translations_all_content_types_one_field(self): ContentType.objects.all() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', @@ -370,7 +377,8 @@ def test_get_obsolete_translations_all_content_types_one_field(self): '', '', '' - ] + ], + transform=repr ) @override_tmeta(Continent, fields=[]) @@ -392,9 +400,10 @@ def test_get_obsolete_translations_no_content_types_two_fields(self): ContentType.objects.none() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), - [] + [], + transform=repr ) @override_tmeta(Continent, fields=[]) @@ -416,7 +425,7 @@ def test_get_obsolete_translations_one_content_type_two_fields(self): ContentType.objects.get_for_models(Continent).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', @@ -427,7 +436,8 @@ def test_get_obsolete_translations_one_content_type_two_fields(self): '', '', '' - ] + ], + transform=repr ) @override_tmeta(Continent, fields=[]) @@ -449,7 +459,7 @@ def test_get_obsolete_translations_two_content_types_two_fields(self): ContentType.objects.get_for_models(Continent, Country).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', @@ -468,7 +478,8 @@ def test_get_obsolete_translations_two_content_types_two_fields(self): '', '', '' - ] + ], + transform=repr ) @override_tmeta(Continent, fields=[]) @@ -490,7 +501,7 @@ def test_get_obsolete_translations_all_content_types_two_fields(self): ContentType.objects.all() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', @@ -517,7 +528,8 @@ def test_get_obsolete_translations_all_content_types_two_fields(self): '', '', '' - ] + ], + transform=repr ) def test_get_obsolete_translations_one_content_type_not_trans(self): @@ -535,11 +547,12 @@ def test_get_obsolete_translations_one_content_type_not_trans(self): ContentType.objects.get_for_models(User).values() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', - ] + ], + transform=repr ) def test_get_obsolete_translations_all_content_types_not_trans(self): @@ -557,11 +570,12 @@ def test_get_obsolete_translations_all_content_types_not_trans(self): ContentType.objects.all() ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( obsolete_translations.order_by('id'), [ '', - ] + ], + transform=repr ) def test_log_obsolete_translations_no_content_types_no_fields(self): diff --git a/tests/test_models.py b/tests/test_models.py index 3d2985d9..f1562e46 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,4 @@ -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.contrib.contenttypes.models import ContentType from django.db import utils @@ -8,7 +8,7 @@ from sample.utils import create_samples -class TranslationTest(TestCase): +class TranslationTest(TranslationTestCase): """Tests for `Translation`.""" def test_content_type_none(self): @@ -160,7 +160,7 @@ def test_uniqueness(self): ) -class TranslatableTest(TestCase): +class TranslatableTest(TranslationTestCase): """Tests for `Translatable`.""" def test_one_translations_rel(self): @@ -172,12 +172,13 @@ def test_one_translations_rel(self): europe = Continent.objects.get(code='EU') - self.assertQuerysetEqual( + self.assertQuerySetEqual( europe.translations.order_by('id'), [ '', '', - ] + ], + transform=repr ) def test_two_translations_rel(self): @@ -190,19 +191,21 @@ def test_two_translations_rel(self): europe = Continent.objects.get(code='EU') asia = Continent.objects.get(code='AS') - self.assertQuerysetEqual( + self.assertQuerySetEqual( europe.translations.order_by('id'), [ '', '', - ] + ], + transform=repr ) - self.assertQuerysetEqual( + self.assertQuerySetEqual( asia.translations.order_by('id'), [ '', '', - ] + ], + transform=repr ) def test_get_translatable_fields_automatic(self): diff --git a/tests/test_query.py b/tests/test_query.py index 13329aa1..32c310c6 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -1,6 +1,6 @@ import copy -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.db.models import Q from django.utils.translation import override @@ -9,7 +9,7 @@ from sample.models import Continent -class FetchTranslationsQueryGetterTest(TestCase): +class FetchTranslationsQueryGetterTest(TranslationTestCase): """Tests for `_fetch_translations_query_getter`.""" def test_lookup_nrel_yfield_ntrans_nsupp_strlang(self): @@ -2373,8 +2373,8 @@ def test_tq_yrel_nfield_nsupp_listlangdef(self): countries=1, )( ['en', 'de'] - ) - ).children[0].children[0].children, + ) + ).children[0].children[0].children, [ ('countries', 1), ] @@ -2545,7 +2545,7 @@ def test_tq_yrelnested_yfield_ytrans_ysupp_listlangdef(self): ) -class TQTest(TestCase): +class TQTest(TranslationTestCase): """Tests for `_fetch_translations_query_getter`.""" def test_init(self): diff --git a/tests/test_querysets.py b/tests/test_querysets.py index 1f525540..513dfc2e 100644 --- a/tests/test_querysets.py +++ b/tests/test_querysets.py @@ -1,4 +1,5 @@ -from django.test import TestCase, override_settings +from django.test import override_settings +from tests.test_case import TranslationTestCase from django.db.models import Q from django.utils.translation import override @@ -6,7 +7,7 @@ from sample.utils import create_samples -class TranslatableQuerySetTest(TestCase): +class TranslatableQuerySetTest(TranslationTestCase): """Tests for `TranslatableQuerySet`.""" @override_settings(LANGUAGE_CODE='en-us') @@ -69,7 +70,7 @@ def test_fetch_all_get_level_0_relation_no_lang(self): ) europe = Continent.objects.translate( - ).get(code='EU') + ).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -95,7 +96,7 @@ def test_fetch_all_get_level_1_relation_no_lang(self): lvl_1 = ('countries',) europe = Continent.objects.translate( - ).translate_related( + ).translate_related( *lvl_1).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -122,7 +123,7 @@ def test_fetch_all_get_level_2_relation_no_lang(self): lvl_2 = ('countries__cities',) europe = Continent.objects.translate( - ).translate_related( + ).translate_related( *lvl_2).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -149,7 +150,7 @@ def test_fetch_all_get_level_1_2_relation_no_lang(self): lvl_1_2 = ('countries', 'countries__cities',) europe = Continent.objects.translate( - ).translate_related( + ).translate_related( *lvl_1_2).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -278,7 +279,7 @@ def test_fetch_all_prefetched_get_level_0_relation_no_lang(self): europe = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).get(code='EU') + ).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -306,7 +307,7 @@ def test_fetch_all_prefetched_get_level_1_relation_no_lang(self): europe = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related( + ).translate_related( *lvl_1).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -335,7 +336,7 @@ def test_fetch_all_prefetched_get_level_2_relation_no_lang(self): europe = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related( + ).translate_related( *lvl_2).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -363,7 +364,7 @@ def test_fetch_all_prefetched_get_level_1_2_relation_no_lang(self): europe = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related( + ).translate_related( *lvl_1_2).get(code='EU') germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -532,7 +533,7 @@ def test_fetch_all_all_level_1_relation_no_lang(self): lvl_1 = ('countries',) continents = Continent.objects.translate( - ).translate_related(*lvl_1) + ).translate_related(*lvl_1) europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -568,7 +569,7 @@ def test_fetch_all_all_level_2_relation_no_lang(self): lvl_2 = ('countries__cities',) continents = Continent.objects.translate( - ).translate_related(*lvl_2) + ).translate_related(*lvl_2) europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -604,7 +605,7 @@ def test_fetch_all_all_level_1_2_relation_no_lang(self): lvl_1_2 = ('countries', 'countries__cities',) continents = Continent.objects.translate( - ).translate_related(*lvl_1_2) + ).translate_related(*lvl_1_2) europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -815,7 +816,7 @@ def test_fetch_all_prefetched_all_level_1_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related(*lvl_1) + ).translate_related(*lvl_1) europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -853,7 +854,7 @@ def test_fetch_all_prefetched_all_level_2_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related(*lvl_2) + ).translate_related(*lvl_2) europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -890,7 +891,7 @@ def test_fetch_all_prefetched_all_level_1_2_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related(*lvl_1_2) + ).translate_related(*lvl_1_2) europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -1677,7 +1678,7 @@ def test_fetch_all_decipher_level_0_relation_no_lang(self): ) continents = Continent.objects.translate( - ).translate('en-us') + ).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -1713,7 +1714,7 @@ def test_fetch_all_decipher_level_1_relation_no_lang(self): lvl_1 = ('countries',) continents = Continent.objects.translate( - ).translate_related( + ).translate_related( *lvl_1).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] @@ -1750,7 +1751,7 @@ def test_fetch_all_decipher_level_2_relation_no_lang(self): lvl_2 = ('countries__cities',) continents = Continent.objects.translate( - ).translate_related( + ).translate_related( *lvl_2).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] @@ -1787,7 +1788,7 @@ def test_fetch_all_decipher_level_1_2_relation_no_lang(self): lvl_1_2 = ('countries', 'countries__cities',) continents = Continent.objects.translate( - ).translate_related( + ).translate_related( *lvl_1_2).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] @@ -1966,7 +1967,7 @@ def test_fetch_all_prefetched_decipher_level_0_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate('en-us') + ).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] cologne = germany.cities.all()[0] @@ -2004,7 +2005,7 @@ def test_fetch_all_prefetched_decipher_level_1_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related( + ).translate_related( *lvl_1).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] @@ -2043,7 +2044,7 @@ def test_fetch_all_prefetched_decipher_level_2_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related( + ).translate_related( *lvl_2).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] @@ -2081,7 +2082,7 @@ def test_fetch_all_prefetched_decipher_level_1_2_relation_no_lang(self): continents = Continent.objects.prefetch_related( *lvl_1_2).translate( - ).translate_related( + ).translate_related( *lvl_1_2).translate('en-us') europe = [x for x in continents if x.code == 'EU'][0] germany = europe.countries.all()[0] diff --git a/tests/test_utils.py b/tests/test_utils.py index 25daabca..2cf2917d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,4 @@ -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.core.exceptions import FieldDoesNotExist from django.contrib.contenttypes.models import ContentType @@ -10,7 +10,7 @@ from sample.utils import create_samples -class GetReverseRelationTest(TestCase): +class GetReverseRelationTest(TranslationTestCase): """Tests for `_get_reverse_relation`.""" def test_simple_relation(self): @@ -65,7 +65,7 @@ def test_invalid_nested_relation(self): ) -class GetDissectedLookupTest(TestCase): +class GetDissectedLookupTest(TranslationTestCase): """Tests for `_get_dissected_lookup`.""" def test_nrel_yfield_ntranslatable_nlookup(self): @@ -226,7 +226,7 @@ def test_ynestedrel_yfield_ytranslatable_ylookup(self): ) -class GetRelationsHierarchyTest(TestCase): +class GetRelationsHierarchyTest(TranslationTestCase): """Tests for `_get_relations_hierarchy`.""" def test_level_0_relation(self): @@ -487,7 +487,7 @@ def test_many_included_level_1_and_many_nested_level_2_relations(self): ) -class GetEntityDetailsTest(TestCase): +class GetEntityDetailsTest(TranslationTestCase): """Tests for `_get_entity_details`.""" def test_iterable(self): @@ -581,7 +581,7 @@ def __repr__(self): ) -class GetPurviewTest(TestCase): +class GetPurviewTest(TranslationTestCase): """Tests for `_get_purview`.""" def test_instance_level_0_relation(self): @@ -1221,7 +1221,7 @@ def __repr__(self): ) -class GetTranslationsTest(TestCase): +class GetTranslationsTest(TranslationTestCase): """Tests for `_get_translations`.""" def test_instance_level_0_relation_with_lang(self): @@ -1239,12 +1239,13 @@ def test_instance_level_0_relation_with_lang(self): hierarchy = _get_relations_hierarchy() mapping, query = _get_purview(europe, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', '', - ] + ], + transform=repr ) def test_instance_level_1_relation_with_lang(self): @@ -1264,14 +1265,15 @@ def test_instance_level_1_relation_with_lang(self): hierarchy = _get_relations_hierarchy(*lvl_1) mapping, query = _get_purview(europe, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', '', '', '', - ] + ], + transform=repr ) def test_instance_level_2_relation_with_lang(self): @@ -1291,14 +1293,15 @@ def test_instance_level_2_relation_with_lang(self): hierarchy = _get_relations_hierarchy(*lvl_2) mapping, query = _get_purview(europe, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', '', '', '', - ] + ], + transform=repr ) def test_instance_level_1_2_relation_with_lang(self): @@ -1318,7 +1321,7 @@ def test_instance_level_1_2_relation_with_lang(self): hierarchy = _get_relations_hierarchy(*lvl_1_2) mapping, query = _get_purview(europe, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', @@ -1327,7 +1330,8 @@ def test_instance_level_1_2_relation_with_lang(self): '', '', '', - ] + ], + transform=repr ) def test_queryset_level_0_relation_with_lang(self): @@ -1345,14 +1349,15 @@ def test_queryset_level_0_relation_with_lang(self): hierarchy = _get_relations_hierarchy() mapping, query = _get_purview(continents, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', '', '', '', - ] + ], + transform=repr ) def test_queryset_level_1_relation_with_lang(self): @@ -1372,7 +1377,7 @@ def test_queryset_level_1_relation_with_lang(self): hierarchy = _get_relations_hierarchy(*lvl_1) mapping, query = _get_purview(continents, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', @@ -1383,7 +1388,8 @@ def test_queryset_level_1_relation_with_lang(self): '', '', '', - ] + ], + transform=repr ) def test_queryset_level_2_relation_with_lang(self): @@ -1403,7 +1409,7 @@ def test_queryset_level_2_relation_with_lang(self): hierarchy = _get_relations_hierarchy(*lvl_2) mapping, query = _get_purview(continents, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', @@ -1414,7 +1420,8 @@ def test_queryset_level_2_relation_with_lang(self): '', '', '', - ] + ], + transform=repr ) def test_queryset_level_1_2_relation_with_lang(self): @@ -1434,7 +1441,7 @@ def test_queryset_level_1_2_relation_with_lang(self): hierarchy = _get_relations_hierarchy(*lvl_1_2) mapping, query = _get_purview(continents, hierarchy) - self.assertQuerysetEqual( + self.assertQuerySetEqual( _get_translations(query, 'de').order_by('id'), [ '', @@ -1449,5 +1456,6 @@ def test_queryset_level_1_2_relation_with_lang(self): '', '', '', - ] + ], + transform=repr ) diff --git a/tests/test_views.py b/tests/test_views.py index 918311b6..e50ccd10 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,13 +1,13 @@ import json -from django.test import TestCase +from tests.test_case import TranslationTestCase from django.urls import reverse from sample.models import Continent from sample.utils import create_samples -class GetContinentListTest(TestCase): +class GetContinentListTest(TranslationTestCase): """Tests for `get_continent_list`.""" def test_fallback(self): @@ -215,7 +215,7 @@ def test_accent_not_exists(self): ) -class GetContinentDetailTest(TestCase): +class GetContinentDetailTest(TranslationTestCase): """Tests for `get_continent_detail`.""" def test_fallback(self):