Skip to content

Commit

Permalink
chore: added Django 5 tox tests, switched from black to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
cordery committed Jan 11, 2024
1 parent e08125d commit b6000ee
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 385 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.9', '3.10', '3.11' ]
django-version: [ ">=3,<4", ">=4,<5" ]
python-version: [ '3.10', '3.11', '3.12' ]
django-version: [ ">=3,<4", ">=4,<5", ">=5,<6" ]

steps:
#----------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions .python-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
3.9.16
3.10.9
3.11.1
3.10
3.11
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [2.1]

### Added

- Added support and tests for Django 5.0 (thanks Akay7)


## [2.0]

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Requirements
---------------------------------------
django-countries-plus >= 1.

Django: Tested against the LTS versions of 3, 4, and the latests of 5.
Django: Tested against the LTS versions of 3, 4, and the latest of 5.
Python 3


Expand Down
638 changes: 293 additions & 345 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ tox = "^4"

[tool.poetry.group.dev.dependencies]
bump2version = "^1.0.1"
black = "^22.1.0"
ruff = "^0.1.11"


[tool.ruff.format]
exclude = ["**/migrations/*"]


[build-system]
requires = ["poetry_core>=1.0.0"]
Expand Down
52 changes: 26 additions & 26 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class TestLanguages(TestCase):
fixtures = ['countries_data.json.gz', 'languages_data.json.gz']
fixtures = ["countries_data.json.gz", "languages_data.json.gz"]

@classmethod
def setUpTestData(cls):
Expand All @@ -17,63 +17,63 @@ def test_language_count(self):
self.assertEqual(language_count, 184)

def test_get_language_by_pk(self):
language = Language.objects.get(pk='en')
self.assertEqual(language.name_en, 'English')
language = Language.objects.get(pk="en")
self.assertEqual(language.name_en, "English")

def test_get_by_code(self):
language = Language.objects.get_by_code('iu')
self.assertEqual(language.name_en, 'Inuktitut')
language = Language.objects.get_by_code("iu")
self.assertEqual(language.name_en, "Inuktitut")

def test_language__str__(self):
language = Language.objects.get(pk='es')
self.assertEqual(str(language), 'Spanish; Castilian')
language = Language.objects.get(pk="es")
self.assertEqual(str(language), "Spanish; Castilian")

def test_get_culture_pair(self):
language, country = Language.objects.get_culture_pair('en-CA')
self.assertEqual(str(language), 'English')
self.assertEqual(str(country), 'Canada')
language, country = Language.objects.get_culture_pair("en-CA")
self.assertEqual(str(language), "English")
self.assertEqual(str(country), "Canada")

def test_filter_by_codes(self):
canada = Country.objects.get(name='Canada')
codes = canada.languages.split(',')
canada = Country.objects.get(name="Canada")
codes = canada.languages.split(",")
langs = Language.objects.filter_by_codes(codes)
self.assertEqual(langs, [Language.objects.get(pk=x.split('-')[0]) for x in codes])
self.assertEqual(
langs, [Language.objects.get(pk=x.split("-")[0]) for x in codes]
)
langs = {x.pk: x for x in langs}
self.assertEqual(langs['en'].country, canada)
self.assertEqual(langs['en'].culturecode, 'en-CA')
self.assertEqual(langs["en"].country, canada)
self.assertEqual(langs["en"].culturecode, "en-CA")


class TestCultureCode(TestCase):
fixtures = ['countries_data.json.gz', 'languages_data.json.gz']
fixtures = ["countries_data.json.gz", "languages_data.json.gz"]

@classmethod
def setUpTestData(cls):
associate_countries_and_languages()

def test_get_as_languages(self):
languages = CultureCode.objects.filter(pk='en-CA').as_languages()
languages = CultureCode.objects.filter(pk="en-CA").as_languages()
self.assertIsInstance(languages[0], Language)
self.assertEqual(languages[0].country, Country.objects.get(name='Canada'))
self.assertEqual(languages[0].culturecode, 'en-CA')
self.assertEqual(languages[0].country, Country.objects.get(name="Canada"))
self.assertEqual(languages[0].culturecode, "en-CA")


class TestCountry(TestCase):
fixtures = ['countries_data.json.gz', 'languages_data.json.gz']
fixtures = ["countries_data.json.gz", "languages_data.json.gz"]

@classmethod
def setUpTestData(cls):
associate_countries_and_languages()

def test_primary_language(self):
uk = Country.objects.get(name='United Kingdom')
self.assertEqual(uk.primary_language(), Language.objects.get(pk='en'))
uk = Country.objects.get(name="United Kingdom")
self.assertEqual(uk.primary_language(), Language.objects.get(pk="en"))

def test_get_all_languages(self):
canada = Country.objects.get(pk='CA')
canada = Country.objects.get(pk="CA")
languages = canada.get_all_languages()
results = {'en': 'English',
'fr': 'French',
'iu': 'Inuktitut'}
results = {"en": "English", "fr": "French", "iu": "Inuktitut"}
self.assertEqual(len(results), len(languages))
for language in languages:
self.assertEqual(results[language.iso], str(language.name_en))
13 changes: 6 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class TestAssociation(TestCase):
fixtures = ['countries_data.json.gz', 'languages_data.json.gz']
fixtures = ["countries_data.json.gz", "languages_data.json.gz"]

@classmethod
def setUpTestData(cls):
Expand All @@ -20,14 +20,13 @@ def test_count(self):
self.assertEqual(culture_code_count, 235)

def test_get_culture_code(self):
culture_code = CultureCode.objects.get(pk='en-CA')
self.assertEqual(culture_code.country.name, 'Canada')
self.assertEqual(culture_code.language.name, 'English')
culture_code = CultureCode.objects.get(pk="en-CA")
self.assertEqual(culture_code.country.name, "Canada")
self.assertEqual(culture_code.language.name, "English")

def test_get_languages_for_country(self):
culture_codes = CultureCode.objects.filter(country__name='Canada')
results = {'en-CA': 'English',
'fr-CA': 'French'}
culture_codes = CultureCode.objects.filter(country__name="Canada")
results = {"en-CA": "English", "fr-CA": "French"}
self.assertEqual(len(results), len(culture_codes))
for culture_code in culture_codes:
self.assertEqual(results[culture_code.code], str(culture_code.language))

0 comments on commit b6000ee

Please sign in to comment.