Browse Source

Rename references from corvus to server

merge-requests/2/head
Drew Short 5 years ago
parent
commit
9796f2e6ea
  1. 2
      server/.env
  2. 22
      server/Dockerfile
  3. 4
      server/corvus/api/__init__.py
  4. 2
      server/corvus/model/__init__.py
  5. 1
      server/corvus/utility/__init__.py
  6. 4
      server/dev-run.sh
  7. 10
      server/documentation/api/user.rst
  8. 2
      server/documentation/conf.py
  9. 4
      server/entrypoint.sh
  10. 14
      server/manage.py
  11. 10
      server/run_tests.bat
  12. 12
      server/run_tests.sh
  13. 42
      server/server/__init__.py
  14. 4
      server/server/api/__init__.py
  15. 16
      server/server/api/authentication_api.py
  16. 2
      server/server/api/decorators.py
  17. 4
      server/server/api/health_api.py
  18. 2
      server/server/api/model.py
  19. 20
      server/server/api/user_api.py
  20. 0
      server/server/db.py
  21. 2
      server/server/default_settings.py
  22. 20
      server/server/errors.py
  23. 0
      server/server/middleware/__init__.py
  24. 8
      server/server/middleware/authentication_middleware.py
  25. 2
      server/server/model/__init__.py
  26. 4
      server/server/model/user_model.py
  27. 0
      server/server/service/__init__.py
  28. 6
      server/server/service/authentication_service.py
  29. 10
      server/server/service/patch_service.py
  30. 2
      server/server/service/role_service.py
  31. 4
      server/server/service/transformation_service.py
  32. 16
      server/server/service/user_service.py
  33. 8
      server/server/service/user_token_service.py
  34. 8
      server/server/service/validation_service.py
  35. 1
      server/server/utility/__init__.py
  36. 0
      server/server/utility/authentication_utility.py
  37. 8
      server/server/utility/json_utility.py
  38. 2
      server/server/utility/pagination_utility.py
  39. 0
      server/server/utility/session_utility.py
  40. 4
      server/setup.py
  41. 4
      server/tests/api/test_decorators.py
  42. 2
      server/tests/api/test_user_api.py
  43. 26
      server/tests/conftest.py
  44. 4
      server/tests/middleware/test_authentication_middleware.py
  45. 4
      server/tests/service/test_authentication_service.py
  46. 6
      server/tests/service/test_patch_service.py
  47. 2
      server/tests/service/test_role_service.py
  48. 8
      server/tests/service/test_transformation_service.py
  49. 4
      server/tests/service/test_validation_service.py

2
server/.env

@ -1 +1 @@
FLASK_APP=corvus:corvus
FLASK_APP=server:server

22
server/Dockerfile

@ -1,25 +1,25 @@
FROM python:3.7-slim-stretch FROM python:3.7-slim-stretch
MAINTAINER Drew Short <warrick@sothr.com> MAINTAINER Drew Short <warrick@sothr.com>
ENV CORVUS_APP_DIRECTORY /opt/corvus
ENV CORVUS_CONFIG_DIRECTORY /srv/corvus/config
ENV CORVUS_DATA_DIRECTORY /srv/corvus/data
ENV SERVER_APP_DIRECTORY /opt/server
ENV SERVER_CONFIG_DIRECTORY /srv/server/config
ENV SERVER_DATA_DIRECTORY /srv/server/data
RUN mkdir -p ${CORVUS_APP_DIRECTORY} \
&& mkdir -p ${CORVUS_CONFIG_DIRECTORY} \
&& mkdir -p ${CORVUS_DATA_DIRECTORY} \
RUN mkdir -p ${SERVER_APP_DIRECTORY} \
&& mkdir -p ${SERVER_CONFIG_DIRECTORY} \
&& mkdir -p ${SERVER_DATA_DIRECTORY} \
&& pip install pipenv gunicorn && pip install pipenv gunicorn
VOLUME ${CORVUS_CONFIG_DIRECTORY}
VOLUME ${CORVUS_DATA_DIRECTORY}
VOLUME ${SERVER_CONFIG_DIRECTORY}
VOLUME ${SERVER_DATA_DIRECTORY}
COPY ./ ${CORVUS_APP_DIRECTORY}/
COPY ./ ${SERVER_APP_DIRECTORY}/
RUN cd ${CORVUS_APP_DIRECTORY} \
RUN cd ${SERVER_APP_DIRECTORY} \
&& pipenv install --system --deploy --ignore-pipfile && pipenv install --system --deploy --ignore-pipfile
EXPOSE 8080 EXPOSE 8080
WORKDIR ${CORVUS_APP_DIRECTORY}
WORKDIR ${SERVER_APP_DIRECTORY}
CMD ./entrypoint.sh CMD ./entrypoint.sh

