Skip to content

Commit

Permalink
Fixed tests with the new required email field for users.
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricbonhomme committed Apr 7, 2020
1 parent 4bb0433 commit 8ca55e9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
17 changes: 10 additions & 7 deletions mosp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import mosp.models
from mosp.bootstrap import application, db

logger = logging.getLogger('commands')
logger = logging.getLogger("commands")


@application.cli.command("uml_graph")
Expand All @@ -30,8 +30,11 @@ def db_empty():
def db_create():
"Will create the database."
with application.app_context():
mosp.models.db_create(db, application.config['DB_CONFIG_DICT'],
application.config['DATABASE_NAME'])
mosp.models.db_create(
db,
application.config["DB_CONFIG_DICT"],
application.config["DATABASE_NAME"],
)


@application.cli.command("db_init")
Expand All @@ -50,8 +53,8 @@ def import_licenses_from_spdx():


@application.cli.command("create_user")
@click.option('--login', default='admin', help='Login')
@click.option('--password', default='password', help='Password')
@click.option("--login", default="admin", help="Login")
@click.option("--password", default="password", help="Password")
def create_user(login, password):
"Initializes a user"
print("Creation of the user {} ...".format(login))
Expand All @@ -60,8 +63,8 @@ def create_user(login, password):


@application.cli.command("create_admin")
@click.option('--login', default='admin', help='Login')
@click.option('--password', default='password', help='Password')
@click.option("--login", default="admin", help="Login")
@click.option("--password", default="password", help="Password")
def create_admin(login, password):
"Initializes an admin user"
print("Creation of the admin user {} ...".format(login))
Expand Down
20 changes: 16 additions & 4 deletions mosp/web/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
SubmitField,
validators,
HiddenField,
SelectMultipleField
SelectMultipleField,
)
from wtforms.fields.html5 import EmailField
from wtforms.validators import Email, InputRequired
Expand Down Expand Up @@ -146,7 +146,7 @@ class SchemaForm(FlaskForm):
lazy_gettext("Organization"),
[validators.Required(lazy_gettext("Please select an organization"))],
coerce=int,
default=0
default=0,
)
org_id.choices = [(0, "")]

Expand All @@ -166,7 +166,13 @@ class UserForm(FlaskForm):
],
)
password = PasswordField(lazy_gettext("Password"))
email = EmailField("Email", [InputRequired("Please enter your email address."), Email("Please enter your email address.")])
email = EmailField(
"Email",
[
InputRequired("Please enter your email address."),
Email("Please enter your email address."),
],
)
public_profile = BooleanField(lazy_gettext("Public profile"), default=True)
is_active = BooleanField(lazy_gettext("Active"), default=True)
is_admin = BooleanField(lazy_gettext("Admin"), default=False)
Expand Down Expand Up @@ -221,6 +227,12 @@ class ProfileForm(FlaskForm):
],
)
password = PasswordField(lazy_gettext("Password"))
email = EmailField("Email", [InputRequired("Please enter your email address."), Email("Please enter your email address.")])
email = EmailField(
"Email",
[
InputRequired("Please enter your email address."),
Email("Please enter your email address."),
],
)
public_profile = BooleanField(lazy_gettext("Public profile"), default=True)
submit = SubmitField(lazy_gettext("Save"))
4 changes: 2 additions & 2 deletions mosp/web/lib/objects_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def generate_misp_galaxy_cluster(json_object):
"uuid": value.pop("uuid", ""),
"value": value.pop("code", ""),
"description": value.pop("label")
if value.get("label", False)
else value.pop("description", ""),
if value.get("label", False)
else value.pop("description", ""),
"meta": value,
}
)
Expand Down
8 changes: 6 additions & 2 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@


def test_user(session):
user = User(login="john", pwdhash=generate_password_hash("password"))
user = User(
login="john",
pwdhash=generate_password_hash("password"),
email="[email protected]"
)

session.add(user)
session.commit()
Expand All @@ -14,4 +18,4 @@ def test_user(session):
assert user.is_api is False
assert user.public_profile is True
assert user.check_password("password") is True
assert user.apikey != ''
assert user.apikey != ""

0 comments on commit 8ca55e9

Please sign in to comment.