Skip to content

Commit c409e05

Browse files
authored
Merge pull request pallets-eco#2169 from michaelbukachi/setup_actions
Migrate to github actions
2 parents 27185e9 + 0680a25 commit c409e05

File tree

8 files changed

+92
-25
lines changed

8 files changed

+92
-25
lines changed

.github/workflows/test.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Run tests
2+
on:
3+
- pull_request
4+
- push
5+
6+
jobs:
7+
test-job:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
12+
tox-version: [ 'WTForms2' ]
13+
include:
14+
- python-version: 3.6
15+
tox-version: flake8
16+
- python-version: 3.6
17+
tox-version: docs-html
18+
services:
19+
# Label used to access the service container
20+
postgres:
21+
# Docker Hub image
22+
image: postgis/postgis:12-master # postgres with postgis installed
23+
# Provide the password for postgres
24+
env:
25+
POSTGRES_PASSWORD: postgres
26+
POSTGRES_DB: flask_admin_test
27+
ports:
28+
- 5432:5432
29+
# Set health checks to wait until postgres has started
30+
options: >-
31+
--health-cmd pg_isready
32+
--health-interval 10s
33+
--health-timeout 5s
34+
--health-retries 5
35+
mongo:
36+
image: mongo:3.1
37+
ports:
38+
- 27017:27017
39+
azurite:
40+
image: arafato/azurite:2.6.5
41+
env:
42+
executable: blob
43+
ports:
44+
- 10000:10000
45+
steps:
46+
# Downloads a copy of the code in your repository before running CI tests
47+
- name: Check out repository code
48+
uses: actions/checkout@v2
49+
- name: Install postgis
50+
run: sudo apt-get install -y postgis postgresql-12-postgis-3 postgresql-12-postgis-3-scripts
51+
- name: Setup postgis
52+
env:
53+
PGPASSWORD: postgres
54+
run: psql -U postgres -h localhost -c 'CREATE EXTENSION hstore;' flask_admin_test
55+
- name: Set up Python
56+
uses: actions/setup-python@v2
57+
with:
58+
python-version: ${{ matrix.python-version }}
59+
- name: Install tox
60+
run: pip install tox
61+
- name: Run tests
62+
run: tox -e ${{ matrix.tox-version }}

flask_admin/contrib/sqla/form.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def conv_String(self, column, field_args, **extra):
282282
@converts('sqlalchemy.sql.sqltypes.Enum')
283283
def convert_enum(self, column, field_args, **extra):
284284
available_choices = [(f, f) for f in column.type.enums]
285-
accepted_values = [key for key, val in available_choices]
285+
accepted_values = [choice[0] for choice in available_choices]
286286

287287
if column.nullable:
288288
field_args['allow_blank'] = column.nullable
@@ -304,7 +304,7 @@ def convert_choice_type(self, column, field_args, **extra):
304304
available_choices = [(f.value, f.name) for f in column.type.choices]
305305
else:
306306
available_choices = column.type.choices
307-
accepted_values = [key for key, val in available_choices]
307+
accepted_values = [choice[0] if isinstance(choice, tuple) else choice.value for choice in available_choices]
308308

309309
if column.nullable:
310310
field_args['allow_blank'] = column.nullable

flask_admin/form/fields.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ def iter_choices(self):
121121
if self.allow_blank:
122122
yield (u'__None', self.blank_text, self.data is None)
123123

124-
for value, label in self.choices:
125-
yield (value, label, self.coerce(value) == self.data)
124+
for choice in self.choices:
125+
if isinstance(choice, tuple):
126+
yield (choice[0], choice[1], self.coerce(choice[0]) == self.data)
127+
else:
128+
yield (choice.value, choice.name, self.coerce(choice.value) == self.data)
126129

127130
def process_data(self, value):
128131
if value is None:

flask_admin/tests/geoa/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def setup():
77
app = Flask(__name__)
88
app.config['SECRET_KEY'] = '1'
99
app.config['CSRF_ENABLED'] = False
10-
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/flask_admin_test'
10+
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:postgres@localhost/flask_admin_test'
1111
app.config['SQLALCHEMY_ECHO'] = True
1212
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
1313

flask_admin/tests/geoa/test_basic.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import re
44

