Skip to content

Commit

Permalink
Merge pull request #83 from cuenca-mx/fix-enums
Browse files Browse the repository at this point in the history
Fix IntEnum values
  • Loading branch information
rogelioLpz authored Oct 9, 2023
2 parents f6128be + 834be8c commit 4e16bc5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
name: release

on: push
on:
release:
types: [published]

jobs:
publish-pypi:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/mongoengine_plus
permissions:
id-token: write
steps:
- uses: actions/checkout@master
- name: Set up Python 3.8
Expand All @@ -15,9 +23,7 @@ jobs:
run: pip install -qU setuptools wheel twine
- name: Generating distribution archives
run: python setup.py sdist bdist_wheel
- name: Publish distribution 📦 to PyPI
if: startsWith(github.event.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: ${{ secrets.PYPI_USERNAME }}
password: ${{ secrets.PYPI_PASSWORD }}
user: __token__
2 changes: 1 addition & 1 deletion mongoengine_plus/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def mongo_to_dict(obj, exclude_fields: list = None) -> dict:
elif isinstance(obj._fields[field_name], DictField):
return_data[field_name] = data
elif isinstance(obj._fields[field_name], EnumField):
return_data[field_name] = data.value if data else None
return_data[field_name] = data.value if data is not None else None
elif isinstance(obj._fields[field_name], LazyReferenceField):
return_data[f'{field_name}_uri'] = (
f'/{data._DBRef__collection}/{data.id}' if data else None
Expand Down
2 changes: 1 addition & 1 deletion mongoengine_plus/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.1.1'
8 changes: 8 additions & 0 deletions tests/models/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class EnumType(Enum):
member = 'name'


class IntEnum(int, Enum):
exito = 0
invalid = 1


class Embedded(EmbeddedDocument):
meta = {'allow_inheritance': True}
name = StringField()
Expand Down Expand Up @@ -59,6 +64,7 @@ class TestModel(Document):
lazzy_field = LazyReferenceField(Reference)
lazzy_list_field = ListField(LazyReferenceField(Reference))
generic_lazzy_field = GenericLazyReferenceField()
code = EnumField(IntEnum)

__test__ = False

Expand All @@ -71,6 +77,7 @@ def test_mongo_to_dict():
lazzy_list_field=[reference],
embedded_field=Embedded(name='Peter'),
heritage_field=HeritageEmbedded(name='some', lastname='other'),
code=IntEnum.exito,
)
model.save()
model_dict = mongo_to_dict(model, exclude_fields=['str_field'])
Expand All @@ -95,3 +102,4 @@ def test_mongo_to_dict():
'name': 'some',
'lastname': 'other',
}
assert model_dict['code'] == 0

0 comments on commit 4e16bc5

Please sign in to comment.