Skip to content

Commit

Permalink
[#2838] fix python3 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calexandr committed Jan 27, 2020
1 parent aef247b commit 41d8ea0
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions ckan/tests/logic/test_validators.py
Expand Up @@ -164,50 +164,54 @@ def call_and_assert(key, data, errors, context):


@pytest.mark.usefixtures("clean_db")
def test_email_is_unique_validator_with_existed_value():
user1 = factories.User(username="user01", email="user01@email.com")
def test_email_is_unique_validator_with_existed_value(app):
with app.flask_app.test_request_context():
user1 = factories.User(username="user01", email="user01@email.com")

# try to create new user with occupied email
with pytest.raises(logic.ValidationError):
factories.User(username="new_user", email="user01@email.com")
# try to create new user with occupied email
with pytest.raises(logic.ValidationError):
factories.User(username="new_user", email="user01@email.com")


@pytest.mark.usefixtures("clean_db")
def test_email_is_unique_validator_user_update_email_unchanged():
def test_email_is_unique_validator_user_update_email_unchanged(app):
user = factories.User(username="user01", email="user01@email.com")

# try to update user1 and leave email unchanged
old_email = "user01@email.com"

helpers.call_action("user_update", **user)
updated_user = model.User.get(user["id"])
with app.flask_app.test_request_context():
helpers.call_action("user_update", **user)
updated_user = model.User.get(user["id"])

assert updated_user.email == old_email
assert updated_user.email == old_email


@pytest.mark.usefixtures("clean_db")
def test_email_is_unique_validator_user_update_email_new():
def test_email_is_unique_validator_user_update_email_new(app):
user = factories.User(username="user01", email="user01@email.com")

# try to update user1 email to unoccupied one
new_email = "user_new@email.com"
user["email"] = new_email

helpers.call_action("user_update", **user)
updated_user = model.User.get(user["id"])
with app.flask_app.test_request_context():
helpers.call_action("user_update", **user)
updated_user = model.User.get(user["id"])

assert updated_user.email == new_email
assert updated_user.email == new_email


@pytest.mark.usefixtures("clean_db")
def test_email_is_unique_validator_user_update_to_existed_email():
def test_email_is_unique_validator_user_update_to_existed_email(app):
user1 = factories.User(username="user01", email="user01@email.com")
user2 = factories.User(username="user02", email="user02@email.com")

# try to update user1 email to existed one
user1["email"] = user2["email"]
with pytest.raises(logic.ValidationError):
helpers.call_action("user_update", **user1)
with app.flask_app.test_request_context():
with pytest.raises(logic.ValidationError):
helpers.call_action("user_update", **user1)


def test_name_validator_with_invalid_value():
Expand Down

0 comments on commit 41d8ea0

Please sign in to comment.