5+
56
from flask_admin.contrib.geoa import ModelView
67
from flask_admin.contrib.geoa.fields import GeoJSONField
78
from geoalchemy2 import Geometry
@@ -74,14 +75,14 @@ def test_model():
7475
assert to_shape(model.point).geom_type == "Point"
7576
assert list(to_shape(model.point).coords) == [(125.8, 10.0,)]
7677
assert to_shape(model.line).geom_type == "LineString"
77-
assert list(to_shape(model.line).coords) == [(50.2345, 94.2, (50.21, 94.87)])
78+
assert list(to_shape(model.line).coords) == [(50.2345, 94.2), (50.21, 94.87)]
7879
assert to_shape(model.polygon).geom_type == "Polygon"
79-
eq_(list(to_shape(model.polygon).exterior.coords),
80-
[(100.0, 0.0), (101.0, 0.0), (101.0, 1.0), (100.0, 1.0), (100.0, 0.0)])
80+
assert list(to_shape(model.polygon).exterior.coords) == \
81+
[(100.0, 0.0), (101.0, 0.0), (101.0, 1.0), (100.0, 1.0), (100.0, 0.0)]
8182
assert to_shape(model.multi).geom_type == "MultiPoint"
8283
assert len(to_shape(model.multi).geoms) == 2
83-
assert list(to_shape(model.multi).geoms[0].coords) == [(100.0, 0.0])
84-
assert list(to_shape(model.multi).geoms[1].coords) == [(101.0, 1.0])
84+
assert list(to_shape(model.multi).geoms[0].coords) == [(100.0, 0.0)]
85+
assert list(to_shape(model.multi).geoms[1].coords) == [(101.0, 1.0)]
8586

8687
rv = client.get('/admin/geomodel/')
8788
assert rv.status_code == 200

flask_admin/tests/sqla/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup_postgres():
2121
app = Flask(__name__)
2222
app.config['SECRET_KEY'] = '1'
2323
app.config['CSRF_ENABLED'] = False
24-
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/flask_admin_test'
24+
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres:postgres@localhost/flask_admin_test'
2525
app.config['SQLALCHEMY_ECHO'] = True
2626
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
2727

flask_admin/tests/test_base.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from flask import Flask, request, abort, url_for
66
from flask.views import MethodView
7+
78
from flask_admin import base
89

910

@@ -233,23 +234,23 @@ def test_add_category():
233234
admin.add_view(MockView(name='Test 1', endpoint='test1', category='Category1'))
234235
admin.add_view(MockView(name='Test 2', endpoint='test2', category='Category2'))
235236

236-
eq_(len(admin.menu()), 3)
237+
assert len(admin.menu()) == 3
237238

238239
# Test 1 should be underneath Category1
239-
eq_(admin.menu()[1].name, 'Category1')
240-
eq_(admin.menu()[1].get_class_name(), 'class-name')
241-
eq_(admin.menu()[1].get_icon_type(), 'icon-type')
242-
eq_(admin.menu()[1].get_icon_value(), 'icon-value')
243-
eq_(len(admin.menu()[1].get_children()), 1)
244-
eq_(admin.menu()[1].get_children()[0].name, 'Test 1')
240+
assert admin.menu()[1].name == 'Category1'
241+
assert admin.menu()[1].get_class_name() == 'class-name'
242+
assert admin.menu()[1].get_icon_type() == 'icon-type'
243+
assert admin.menu()[1].get_icon_value() == 'icon-value'
244+
assert len(admin.menu()[1].get_children()) == 1
245+
assert admin.menu()[1].get_children()[0].name == 'Test 1'
245246

246247
# Test 2 should be underneath Category2
247-
eq_(admin.menu()[2].name, 'Category2')
248-
eq_(admin.menu()[2].get_class_name(), None)
249-
eq_(admin.menu()[2].get_icon_type(), None)
250-
eq_(admin.menu()[2].get_icon_value(), None)
251-
eq_(len(admin.menu()[2].get_children()), 1)
252-
eq_(admin.menu()[2].get_children()[0].name, 'Test 2')
248+
assert admin.menu()[2].name == 'Category2'
249+
assert admin.menu()[2].get_class_name() == None
250+
assert admin.menu()[2].get_icon_type() == None
251+
assert admin.menu()[2].get_icon_value() == None
252+
assert len(admin.menu()[2].get_children()) == 1
253+
assert admin.menu()[2].get_children()[0].name == 'Test 2'
253254

254255

255256
@pytest.mark.xfail(raises=Exception)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
py{27,35,36,37}-WTForms{1,2}
3+
WTForms{1,2}
44
py38-WTForms2
55
flake8
66
docs-html

0 commit comments

Comments
 (0)