4
server/corvus/api/__init__.py

@ -1,4 +0,0 @@
"""API blueprint exports."""
from corvus.api.authentication_api import AUTH_BLUEPRINT
from corvus.api.user_api import USER_BLUEPRINT
from corvus.api.health_api import HEALTH_BLUEPRINT

2
server/corvus/model/__init__.py

@ -1,2 +0,0 @@
"""Expose models to be used in Corvus."""
from corvus.model.user_model import User, UserToken

1
server/corvus/utility/__init__.py

@ -1 +0,0 @@
"""Utilities for Corvus."""

4
server/dev-run.sh

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
FLASK_APP=corvus:corvus flask db upgrade
FLASK_APP=server:server flask db upgrade
python manage.py user register-admin python manage.py user register-admin
FLASK_APP=corvus:corvus flask run
FLASK_APP=server:server flask run

10
server/documentation/api/user.rst

@ -31,7 +31,7 @@ User API
{ {
"creationTime": "2018-07-29T11:58:17-05:00", "creationTime": "2018-07-29T11:58:17-05:00",
"lastLoginTime": "2018-07-29T12:43:27-05:00", "lastLoginTime": "2018-07-29T12:43:27-05:00",
"name": "corvus_administrator",
"name": "server_administrator",
"role": "ADMIN", "role": "ADMIN",
"version": 0 "version": 0
} }
@ -62,7 +62,7 @@ User API
.. sourcecode:: http .. sourcecode:: http
GET /user/corvus_administrator HTTP/1.1
GET /user/server_administrator HTTP/1.1
Host: example.tld Host: example.tld
Accept: application/json Accept: application/json
X-Auth-Token: <Base64(user:userToken)> X-Auth-Token: <Base64(user:userToken)>
@ -78,7 +78,7 @@ User API
{ {
"creationTime": "2018-07-29T11:58:17-05:00", "creationTime": "2018-07-29T11:58:17-05:00",
"lastLoginTime": "2018-07-29T12:43:27-05:00", "lastLoginTime": "2018-07-29T12:43:27-05:00",
"name": "corvus_administrator",
"name": "server_administrator",
"role": "ADMIN", "role": "ADMIN",
"version": 0 "version": 0
} }
@ -104,7 +104,7 @@ User API
.. sourcecode:: http .. sourcecode:: http
PATCH /user/corvus_administrator HTTP/1.1
PATCH /user/server_administrator HTTP/1.1
Host: example.tld Host: example.tld
Accept: application/json Accept: application/json
X-Auth-Token: <Base64(user:userToken)> X-Auth-Token: <Base64(user:userToken)>
@ -126,7 +126,7 @@ User API
{ {
"creationTime": "2018-07-29T11:58:17-05:00", "creationTime": "2018-07-29T11:58:17-05:00",
"lastLoginTime": "2019-07-29T12:43:27-05:00", "lastLoginTime": "2019-07-29T12:43:27-05:00",
"name": "corvus_administrator",
"name": "server_administrator",
"role": "ADMIN", "role": "ADMIN",
"version": 1 "version": 1
} }

2
server/documentation/conf.py

@ -140,7 +140,7 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
(master_doc, 'corvus', 'Corvus Documentation',
(master_doc, 'server', 'Corvus Documentation',
[author], 1) [author], 1)
] ]

4
server/entrypoint.sh

@ -1,10 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Migrate the Database # Migrate the Database
FLASK_APP=corvus:corvus flask db upgrade
FLASK_APP=server:server flask db upgrade
# Make sure an administrator is registered # Make sure an administrator is registered
python manage.py user register-admin python manage.py user register-admin
# Start the application # Start the application
gunicorn -b 0.0.0.0:8080 corvus:corvus
gunicorn -b 0.0.0.0:8080 server:server

14
server/manage.py

