Skip to content

Commit 9003f7e

Browse files
authored
Merge pull request #87 from browniebroke/ci/setup-gh-actions
Bootstrap test infrastructure and add a very basic test
2 parents c84c876 + 771c00f commit 9003f7e

File tree

11 files changed

+124
-11
lines changed

11 files changed

+124
-11
lines changed

.github/workflows/test.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: "3.12"
15+
- uses: pre-commit/[email protected]
16+
- uses: pre-commit-ci/[email protected]
17+
if: always()
18+
19+
test:
20+
runs-on: ubuntu-latest
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
python-version:
25+
- "3.8"
26+
- "3.9"
27+
- "3.10"
28+
- "3.11"
29+
- "3.12"
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-python@v5
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- run: python -m pip install tox
36+
- run: tox -f py$(echo ${{ matrix.python-version }} | tr -d .)

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ Desktop.ini
3333

3434
# Coverage
3535
htmlcov/
36+
.coverage

.pre-commit-config.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: check-case-conflict
6+
- id: check-merge-conflict
7+
- id: check-symlinks
8+
- id: check-json
9+
- id: check-toml
10+
- id: check-yaml
11+
- id: debug-statements
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ To upgrade to `drf_excel` 2.0.0 from `drf_renderer_xlsx`, update your import pat
5656
* `drf_renderer_xlsx.renderers.XLSXRenderer` becomes `drf_excel.renderers.XLSXRenderer`.
5757
* `xlsx_date_format_mappings` has been removed in favor of `column_data_styles` which provides more flexibility
5858

59-
## Configuring Styles
59+
## Configuring Styles
6060

6161
Styles can be added to your worksheet header, column header row, body and column data from view attributes `header`, `column_header`, `body`, `column_data_styles`. Any arguments from [the OpenPyXL package](https://openpyxl.readthedocs.io/en/stable/styles.html) can be used for font, alignment, fill and border_side (border will always be all side of cell).
6262

@@ -148,7 +148,7 @@ def get_header(self):
148148
datetime_format = "%H:%M:%S %d.%m.%Y"
149149
return {
150150
'tab_title': 'MyReport', # title of tab/workbook
151-
'use_header': True, # show the header_title
151+
'use_header': True, # show the header_title
152152
'header_title': 'Report from {} to {}'.format(
153153
start_time.strftime(datetime_format),
154154
end_time.strftime(datetime_format),
@@ -200,7 +200,7 @@ They can be set in the view as a property `sheet_view_options`:
200200
```python
201201
class MyExampleViewSet(serializers.Serializer):
202202
sheet_view_options = {
203-
'rightToLeft': True,
203+
'rightToLeft': True,
204204
'showGridLines': False
205205
}
206206
```
@@ -209,18 +209,18 @@ or using method `get_sheet_view_options`:
209209

210210
```python
211211
class MyExampleViewSet(serializers.Serializer):
212-
212+
213213
def get_sheet_view_options(self):
214214
return {
215-
'rightToLeft': True,
215+
'rightToLeft': True,
216216
'showGridLines': False
217217
}
218218
```
219219
## Controlling XLSX headers and values
220220

221221
### Use Serializer Field labels as header names
222222

223-
By default, headers will use the same 'names' as they are returned by the API. This can be changed by setting `xlsx_use_labels = True` inside your API View.
223+
By default, headers will use the same 'names' as they are returned by the API. This can be changed by setting `xlsx_use_labels = True` inside your API View.
224224

225225
Instead of using the field names, the export will use the labels as they are defined inside your Serializer. A serializer field defined as `title = serializers.CharField(label=_("Some title"))` would return `Some title` instead of `title`, also supporting translations. If no label is set, it will fall back to using `title`.
226226

@@ -248,9 +248,9 @@ DRF_EXCEL_DECIMAL_FORMAT = '0.00E+00'
248248

249249
### Name boolean values
250250

251-
`True` and `False` as values for boolean fields are not always the best representation and don't support translation.
251+
`True` and `False` as values for boolean fields are not always the best representation and don't support translation.
252252

253-
This can be controlled with in you API view with `xlsx_boolean_labels`.
253+
This can be controlled with in you API view with `xlsx_boolean_labels`.
254254

255255
```
256256
xlsx_boolean_labels = {True: _('Yes'), False: _('No')}
@@ -282,7 +282,7 @@ def custom_value_formatter(val):
282282
return val + '!!!'
283283

284284
### Example response:
285-
{
285+
{
286286
results: [
287287
{
288288
title: 'XLSX renderer',

drf_excel/renderers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def _save_virtual_workbook(self, wb):
232232
with TemporaryFile() as tmp:
233233
save_workbook(wb, tmp)
234234
tmp.seek(0)
235-
virtual_workbook = tmp.read()
235+
virtual_workbook = tmp.read()
236236

237237
return virtual_workbook
238238

@@ -380,7 +380,7 @@ def _drf_to_xlsx_field(self, key, value) -> XLSXField:
380380
elif isinstance(field, (IntegerField, FloatField, DecimalField)):
381381
return XLSXNumberField(**kwargs)
382382
elif isinstance(field, (DateTimeField, DateField, TimeField)):
383-
return XLSXDateField(**kwargs)
383+
return XLSXDateField(**kwargs)
384384
elif (
385385
isinstance(field, ListField)
386386
or isinstance(value, Iterable)

tests/__init__.py

Whitespace-only changes.

tests/settings.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import annotations
2+
3+
SECRET_KEY = "NOTASECRET" # noqa S105
4+
5+
DATABASES = {
6+
"default": {
7+
"ENGINE": "django.db.backends.sqlite3",
8+
"NAME": ":memory:",
9+
"ATOMIC_REQUESTS": True,
10+
},
11+
}
12+
13+
USE_TZ = True
14+
TIME_ZONE = "UTC"
15+
16+
INSTALLED_APPS = [
17+
"django.contrib.auth",
18+
"django.contrib.admin",
19+
"django.contrib.contenttypes",
20+
"rest_framework",
21+
"tests.testapp",
22+
]
23+
24+
REST_FRAMEWORK = {
25+
"DEFAULT_RENDERER_CLASSES": (
26+
"rest_framework.renderers.JSONRenderer",
27+
"rest_framework.renderers.BrowsableAPIRenderer",
28+
"drf_excel.renderers.XLSXRenderer",
29+
),
30+
}

tests/test_utilities.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from drf_excel.utilities import get_setting
2+
3+
4+
def test_get_setting_not_found():
5+
assert get_setting("INTEGER_FORMAT") is None

tests/testapp/__init__.py

Whitespace-only changes.

tests/testapp/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class TestAppConfig(AppConfig):
5+
name = "tests.testapp"
6+
verbose_name = "Test App"

tox.ini

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[tox]
2+
envlist =
3+
py{38,39,310,311}-dj42
4+
py{310,311,312}-dj50
5+
py{310,311,312}-dj51
6+
skipsdist = True
7+
8+
[testenv]
9+
deps =
10+
dj42: Django>=4.2,<5.0
11+
dj50: Django>=5.0,<5.1
12+
dj51: Django>=5.1,<5.2
13+
14+
djangorestframework
15+
openpyxl
16+
17+
pytest
18+
pytest-django
19+
pytest-cov
20+
django-coverage-plugin
21+
22+
commands = {posargs:python -m pytest}

0 commit comments

Comments
 (0)