diff --git a/.env b/.env index b6c313d930357154a23de1d2203de0cab62a0836..e028ff2c7c7b709ba904887c02151414753c63ba 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ POSTGRES_USER=ics POSTGRES_PASSWORD=icspwd -POSTGRES_DB=inventory_db +POSTGRES_DB=csentry_db PGDATA_VOLUME=./data diff --git a/Dockerfile b/Dockerfile index 0d66256e06aa0cdb07a2dc18dcb310783f54b9af..e34a3eabc607a3acdb71efb14191b65ccd2c735e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,15 +11,15 @@ RUN apt-get update && apt-get install -y \ gcc \ && rm -rf /var/lib/apt/lists/* -# Install inventory requirements +# Install CSEntry requirements COPY environment.yml /app/environment.yml RUN conda config --add channels conda-forge \ - && conda env create -n inventory -f environment.yml \ + && conda env create -n csentry -f environment.yml \ && rm -rf /opt/conda/pkgs/* # Install the app COPY . /app/ RUN chown -R ics:ics /app/* -# activate the inventory environment -ENV PATH /opt/conda/envs/inventory/bin:$PATH +# activate the csentry environment +ENV PATH /opt/conda/envs/csentry/bin:$PATH diff --git a/Makefile b/Makefile index b4656cf6a7cbf847dfee4a3b314158c246617059..4f6e4c54227735dbcb409aeccc84154c8ceb9346 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,13 @@ OWNER := europeanspallationsource GIT_TAG := $(shell git describe --always) -IMAGE := ics-inventory +IMAGE := csentry help: # http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html - @echo "ics-inventory" - @echo "=============" + @echo "CSEntry" + @echo "=======" @echo @grep -E '^[a-zA-Z0-9_%/-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @@ -24,7 +24,7 @@ push: ## push the latest and git tag image clean: ## remove the image with git tag and the test database -docker rmi $(OWNER)/$(IMAGE):$(GIT_TAG) - -docker rm -f inventory_postgres + -docker rm -f csentry_postgres refresh: ## pull the latest image from Docker Hub # skip if error: image might not be on dockerhub yet diff --git a/README.rst b/README.rst index 338cf8b9dde33e81672c749dc4b55d3eee4c2c0b..4992db33a384d7d06fab69b9740a440e9cc9516d 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ -ICS inventory -============= +CSEntry +======= -ICS inventory web server. +Control System Entry web server. Development @@ -68,11 +68,11 @@ Backup & restore To dump the database:: - $ docker run --rm --link inventory_postgres:postgres --net inventory_default -e PGPASSWORD="<inventory_password>" - postgres:9.6 pg_dump -h postgres -U inventory inventory_db | gzip > inventory_db.dump.gz + $ docker run --rm --link csentry_postgres:postgres --net csentry_default -e PGPASSWORD="<csentry_password>" + postgres:9.6 pg_dump -h postgres -U csentry csentry_db | gzip > csentry_db.dump.gz To restore the database:: - $ gunzip -c inventory_db.dump.g | docker run --rm --link inventory_postgres:postgres --net inventory_default - -e PGPASSWORD="<inventory_password>" -i postgres:9.6 psql -h postgres -U inventory inventory_db + $ gunzip -c csentry_db.dump.g | docker run --rm --link csentry_postgres:postgres --net csentry_default + -e PGPASSWORD="<csentry_password>" -i postgres:9.6 psql -h postgres -U csentry csentry_db diff --git a/app/api/main.py b/app/api/main.py index b2da8f6cdad4d0a24b83b5643d8eae8335f9e91f..e2cf9ca50382db8cd61a974147881cc5f284cbe5 100644 --- a/app/api/main.py +++ b/app/api/main.py @@ -31,7 +31,7 @@ def get_item_by_id_or_ics_id(id_): else: item = Item.query.get(item_id) if item is None: - raise utils.InventoryError(f"Item id '{id_}' not found", status_code=404) + raise utils.CSEntryError(f"Item id '{id_}' not found", status_code=404) return item @@ -51,21 +51,21 @@ def get_generic_model(model, args): def create_generic_model(model, mandatory_field='name'): data = request.get_json() if data is None: - raise utils.InventoryError('Body should be a JSON object') + raise utils.CSEntryError('Body should be a JSON object') current_app.logger.debug(f'Received: {data}') if mandatory_field not in data: - raise utils.InventoryError(f"Missing mandatory field '{mandatory_field}'", status_code=422) + raise utils.CSEntryError(f"Missing mandatory field '{mandatory_field}'", status_code=422) try: instance = model(**data) except TypeError as e: message = str(e).replace('__init__() got an ', '') - raise utils.InventoryError(message) + raise utils.CSEntryError(message) db.session.add(instance) try: db.session.commit() except sa.exc.IntegrityError as e: db.session.rollback() - raise utils.InventoryError('IntegrityError', status_code=409) + raise utils.CSEntryError('IntegrityError', status_code=409) return jsonify(instance.to_dict()), 201 @@ -73,12 +73,12 @@ def create_generic_model(model, mandatory_field='name'): def login(): data = request.get_json() if data is None: - raise utils.InventoryError('Body should be a JSON object') + raise utils.CSEntryError('Body should be a JSON object') try: username = data['username'] password = data['password'] except KeyError: - raise utils.InventoryError('Missing mandatory field (username or password)', status_code=422) + raise utils.CSEntryError('Missing mandatory field (username or password)', status_code=422) response = ldap_manager.authenticate(username, password) if response.status == AuthenticationResponseStatus.success: current_app.logger.debug(f'{username} successfully logged in') @@ -89,7 +89,7 @@ def login(): response.user_groups) payload = {'access_token': create_access_token(identity=user.id)} return jsonify(payload), 200 - raise utils.InventoryError('Invalid credentials', status_code=401) + raise utils.CSEntryError('Invalid credentials', status_code=401) @bp.route('/items') @@ -141,19 +141,19 @@ def patch_item(id_): """ data = request.get_json() if data is None: - raise utils.InventoryError('Body should be a JSON object') + raise utils.CSEntryError('Body should be a JSON object') if not data: - raise utils.InventoryError('At least one field is required', status_code=422) + raise utils.CSEntryError('At least one field is required', status_code=422) for key in data.keys(): if key not in ('ics_id', 'manufacturer', 'model', 'location', 'status', 'parent'): - raise utils.InventoryError(f"Invalid field '{key}'", status_code=422) + raise utils.CSEntryError(f"Invalid field '{key}'", status_code=422) item = get_item_by_id_or_ics_id(id_) # Only allow to set ICS id if it's null if item.ics_id is None: item.ics_id = data.get('ics_id') elif 'ics_id' in data: - raise utils.InventoryError("'ics_id' can't be changed", status_code=422) + raise utils.CSEntryError("'ics_id' can't be changed", status_code=422) item.manufacturer = utils.convert_to_model(data.get('manufacturer', item.manufacturer), Manufacturer) item.model = utils.convert_to_model(data.get('model', item.model), Model) item.location = utils.convert_to_model(data.get('location', item.location), Location) @@ -174,7 +174,7 @@ def patch_item(id_): db.session.commit() except sa.exc.IntegrityError as e: db.session.rollback() - raise utils.InventoryError('IntegrityError', status_code=409) + raise utils.CSEntryError('IntegrityError', status_code=409) return jsonify(item.to_dict()) diff --git a/app/decorators.py b/app/decorators.py index bdf40ab2956ae4e088ae6e7651bd5b05f839bfc7..90da276eac6e824e128ef4a4cacd67309b11f9bb 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -13,7 +13,7 @@ from functools import wraps from flask import current_app, abort from flask_login import current_user from flask_jwt_extended import get_current_user -from .utils import InventoryError +from .utils import CSEntryError def jwt_groups_accepted(*groups): @@ -38,9 +38,9 @@ def jwt_groups_accepted(*groups): def decorated_view(*args, **kwargs): user = get_current_user() if user is None: - raise InventoryError('Invalid indentity', status_code=403) + raise CSEntryError('Invalid indentity', status_code=403) if not user.is_member_of_one_group(groups): - raise InventoryError("User doesn't have the required group", status_code=403) + raise CSEntryError("User doesn't have the required group", status_code=403) return fn(*args, **kwargs) return decorated_view return wrapper diff --git a/app/factory.py b/app/factory.py index 7ffe7fc6b103d68e0385234584d26720d5ddae60..be964e41613725a7702b5e7dd4de517c0dde192a 100644 --- a/app/factory.py +++ b/app/factory.py @@ -51,7 +51,7 @@ def create_app(config=None): mail_handler = SMTPHandler(app.config['MAIL_SERVER'], fromaddr=app.config['EMAIL_SENDER'], toaddrs=app.config['ADMIN_EMAILS'], - subject='Inventory: ERROR raised', + subject='CSEntry: ERROR raised', credentials=app.config['MAIL_CREDENTIALS']) mail_handler.setFormatter(logging.Formatter(""" Message type: %(levelname)s @@ -77,7 +77,7 @@ def create_app(config=None): app.logger.setLevel(logging.DEBUG) handler.setLevel(logging.DEBUG) app.logger.addHandler(handler) - app.logger.info('Inventory created!') + app.logger.info('CSEntry created!') app.logger.info('Settings:\n{}'.format( '\n'.join(['{}: {}'.format(key, value) for key, value in app.config.items() if key not in ('SECRET_KEY', 'LDAP_BIND_USER_PASSWORD')]))) @@ -107,7 +107,7 @@ def create_app(config=None): app.wsgi_app = WhiteNoise(app.wsgi_app, root='static/') app.wsgi_app.add_files( - root='/opt/conda/envs/inventory/lib/python3.6/site-packages/flask_bootstrap/static/', + root='/opt/conda/envs/csentry/lib/python3.6/site-packages/flask_bootstrap/static/', prefix='bootstrap/' ) diff --git a/app/main/views.py b/app/main/views.py index f85bb390662e476baeb0822abb9eda601ceb3800..4bde3789c71fe5a9c7e9fcf611fa302c145b06a3 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -33,8 +33,8 @@ def internal_error(error): return render_template('500.html'), 500 -@bp.app_errorhandler(utils.InventoryError) -def handle_inventory_error(error): +@bp.app_errorhandler(utils.CSEntryError) +def handle_csentry_error(error): response = jsonify(error.to_dict()) response.status_code = error.status_code return response @@ -108,7 +108,7 @@ def retrieve_qrcodes_name(kind): try: model = globals()[kind] except KeyError: - raise utils.InventoryError(f"Unknown model '{kind}'", status_code=422) + raise utils.CSEntryError(f"Unknown model '{kind}'", status_code=422) items = db.session.query(model).order_by(model.name) data = [[item.name] for item in items] return jsonify(data=data) diff --git a/app/models.py b/app/models.py index 588c9dd203aebd700efb354db05bd3d4bb14e513..dce36d80498f7b81287c5ba563a96b3cfa2d32b1 100644 --- a/app/models.py +++ b/app/models.py @@ -121,16 +121,16 @@ class User(db.Model, UserMixin): @property def is_admin(self): - return current_app.config['INVENTORY_LDAP_GROUPS']['admin'] in self.groups + return current_app.config['CSENTRY_LDAP_GROUPS']['admin'] in self.groups def is_member_of_one_group(self, groups): """Return True if the user is at least member of one of the given groups""" - names = [current_app.config['INVENTORY_LDAP_GROUPS'].get(group) for group in groups] + names = [current_app.config['CSENTRY_LDAP_GROUPS'].get(group) for group in groups] return bool(set(self.groups) & set(names)) def is_member_of_all_groups(self, groups): """Return True if the user is member of all the given groups""" - names = [current_app.config['INVENTORY_LDAP_GROUPS'].get(group) for group in groups] + names = [current_app.config['CSENTRY_LDAP_GROUPS'].get(group) for group in groups] return set(names).issubset(self.groups) def __str__(self): @@ -231,7 +231,7 @@ class Item(db.Model): """Ensure the ICS id field matches the required format""" if string is not None: if ICS_ID_RE.fullmatch(string) is None: - raise utils.InventoryError('ICS id shall match [A-Z]{3}[0-9]{3}', status_code=422) + raise utils.CSEntryError('ICS id shall match [A-Z]{3}[0-9]{3}', status_code=422) return string def to_dict(self, extra=False): diff --git a/app/settings.py b/app/settings.py index 3a7cc2adc5f06131077319e3b15a792f7dbf17c4..cab395a4f93e8e424c0bddcbce5340ffd073202d 100644 --- a/app/settings.py +++ b/app/settings.py @@ -12,7 +12,7 @@ This module implements the app default settings. import os from datetime import timedelta -SQLALCHEMY_DATABASE_URI = 'postgresql://ics:icspwd@postgres/inventory_db' +SQLALCHEMY_DATABASE_URI = 'postgresql://ics:icspwd@postgres/csentry_db' SQLALCHEMY_TRACK_MODIFICATIONS = False BOOTSTRAP_SERVE_LOCAL = True SECRET_KEY = (os.environ.get('SECRET_KEY') or @@ -41,7 +41,7 @@ LDAP_GROUP_MEMBERS_ATTR = 'member' LDAP_GET_USER_ATTRIBUTES = ['cn', 'sAMAccountName', 'mail'] LDAP_GET_GROUP_ATTRIBUTES = ['cn'] -INVENTORY_LDAP_GROUPS = { +CSENTRY_LDAP_GROUPS = { 'admin': 'ICS Control System Infrastructure group', 'create': 'ICS Employees', } diff --git a/app/static/css/inventory.css b/app/static/css/csentry.css similarity index 100% rename from app/static/css/inventory.css rename to app/static/css/csentry.css diff --git a/app/static/js/inventory.js b/app/static/js/csentry.js similarity index 100% rename from app/static/js/inventory.js rename to app/static/js/csentry.js diff --git a/app/templates/404.html b/app/templates/404.html index 6d26798d54e282bc04a9ff9e6e0d26193415fee1..35155ba724a560fdccaf730ec535ac0beeb3cd90 100644 --- a/app/templates/404.html +++ b/app/templates/404.html @@ -1,6 +1,6 @@ {%- extends "base.html" %} -{% block title %}Page Not Found - ICS Inventory{% endblock %} +{% block title %}Page Not Found - CSEntry{% endblock %} {% block main %} <h1>Page Not Found</h1> diff --git a/app/templates/500.html b/app/templates/500.html index 8be15a0484667624c8e7f2d04e20a2de5204689e..175b857a33fd7cf2af11b4052404d37275852791 100644 --- a/app/templates/500.html +++ b/app/templates/500.html @@ -1,6 +1,6 @@ {%- extends "base.html" %} -{% block title %}Internal Server Error - ICS Inventory{% endblock %} +{% block title %}Internal Server Error - CSEntry{% endblock %} {% block main %} <h1>Internal Server Error</h1> diff --git a/app/templates/admin/index.html b/app/templates/admin/index.html index b121f3f492399867eb4e61cd971c4962332daea0..996ac4028d56e285468aabe48fe91b15772ff991 100644 --- a/app/templates/admin/index.html +++ b/app/templates/admin/index.html @@ -1,10 +1,10 @@ {% extends "admin/master.html" %} -{% block title %}Admin - ICS Inventory{% endblock %} +{% block title %}Admin - CSEntry{% endblock %} {% block body %} <h2>Use the admin interface with care</h2> <!-- flask-admin uses bootstrap 3 --> -<a class="btn btn-primary" href="{{ url_for('main.index') }}">ICS Inventory</a> +<a class="btn btn-primary" href="{{ url_for('main.index') }}">CSEntry</a> {% endblock %} diff --git a/app/templates/base.html b/app/templates/base.html index bd87084f6bf579111e7a83a1d060953050471478..19ed9bd0abeb2383f3ac0a3ca93677790885412a 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -5,15 +5,15 @@ {% block styles %} {{super()}} <link href="{{ url_for('static', filename='css/dataTables.bootstrap4.min.css') }}" rel="stylesheet"> - <link href="{{ url_for('static', filename='css/inventory.css') }}" rel="stylesheet"> + <link href="{{ url_for('static', filename='css/csentry.css') }}" rel="stylesheet"> {% endblock %} -{% block title %}ICS Inventory{% endblock %} +{% block title %}CSEntry{% endblock %} {% block navbar %} <!-- Fixed navbar --> <div class="navbar fixed-top navbar-expand-lg navbar-light bg-light" role="navigation"> - <a class="navbar-brand" href="{{ url_for('main.index') }}">ICS Inventory</a> + <a class="navbar-brand" href="{{ url_for('main.index') }}">CSEntry</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> @@ -69,5 +69,5 @@ <script type=text/javascript> $SCRIPT_ROOT = {{ request.script_root|tojson|safe }}; </script> - {% block inventory_scripts %}{% endblock %} + {% block csentry_scripts %}{% endblock %} {% endblock %} diff --git a/app/templates/create_qrcodes.html b/app/templates/create_qrcodes.html index a785be8f679675b1757d2b774155a2c479cff005..9b535d8ca596fc38221ff231ebff4413eefb0fe1 100644 --- a/app/templates/create_qrcodes.html +++ b/app/templates/create_qrcodes.html @@ -1,7 +1,7 @@ {%- extends "base.html" %} {% import "bootstrap/wtf.html" as wtf %} -{% block title %}Create QR Codes - ICS Inventory{% endblock %} +{% block title %}Create QR Codes - CSEntry{% endblock %} {% block main %} <h2>Create QR Codes</h2> @@ -29,6 +29,6 @@ </table> {%- endblock %} -{% block inventory_scripts %} +{% block csentry_scripts %} <script src="{{ url_for('static', filename='js/qrcodes.js') }}"></script> {% endblock %} diff --git a/app/templates/index.html b/app/templates/index.html index f76de15d8221da58c4f193f0ec99a637af071352..43c0d8205751f78c1c189dcfee36e187a3e98d59 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -2,7 +2,7 @@ {% block main %} <div class="jumbotron"> - <h1 class="display-4">Welcome to the ICS Inventory!</h1> + <h1 class="display-4">Welcome to CSEntry!</h1> </div> <table id="items_table" class="table table-bordered table-hover table-sm"> <thead> @@ -22,6 +22,6 @@ </table> {%- endblock %} -{% block inventory_scripts %} - <script src="{{ url_for('static', filename='js/inventory.js') }}"></script> +{% block csentry_scripts %} + <script src="{{ url_for('static', filename='js/csentry.js') }}"></script> {% endblock %} diff --git a/app/templates/qrcodes.html b/app/templates/qrcodes.html index 3a0bbd1a8e136a06be883e814c4d3a3f2fe55974..91aa071a46d0b056f3e1f62a7831f1562f39a44a 100644 --- a/app/templates/qrcodes.html +++ b/app/templates/qrcodes.html @@ -1,6 +1,6 @@ {%- extends "base.html" %} -{% block title %}QR Codes - ICS Inventory{% endblock %} +{% block title %}QR Codes - CSEntry{% endblock %} {% block main %} {% for name, images in codes.items() %} diff --git a/app/templates/users/login.html b/app/templates/users/login.html index 60a6cc594811bf1e592cfb94e7de6022565fe4a4..4e5f426711c134affc44aec09ea64a1c49ec2e17 100644 --- a/app/templates/users/login.html +++ b/app/templates/users/login.html @@ -1,7 +1,7 @@ {% import "bootstrap/wtf.html" as wtf %} {% extends "base.html" %} -{% block title %}Login - ICS Inventory{% endblock %} +{% block title %}Login - CSEntry{% endblock %} {% block main %} <div class="col-sm-offset-2 col-sm-4"> diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html index fc384b05d85d7584080fdad87ab619f466bf1539..70c69e106081cd76cf1147ed8721dfdff9deae7f 100644 --- a/app/templates/users/profile.html +++ b/app/templates/users/profile.html @@ -1,7 +1,7 @@ {% import "bootstrap/wtf.html" as wtf %} {% extends "base.html" %} -{% block title %}Profile - ICS Inventory{% endblock %} +{% block title %}Profile - CSEntry{% endblock %} {% block main %} <h2>{{ user.username }}</h2> diff --git a/app/templates/view_item.html b/app/templates/view_item.html index d38b1d379414b9b840fcbc75ada1f4f383df7ceb..2c039bec793cca09dbb11cc7e92fea229e274c28 100644 --- a/app/templates/view_item.html +++ b/app/templates/view_item.html @@ -1,7 +1,7 @@ {%- extends "base.html" %} {% from "_helpers.html" import link_to_item, link_to_items %} -{% block title %}View Item - ICS Inventory{% endblock %} +{% block title %}View Item - CSEntry{% endblock %} {% block main %} <h2>Item {{ item['ics_id'] }}</h2> diff --git a/app/utils.py b/app/utils.py index a369fbf48f03f73371f8992e875f3b5bddbe4c4b..7f992941d04d7c383c3a64a7aebfbb0365d782be 100644 --- a/app/utils.py +++ b/app/utils.py @@ -15,8 +15,8 @@ import io import sqlalchemy as sa -class InventoryError(Exception): - """InventoryError class +class CSEntryError(Exception): + """CSEntryError class Exception used to pass useful information to the client side (API or AJAX) """ @@ -72,7 +72,7 @@ def convert_to_model(item, model): if not isinstance(item, model): instance = model.query.filter_by(name=item).first() if instance is None: - raise InventoryError(f'{item} is not a valid {model.__name__.lower()}') + raise CSEntryError(f'{item} is not a valid {model.__name__.lower()}') return instance return item @@ -118,5 +118,5 @@ def get_query(query, args): try: query = query.filter_by(**kwargs) except (sa.exc.InvalidRequestError, AttributeError) as e: - raise InventoryError('Invalid query arguments', status_code=422) + raise CSEntryError('Invalid query arguments', status_code=422) return query diff --git a/docker-compose.yml b/docker-compose.yml index 3d94e0183c6a0028702c7501ec7a4507e24d8fec..28cc8fcbe52df49e53701354d1498fce7846f5f4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,14 @@ version: '2' services: web: - image: europeanspallationsource/ics-inventory:latest - container_name: inventory_web + image: europeanspallationsource/csentry:latest + container_name: csentry_web command: pytest --cov=app -v depends_on: - postgres postgres: image: postgres:9.6 - container_name: inventory_postgres + container_name: csentry_postgres expose: - "5432" volumes: diff --git a/environment.yml b/environment.yml index f00e2bb894e4c9909a852cbe441a1cf663343e89..f8a6e164f220b0c625247d926e46a5dcb7f3492d 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,4 @@ -name: inventory +name: csentry channels: !!python/tuple - conda-forge - defaults diff --git a/postgres/create-test-db.sh b/postgres/create-test-db.sh index da67a988c84d63c23fb90b741adc980aa9fe4868..8c723ce31038cdd446cbc95b42cbfa7f565a906c 100755 --- a/postgres/create-test-db.sh +++ b/postgres/create-test-db.sh @@ -3,5 +3,5 @@ set -e psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" -d "$POSTGRES_DB" <<-EOSQL - CREATE DATABASE inventory_db_test; + CREATE DATABASE csentry_db_test; EOSQL diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index ff9104ca598f7ba4306eb29650d196fb88810b03..71a747fe56ce6399c0ad30e81a1344b3dc60e6ee 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -22,10 +22,10 @@ def app(request): config = { 'TESTING': True, 'WTF_CSRF_ENABLED': False, - 'SQLALCHEMY_DATABASE_URI': 'postgresql://ics:icspwd@postgres/inventory_db_test', - 'INVENTORY_LDAP_GROUPS': { - 'admin': 'Inventory Admin', - 'create': 'Inventory User', + 'SQLALCHEMY_DATABASE_URI': 'postgresql://ics:icspwd@postgres/csentry_db_test', + 'CSENTRY_LDAP_GROUPS': { + 'admin': 'CSEntry Admin', + 'create': 'CSEntry User', } } app = create_app(config=config) @@ -105,11 +105,11 @@ def patch_ldap_authenticate(monkeypatch): if username == 'admin' and password == 'adminpasswd': response.status = AuthenticationResponseStatus.success response.user_info = {'cn': 'Admin User', 'mail': 'admin@example.com'} - response.user_groups = [{'cn': 'Inventory Admin'}] + response.user_groups = [{'cn': 'CSEntry Admin'}] elif username == 'user_rw' and password == 'userrw': response.status = AuthenticationResponseStatus.success response.user_info = {'cn': 'User RW', 'mail': 'user_rw@example.com'} - response.user_groups = [{'cn': 'Inventory User'}] + response.user_groups = [{'cn': 'CSEntry User'}] elif username == 'user_ro' and password == 'userro': response.status = AuthenticationResponseStatus.success response.user_info = {'cn': 'User RO', 'mail': 'user_ro@example.com'} diff --git a/tests/functional/test_web.py b/tests/functional/test_web.py index 5ac595b0710ce98236ea2b9062e765e14687a918..f26a20118606a171737ff6f59f74079c4aae9b07 100644 --- a/tests/functional/test_web.py +++ b/tests/functional/test_web.py @@ -42,19 +42,19 @@ def logged_client(request, app): def test_login_logout(client): response = login(client, 'unknown', 'invalid') - assert b'<title>Login - ICS Inventory</title>' in response.data + assert b'<title>Login - CSEntry</title>' in response.data response = login(client, 'user_rw', 'invalid') - assert b'<title>Login - ICS Inventory</title>' in response.data + assert b'<title>Login - CSEntry</title>' in response.data response = login(client, 'user_rw', 'userrw') - assert b'Welcome to the ICS Inventory!' in response.data + assert b'Welcome to CSEntry!' in response.data assert b'User RW' in response.data response = logout(client) - assert b'<title>Login - ICS Inventory</title>' in response.data + assert b'<title>Login - CSEntry</title>' in response.data def test_index(logged_client): response = logged_client.get('/') - assert b'Welcome to the ICS Inventory!' in response.data + assert b'Welcome to CSEntry!' in response.data assert b'User RO' in response.data