style(endpoints/api/repoemail): ran yapf
### Description of Changes Issue: https://coreosdev.atlassian.net/browse/QUAY-626 ## Reviewer Checklist - [ ] It works! - [ ] Comments provide sufficient explanations for the next contributor - [ ] Tests cover changes and corner cases - [ ] Follows Quay syntax patterns and format
This commit is contained in:
parent
d01b55f27d
commit
bbe9b033d0
4 changed files with 31 additions and 17 deletions
|
@ -5,8 +5,7 @@ import logging
|
|||
from flask import request, abort
|
||||
|
||||
from endpoints.api import (resource, nickname, require_repo_admin, RepositoryParamResource,
|
||||
log_action, validate_json_request, internal_only,
|
||||
path_param, show_if)
|
||||
log_action, validate_json_request, internal_only, path_param, show_if)
|
||||
from endpoints.api.repoemail_models_pre_oci import pre_oci_model as model
|
||||
from endpoints.exception import NotFound
|
||||
from app import tf
|
||||
|
@ -15,7 +14,6 @@ from util.useremails import send_repo_authorization_email
|
|||
|
||||
import features
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -26,6 +24,7 @@ logger = logging.getLogger(__name__)
|
|||
@path_param('email', 'The e-mail address')
|
||||
class RepositoryAuthorizedEmail(RepositoryParamResource):
|
||||
""" Resource for checking and authorizing e-mail addresses to receive repo notifications. """
|
||||
|
||||
@require_repo_admin
|
||||
@nickname('checkRepoEmailAuthorized')
|
||||
def get(self, namespace, repository, email):
|
||||
|
@ -36,7 +35,6 @@ class RepositoryAuthorizedEmail(RepositoryParamResource):
|
|||
|
||||
return record.to_dict()
|
||||
|
||||
|
||||
@require_repo_admin
|
||||
@nickname('sendAuthorizeRepoEmail')
|
||||
def post(self, namespace, repository, email):
|
||||
|
|
|
@ -5,7 +5,13 @@ from six import add_metaclass
|
|||
|
||||
|
||||
class RepositoryAuthorizedEmail(
|
||||
namedtuple('RepositoryAuthorizedEmail', ['email', 'repository_name', 'namespace_name', 'confirmed', 'code',])):
|
||||
namedtuple('RepositoryAuthorizedEmail', [
|
||||
'email',
|
||||
'repository_name',
|
||||
'namespace_name',
|
||||
'confirmed',
|
||||
'code',
|
||||
])):
|
||||
"""
|
||||
Tag represents a name to an image.
|
||||
:type email: string
|
||||
|
|
|
@ -6,7 +6,8 @@ def _return_none_or_data(func, namespace_name, repository_name, email):
|
|||
data = func(namespace_name, repository_name, email)
|
||||
if data is None:
|
||||
return data
|
||||
return RepositoryAuthorizedEmail(email, repository_name, namespace_name, data.confirmed, data.code)
|
||||
return RepositoryAuthorizedEmail(email, repository_name, namespace_name, data.confirmed,
|
||||
data.code)
|
||||
|
||||
|
||||
class PreOCIModel(RepoEmailDataInterface):
|
||||
|
@ -16,11 +17,12 @@ class PreOCIModel(RepoEmailDataInterface):
|
|||
"""
|
||||
|
||||
def get_email_authorized_for_repo(self, namespace_name, repository_name, email):
|
||||
return _return_none_or_data(model.repository.get_email_authorized_for_repo, namespace_name, repository_name, email)
|
||||
return _return_none_or_data(model.repository.get_email_authorized_for_repo, namespace_name,
|
||||
repository_name, email)
|
||||
|
||||
def create_email_authorization_for_repo(self, namespace_name, repository_name, email):
|
||||
return _return_none_or_data(model.repository.create_email_authorization_for_repo, namespace_name, repository_name,
|
||||
email)
|
||||
return _return_none_or_data(model.repository.create_email_authorization_for_repo,
|
||||
namespace_name, repository_name, email)
|
||||
|
||||
|
||||
pre_oci_model = PreOCIModel()
|
||||
|
|
|
@ -45,9 +45,11 @@ def test_get_email_authorized_for_repo_return_repo(get_monkeypatch):
|
|||
mock = Mock(confirmed=True, code='code')
|
||||
get_monkeypatch.setattr(model.repository, 'get_email_authorized_for_repo', get_return_mock(mock))
|
||||
|
||||
actual = pre_oci_model.get_email_authorized_for_repo('namespace_name', 'repository_name', 'email')
|
||||
actual = pre_oci_model.get_email_authorized_for_repo('namespace_name', 'repository_name',
|
||||
'email')
|
||||
|
||||
assert actual == RepositoryAuthorizedEmail('email', 'repository_name', 'namespace_name', True, 'code')
|
||||
assert actual == RepositoryAuthorizedEmail('email', 'repository_name', 'namespace_name', True,
|
||||
'code')
|
||||
|
||||
|
||||
def test_create_email_authorization_for_repo(get_monkeypatch):
|
||||
|
@ -62,20 +64,26 @@ def test_create_email_authorization_for_repo(get_monkeypatch):
|
|||
def test_create_email_authorization_for_repo_return_none(get_monkeypatch):
|
||||
get_monkeypatch.setattr(model.repository, 'create_email_authorization_for_repo', return_none)
|
||||
|
||||
assert pre_oci_model.create_email_authorization_for_repo('namespace_name', 'repository_name', 'email') is None
|
||||
assert pre_oci_model.create_email_authorization_for_repo('namespace_name', 'repository_name',
|
||||
'email') is None
|
||||
|
||||
|
||||
def test_create_email_authorization_for_repo_return_mock(get_monkeypatch):
|
||||
mock = Mock()
|
||||
get_monkeypatch.setattr(model.repository, 'create_email_authorization_for_repo', get_return_mock(mock))
|
||||
get_monkeypatch.setattr(model.repository, 'create_email_authorization_for_repo',
|
||||
get_return_mock(mock))
|
||||
|
||||
assert pre_oci_model.create_email_authorization_for_repo('namespace_name', 'repository_name', 'email') is not None
|
||||
assert pre_oci_model.create_email_authorization_for_repo('namespace_name', 'repository_name',
|
||||
'email') is not None
|
||||
|
||||
|
||||
def test_create_email_authorization_for_repo_return_value(get_monkeypatch):
|
||||
mock = Mock(confirmed=False, code='code')
|
||||
|
||||
get_monkeypatch.setattr(model.repository, 'create_email_authorization_for_repo', get_return_mock(mock))
|
||||
get_monkeypatch.setattr(model.repository, 'create_email_authorization_for_repo',
|
||||
get_return_mock(mock))
|
||||
|
||||
actual = pre_oci_model.create_email_authorization_for_repo('namespace_name', 'repository_name', 'email')
|
||||
assert actual == RepositoryAuthorizedEmail('email', 'repository_name', 'namespace_name', False, 'code')
|
||||
actual = pre_oci_model.create_email_authorization_for_repo('namespace_name', 'repository_name',
|
||||
'email')
|
||||
assert actual == RepositoryAuthorizedEmail('email', 'repository_name', 'namespace_name', False,
|
||||
'code')
|
||||
|
|
Reference in a new issue