From ef44731e5a88103b2ac8daf32848089149bcef22 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Fri, 12 Jan 2018 15:57:11 +0100 Subject: [PATCH] Fix error when creating user with no group --- app/models.py | 2 +- tests/functional/test_models.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index c6f16ba..4d931f1 100644 --- a/app/models.py +++ b/app/models.py @@ -104,7 +104,7 @@ class User(db.Model, UserMixin): username = db.Column(db.Text, nullable=False, unique=True) display_name = db.Column(db.Text, nullable=False) email = db.Column(db.Text) - groups = db.Column(postgresql.ARRAY(db.Text)) + groups = db.Column(postgresql.ARRAY(db.Text), default=[]) tokens = db.relationship("Token", backref="user") def get_id(self): diff --git a/tests/functional/test_models.py b/tests/functional/test_models.py index 4ec1ea5..5956fec 100644 --- a/tests/functional/test_models.py +++ b/tests/functional/test_models.py @@ -14,6 +14,14 @@ import pytest from wtforms import ValidationError +def test_user_groups(user_factory): + user = user_factory() + assert user.groups == [] + groups = ['foo', 'Another group'] + user = user_factory(groups=groups) + assert user.groups == groups + + def test_network_ip_properties(network_factory): # Create some networks network1 = network_factory(address='172.16.1.0/24', first_ip='172.16.1.10', last_ip='172.16.1.250') -- GitLab