@ -8,10 +8,10 @@ from typing import Optional
import click import click
from click import Context from click import Context
from corvus import corvus
from corvus.model import User
from corvus.service import user_service
from corvus.service.role_service import ROLE_LIST
from server import server
from server.model import User
from server.service import user_service
from server.service.role_service import ROLE_LIST
logging.basicConfig() logging.basicConfig()
@ -85,7 +85,7 @@ def register_user(
def register_admin_user(ctx: Context): def register_admin_user(ctx: Context):
admin_users = User.query.filter_by(role=User.ROLE_ADMIN).all() admin_users = User.query.filter_by(role=User.ROLE_ADMIN).all()
if len(admin_users) == 0: if len(admin_users) == 0:
name = 'corvus_administrator'
name = 'server_administrator'
password = ''.join( password = ''.join(
random.choices(string.ascii_letters + string.digits, k=32)) random.choices(string.ascii_letters + string.digits, k=32))
ctx.invoke( ctx.invoke(
@ -150,6 +150,6 @@ user_command_group.add_command(reset_user_password)
user_command_group.add_command(list_users) user_command_group.add_command(list_users)
if __name__ == '__main__': if __name__ == '__main__':
logging.debug('Managing: %s', corvus.name)
with corvus.app_context():
logging.debug('Managing: %s', server.name)
with server.app_context():
main() main()

10
server/run_tests.bat

@ -11,20 +11,20 @@ pipenv run pytest --version
pipenv run pycodestyle --version pipenv run pycodestyle --version
pipenv run pydocstyle --version pipenv run pydocstyle --version
pipenv run pylint corvus
pipenv run pylint server
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%
pipenv run mypy corvus tests
pipenv run mypy server tests
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%
pipenv run coverage run --source corvus -m pytest
pipenv run coverage run --source server -m pytest
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%
pipenv run coverage report --fail-under=85 -m --skip-covered pipenv run coverage report --fail-under=85 -m --skip-covered
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%
pipenv run pycodestyle corvus tests
pipenv run pycodestyle server tests
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%
pipenv run pydocstyle corvus
pipenv run pydocstyle server
if %errorlevel% neq 0 exit /b %errorlevel% if %errorlevel% neq 0 exit /b %errorlevel%

12
server/run_tests.sh

@ -4,7 +4,7 @@ set -e
set -x set -x
# shellcheck disable=SC2034 # shellcheck disable=SC2034
PIPENV_VERBOSITY=-1
export PIPENV_VERBOSITY=-1
pipenv run python3 --version pipenv run python3 --version
pipenv run python3 -m pip --version pipenv run python3 -m pip --version
@ -16,9 +16,9 @@ pipenv run pytest --version
pipenv run pycodestyle --version pipenv run pycodestyle --version
pipenv run pydocstyle --version pipenv run pydocstyle --version
pipenv run pylint corvus
pipenv run mypy corvus tests
PYTHONPATH=$(pwd) pipenv run coverage run --source corvus -m pytest
pipenv run pylint server
pipenv run mypy server tests
PYTHONPATH=$(pwd) pipenv run coverage run --source server -m pytest
pipenv run coverage report --fail-under=85 -m --skip-covered pipenv run coverage report --fail-under=85 -m --skip-covered
pipenv run pycodestyle corvus tests
pipenv run pydocstyle corvus
pipenv run pycodestyle server tests
pipenv run pydocstyle server

42
server/corvus/__init__.py → server/server/__init__.py

@ -1,14 +1,14 @@
"""Corvus Flask Application."""
"""Flask Application."""
import os import os
from logging.config import dictConfig from logging.config import dictConfig
from flask import Flask from flask import Flask
from flask_migrate import Migrate from flask_migrate import Migrate
from corvus.db import db
from corvus.errors import BaseError, handle_corvus_base_error, \
handle_corvus_404_error
from corvus.utility import json_utility, session_utility
from server.db import db
from server.errors import BaseError, handle_base_error, \
handle_404_error
from server.utility import json_utility, session_utility
dictConfig({ dictConfig({
'version': 1, 'version': 1,
@ -29,18 +29,18 @@ dictConfig({
def create_app(test_config: dict = None) -> Flask: def create_app(test_config: dict = None) -> Flask:
""" """
Create an instance of Corvus.
Create a server instance.
:param test_config: :param test_config:
:return: :return:
""" """
app = Flask(__name__, instance_relative_config=True) app = Flask(__name__, instance_relative_config=True)
app.logger.debug('Creating Corvus Server')
app.logger.debug('Creating Server')
data_directory = os.getenv('CORVUS_DATA_DIRECTORY', '/tmp')
app.logger.debug('Corvus Data Directory: %s', data_directory)
data_directory = os.getenv('SERVER_DATA_DIRECTORY', '/tmp')
app.logger.debug('Server Data Directory: %s', data_directory)
default_database_uri = 'sqlite:///{}/corvus.db'.format(data_directory)
default_database_uri = 'sqlite:///{}/server.db'.format(data_directory)
app.config.from_mapping( app.config.from_mapping(
SECRET_KEY='dev', SECRET_KEY='dev',
SQLALCHEMY_DATABASE_URI=default_database_uri, SQLALCHEMY_DATABASE_URI=default_database_uri,
@ -50,10 +50,10 @@ def create_app(test_config: dict = None) -> Flask:
if test_config is None: if test_config is None:
app.logger.debug('Loading configurations') app.logger.debug('Loading configurations')
app.config.from_object('corvus.default_settings')
app.config.from_object('server.default_settings')
app.config.from_pyfile('config.py', silent=True) app.config.from_pyfile('config.py', silent=True)
if os.getenv('CORVUS_SETTINGS', None):
app.config.from_envvar('CORVUS_SETTINGS')
if os.getenv('SERVER_SETTINGS', None):
app.config.from_envvar('SERVER_SETTINGS')
else: else:
app.logger.debug('Loading test configuration') app.logger.debug('Loading test configuration')
app.config.from_mapping(test_config) app.config.from_mapping(test_config)
@ -81,7 +81,7 @@ def register_blueprints(app: Flask) -> None:
:param app: :param app:
:return: :return:
""" """
from corvus.api import AUTH_BLUEPRINT, USER_BLUEPRINT, HEALTH_BLUEPRINT
from server.api import AUTH_BLUEPRINT, USER_BLUEPRINT, HEALTH_BLUEPRINT
app.register_blueprint(AUTH_BLUEPRINT) app.register_blueprint(AUTH_BLUEPRINT)
app.register_blueprint(USER_BLUEPRINT) app.register_blueprint(USER_BLUEPRINT)
app.register_blueprint(HEALTH_BLUEPRINT) app.register_blueprint(HEALTH_BLUEPRINT)
@ -94,15 +94,15 @@ def register_error_handlers(app: Flask) -> None:
:param app: :param app:
:return: :return:
""" """
app.register_error_handler(404, handle_corvus_404_error)
app.register_error_handler(BaseError, handle_corvus_base_error)
app.register_error_handler(404, handle_404_error)
app.register_error_handler(BaseError, handle_base_error)
corvus = create_app() # pylint: disable=C0103
register_blueprints(corvus)
register_error_handlers(corvus)
server = create_app() # pylint: disable=C0103
register_blueprints(server)
register_error_handlers(server)
logger = corvus.logger # pylint: disable=C0103
logger = server.logger # pylint: disable=C0103
if __name__ == "__main__": if __name__ == "__main__":
corvus.run()
server.run()

4
server/server/api/__init__.py

@ -0,0 +1,4 @@
"""API blueprint exports."""
from server.api.authentication_api import AUTH_BLUEPRINT
from server.api.user_api import USER_BLUEPRINT
from server.api.health_api import HEALTH_BLUEPRINT

16
server/corvus/api/authentication_api.py → server/server/api/authentication_api.py

@ -1,19 +1,19 @@
"""Authentication API blueprint and endpoint definitions.""" """Authentication API blueprint and endpoint definitions."""
from flask import Blueprint, g, abort, request from flask import Blueprint, g, abort, request
from corvus.api.decorators import return_json
from corvus.api.model import APIMessage, APIResponse, APIPage
from corvus.middleware import authentication_middleware
from corvus.service import (
from server.api.decorators import return_json
from server.api.model import APIMessage, APIResponse, APIPage
from server.middleware import authentication_middleware
from server.service import (
user_token_service, user_token_service,
authentication_service, authentication_service,
user_service, user_service,
transformation_service transformation_service
) )
from corvus.middleware.authentication_middleware import Auth
from corvus.service.role_service import Role
from corvus.model import UserToken
from corvus.utility.pagination_utility import get_pagination_params
from server.middleware.authentication_middleware import Auth
from server.service.role_service import Role
from server.model import UserToken
from server.utility.pagination_utility import get_pagination_params
AUTH_BLUEPRINT = Blueprint( AUTH_BLUEPRINT = Blueprint(
name='auth', import_name=__name__, url_prefix='/auth') name='auth', import_name=__name__, url_prefix='/auth')

2
server/corvus/api/decorators.py → server/server/api/decorators.py

@ -4,7 +4,7 @@ from typing import Callable, Any
from flask import jsonify, Response from flask import jsonify, Response
from corvus.api.model import APIResponse
from server.api.model import APIResponse
def return_json(func: Callable) -> Callable: def return_json(func: Callable) -> Callable:

4
server/corvus/api/health_api.py → server/server/api/health_api.py

@ -1,8 +1,8 @@
"""Endpoint to expose the health of the application.""" """Endpoint to expose the health of the application."""
from flask import Blueprint from flask import Blueprint
from corvus.api.decorators import return_json
from corvus.api.model import APIResponse, APIMessage
from server.api.decorators import return_json
from server.api.model import APIResponse, APIMessage
HEALTH_BLUEPRINT = Blueprint( HEALTH_BLUEPRINT = Blueprint(
name='health', import_name=__name__, url_prefix='/health') name='health', import_name=__name__, url_prefix='/health')

2
server/corvus/api/model.py → server/server/api/model.py

@ -3,7 +3,7 @@ from typing import Any, List, Optional, Dict
from flask_sqlalchemy import Pagination from flask_sqlalchemy import Pagination
from corvus.db import db_model
from server.db import db_model
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods

20
server/corvus/api/user_api.py → server/server/api/user_api.py

@ -2,20 +2,20 @@
from flask import Blueprint, abort, request, g from flask import Blueprint, abort, request, g
from corvus.api.decorators import return_json
from corvus.api.model import APIResponse, APIMessage, APIPage
from corvus.middleware import authentication_middleware
from corvus.middleware.authentication_middleware import Auth
from corvus.model import User
from corvus.service import (
from server.api.decorators import return_json
from server.api.model import APIResponse, APIMessage, APIPage
from server.middleware import authentication_middleware
from server.middleware.authentication_middleware import Auth
from server.model import User
from server.service import (
patch_service, patch_service,
transformation_service, transformation_service,
user_service user_service
) )
from corvus.service.patch_service import get_patch_fields
from corvus.service.role_service import Role
from corvus.utility.pagination_utility import get_pagination_params
from corvus.service.role_service import ROLE_LIST
from server.service.patch_service import get_patch_fields
from server.service.role_service import Role
from server.utility.pagination_utility import get_pagination_params
from server.service.role_service import ROLE_LIST
USER_BLUEPRINT = Blueprint( USER_BLUEPRINT = Blueprint(
name='user', import_name=__name__, url_prefix='/user') name='user', import_name=__name__, url_prefix='/user')

0
server/corvus/db.py → server/server/db.py

2
server/corvus/default_settings.py → server/server/default_settings.py

@ -1,4 +1,4 @@
"""Default settings for corvus."""
"""Default settings for server."""
DEBUG = False DEBUG = False
SECRET_KEY = b'\xb4\x89\x0f\x0f\xe5\x88\x97\xfe\x8d<\x0b@d\xe9\xa5\x87%' \ SECRET_KEY = b'\xb4\x89\x0f\x0f\xe5\x88\x97\xfe\x8d<\x0b@d\xe9\xa5\x87%' \

20
server/corvus/errors.py → server/server/errors.py

@ -1,14 +1,14 @@
"""Error definitions for Corvus."""
"""Error definitions."""
from typing import Dict from typing import Dict
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from corvus.api.decorators import return_json
from corvus.api.model import APIResponse, APIMessage
from server.api.decorators import return_json
from server.api.model import APIResponse, APIMessage
class BaseError(Exception): class BaseError(Exception):
"""Corvus Base Error Class (5xx errors)."""
"""Base Error Class (5xx errors)."""
def __init__( def __init__(
self, self,
@ -30,7 +30,7 @@ class BaseError(Exception):
class ClientError(BaseError): class ClientError(BaseError):
"""Corvus errors where the client is wrong (4xx errors)."""
"""Errors where the client is wrong (4xx errors)."""
def __init__(self, def __init__(self,
message: str = 'Unknown client error', message: str = 'Unknown client error',
@ -41,18 +41,18 @@ class ClientError(BaseError):
class ValidationError(ClientError): class ValidationError(ClientError):
"""Corvus Validation Error."""
"""Validation Error."""
@return_json @return_json
def handle_corvus_404_error(exception: HTTPException) -> APIResponse:
"""Error handler for 404 Corvus errors."""
def handle_404_error(exception: HTTPException) -> APIResponse:
"""Error handler for 404 errors."""
return APIResponse( return APIResponse(
payload=APIMessage(False, 'Not Found'), payload=APIMessage(False, 'Not Found'),
status=exception.code if exception.code is not None else 404) status=exception.code if exception.code is not None else 404)
@return_json @return_json
def handle_corvus_base_error(error: BaseError) -> APIResponse:
"""Error handler for basic Corvus raised errors."""
def handle_base_error(error: BaseError) -> APIResponse:
"""Error handler for basic raised errors."""
return APIResponse(payload=error, status=error.status_code) return APIResponse(payload=error, status=error.status_code)

0
server/corvus/middleware/__init__.py → server/server/middleware/__init__.py

8
server/corvus/middleware/authentication_middleware.py → server/server/middleware/authentication_middleware.py

@ -9,14 +9,14 @@ from flask import request, Response, g, json
from werkzeug.datastructures import Authorization from werkzeug.datastructures import Authorization
from werkzeug.http import bytes_to_wsgi, wsgi_to_bytes from werkzeug.http import bytes_to_wsgi, wsgi_to_bytes
from corvus.api.model import APIMessage
from corvus.service import (
from server.api.model import APIMessage
from server.service import (
authentication_service, authentication_service,
user_service, user_service,
user_token_service user_token_service
) )
from corvus.service.role_service import ROLES, Role
from corvus.service import transformation_service
from server.service.role_service import ROLES, Role
from server.service import transformation_service
class Auth(Enum): class Auth(Enum):

2
server/server/model/__init__.py

@ -0,0 +1,2 @@
"""Expose models to be used."""
from server.model.user_model import User, UserToken

4
server/corvus/model/user_model.py → server/server/model/user_model.py

@ -1,8 +1,8 @@
"""User related SQLALchemy models.""" """User related SQLALchemy models."""
from sqlalchemy import Enum from sqlalchemy import Enum
from corvus.db import db
from corvus.service.role_service import Role
from server.db import db
from server.service.role_service import Role
class User(db.Model): # pylint: disable=too-few-public-methods class User(db.Model): # pylint: disable=too-few-public-methods

0
server/corvus/service/__init__.py → server/server/service/__init__.py

6
server/corvus/service/authentication_service.py → server/server/service/authentication_service.py

@ -5,9 +5,9 @@ from typing import Optional
from nacl import pwhash from nacl import pwhash
from nacl.exceptions import InvalidkeyError from nacl.exceptions import InvalidkeyError
from corvus import errors
from corvus.model import User, UserToken
from corvus.service import user_token_service
from server import errors
from server.model import User, UserToken
from server.service import user_token_service
def validate_password_strength(proposed_password: str) -> str: def validate_password_strength(proposed_password: str) -> str:

10
server/corvus/service/patch_service.py → server/server/service/patch_service.py

@ -1,11 +1,11 @@
"""Patching support for db.Model objects.""" """Patching support for db.Model objects."""
from typing import Set, Optional, Any, Dict from typing import Set, Optional, Any, Dict
from corvus import errors
from corvus.db import db_model
from corvus.model import User
from corvus.service import transformation_service
from corvus.service import validation_service
from server import errors
from server.db import db_model
from server.model import User
from server.service import transformation_service
from server.service import validation_service
def get_patch_fields(patch_json: Dict[str, Any]) -> Set[str]: def get_patch_fields(patch_json: Dict[str, Any]) -> Set[str]:

2
server/corvus/service/role_service.py → server/server/service/role_service.py

@ -1,4 +1,4 @@
"""Role service for Corvus."""
"""Role service."""
from collections import defaultdict from collections import defaultdict
from enum import Enum from enum import Enum
from typing import Optional, List, Set, Dict from typing import Optional, List, Set, Dict

4
server/corvus/service/transformation_service.py → server/server/service/transformation_service.py

@ -3,8 +3,8 @@ import logging
import re import re
from typing import Dict, Callable, Any, List, Optional, Type from typing import Dict, Callable, Any, List, Optional, Type
from corvus import errors
from corvus.db import db_model
from server import errors
from server.db import db_model
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

16
server/corvus/service/user_service.py → server/server/service/user_service.py

@ -8,20 +8,20 @@ from typing import Optional, Dict, Callable, Any, Tuple
from flask_sqlalchemy import Pagination from flask_sqlalchemy import Pagination
from iso8601 import iso8601 from iso8601 import iso8601
from corvus import errors
from corvus.db import db
from corvus.model import User
from corvus.service import role_service
from corvus.service.authentication_service import validate_password_strength
from corvus.service.transformation_service import (
from server import errors
from server.db import db
from server.model import User
from server.service import role_service
from server.service.authentication_service import validate_password_strength
from server.service.transformation_service import (
BaseTransformer, BaseTransformer,
register_transformer register_transformer
) )
from corvus.service.validation_service import (
from server.service.validation_service import (
BaseValidator, BaseValidator,
register_validator register_validator
) )
from corvus.utility import authentication_utility
from server.utility import authentication_utility
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

8
server/corvus/service/user_token_service.py → server/server/service/user_token_service.py

@ -6,13 +6,13 @@ from typing import Optional, Dict, Callable, Any
from flask_sqlalchemy import Pagination from flask_sqlalchemy import Pagination
from iso8601 import iso8601, ParseError from iso8601 import iso8601, ParseError
from corvus.db import db
from corvus.model import User, UserToken
from corvus.service.transformation_service import (
from server.db import db
from server.model import User, UserToken
from server.service.transformation_service import (
BaseTransformer, BaseTransformer,
register_transformer register_transformer
) )
from corvus import errors
from server import errors
@register_transformer @register_transformer

8
server/corvus/service/validation_service.py → server/server/service/validation_service.py

@ -1,12 +1,12 @@
"""Validation service for Corvus models."""
"""Validation service for models."""
from typing import Type, Dict, Callable, Any, Set, Optional, Tuple from typing import Type, Dict, Callable, Any, Set, Optional, Tuple
from sqlalchemy import orm from sqlalchemy import orm
from corvus import errors
from corvus.db import db_model
from corvus.model import User
from server import errors
from server.db import db_model
from server.model import User
_changable_attribute_names: Dict[str, Set[str]] = {} _changable_attribute_names: Dict[str, Set[str]] = {}

1
server/server/utility/__init__.py

@ -0,0 +1 @@
"""Utilities."""

0
server/corvus/utility/authentication_utility.py → server/server/utility/authentication_utility.py

8
server/corvus/utility/json_utility.py → server/server/utility/json_utility.py

@ -5,10 +5,10 @@ from typing import Any
import rfc3339 import rfc3339
from flask.json import JSONEncoder from flask.json import JSONEncoder
from corvus.api.model import APIResponse, BaseAPIMessage
from corvus.db import db
from corvus.errors import BaseError
from corvus.service.transformation_service import serialize_model
from server.api.model import APIResponse, BaseAPIMessage
from server.db import db
from server.errors import BaseError
from server.service.transformation_service import serialize_model
class CustomJSONEncoder(JSONEncoder): class CustomJSONEncoder(JSONEncoder):

2
server/corvus/utility/pagination_utility.py → server/server/utility/pagination_utility.py

@ -3,7 +3,7 @@ from typing import Tuple
from werkzeug.datastructures import MultiDict from werkzeug.datastructures import MultiDict
from corvus import errors
from server import errors
def get_pagination_params(request_args: MultiDict) -> Tuple[int, int]: def get_pagination_params(request_args: MultiDict) -> Tuple[int, int]:

0
server/corvus/utility/session_utility.py → server/server/utility/session_utility.py

4
server/setup.py

@ -1,8 +1,8 @@
from setuptools import setup from setuptools import setup
setup( setup(
name='corvus',
packages=['corvus'],
name='server',
packages=['server'],
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[
'flask', 'flask',

4
server/tests/api/test_decorators.py

@ -2,8 +2,8 @@ from typing import Any
from flask import Response, Flask from flask import Response, Flask
from corvus.api.decorators import return_json
from corvus.api.model import APIResponse
from server.api.decorators import return_json
from server.api.model import APIResponse
@return_json @return_json

2
server/tests/api/test_user_api.py

@ -6,7 +6,7 @@ from flask.testing import FlaskClient
from tests.conftest import AuthActions from tests.conftest import AuthActions
from corvus.service.role_service import ROLE_LIST
from server.service.role_service import ROLE_LIST
def test_get_users_happy_path(auth: AuthActions, client: FlaskClient): def test_get_users_happy_path(auth: AuthActions, client: FlaskClient):

26
server/tests/conftest.py

@ -10,10 +10,10 @@ from flask import Flask
from flask.testing import FlaskClient, FlaskCliRunner from flask.testing import FlaskClient, FlaskCliRunner
from werkzeug.test import Client from werkzeug.test import Client
from corvus import create_app, register_blueprints, register_error_handlers
from corvus.db import init_db
from corvus.model import User
from corvus.service import user_service
from server import create_app, register_blueprints, register_error_handlers
from server.db import init_db
from server.model import User
from server.service import user_service
def add_test_user() -> Tuple[str, str]: def add_test_user() -> Tuple[str, str]:
@ -27,27 +27,27 @@ def add_test_user() -> Tuple[str, str]:
@pytest.fixture @pytest.fixture
def app() -> Generator[Flask, Any, Any]: def app() -> Generator[Flask, Any, Any]:
"""Create and configure a new corvus_app instance for each test."""
"""Create and configure a new server_app instance for each test."""
# create a temporary file to isolate the database for each test # create a temporary file to isolate the database for each test
db_fd, db_path = tempfile.mkstemp(suffix='.db') db_fd, db_path = tempfile.mkstemp(suffix='.db')
test_database_uri = 'sqlite:///{}'.format(db_path) test_database_uri = 'sqlite:///{}'.format(db_path)
# create the corvus_app with common test config
corvus_app = create_app({
# create the server_app with common test config
server_app = create_app({
'TESTING': True, 'TESTING': True,
'SQLALCHEMY_DATABASE_URI': test_database_uri, 'SQLALCHEMY_DATABASE_URI': test_database_uri,
}) })
register_blueprints(corvus_app)
register_error_handlers(corvus_app)
register_blueprints(server_app)
register_error_handlers(server_app)
# create the database and load test data # create the database and load test data
with corvus_app.app_context():
with server_app.app_context():
init_db() init_db()
test_username, test_password = add_test_user() test_username, test_password = add_test_user()
corvus_app.config['test_username'] = test_username
corvus_app.config['test_password'] = test_password
server_app.config['test_username'] = test_username
server_app.config['test_password'] = test_password
# get_db().executescript(_data_sql) # get_db().executescript(_data_sql)
yield corvus_app
yield server_app
# close and remove the temporary database # close and remove the temporary database
os.close(db_fd) os.close(db_fd)

4
server/tests/middleware/test_authentication_middleware.py

@ -1,9 +1,9 @@
from mock import patch, MagicMock, Mock from mock import patch, MagicMock, Mock
from corvus.middleware.authentication_middleware import \
from server.middleware.authentication_middleware import \
authenticate_with_password, authenticate_with_token authenticate_with_password, authenticate_with_token
middleware_module = 'corvus.middleware.authentication_middleware'
middleware_module = 'server.middleware.authentication_middleware'
@patch(middleware_module + '.g') @patch(middleware_module + '.g')

4
server/tests/service/test_authentication_service.py

@ -1,7 +1,7 @@
import pytest import pytest
from corvus import errors
from corvus.service import authentication_service
from server import errors
from server.service import authentication_service
def test_validate_password_strength_good_password(): def test_validate_password_strength_good_password():

6
server/tests/service/test_patch_service.py

@ -3,9 +3,9 @@ from datetime import datetime, timedelta
import pytest import pytest
from mock import MagicMock, patch from mock import MagicMock, patch
from corvus import errors
from corvus.model import UserToken, User
from corvus.service import patch_service, role_service
from server import errors
from server.model import UserToken, User
from server.service import patch_service, role_service
def test_patch_models(): def test_patch_models():

2
server/tests/service/test_role_service.py

@ -1,4 +1,4 @@
from corvus.service.role_service import ROLES, Role
from server.service.role_service import ROLES, Role
def test_role_tree_find_roles_in_hierarchy(): def test_role_tree_find_roles_in_hierarchy():

8
server/tests/service/test_transformation_service.py

@ -2,14 +2,14 @@ from typing import Dict, Callable, Any
import pytest import pytest
from corvus import db
from corvus.model import UserToken
from corvus.service.transformation_service import (
from server import db
from server.model import UserToken
from server.service.transformation_service import (
BaseTransformer, BaseTransformer,
deserialize_model, deserialize_model,
register_transformer, register_transformer,
serialize_model) serialize_model)
from corvus.service.user_token_service import UserTokenTransformer
from server.service.user_token_service import UserTokenTransformer
def test_serialize_model(): def test_serialize_model():

4
server/tests/service/test_validation_service.py

@ -1,5 +1,5 @@
from corvus.model import User
from corvus.service import role_service, validation_service
from server.model import User
from server.service import role_service, validation_service
def test_successful_validation(): def test_successful_validation():

Loading…
Cancel
Save