From 4193589df734eb768f03414f83e1709f1c3297bb Mon Sep 17 00:00:00 2001 From: "Kushal Beniwal (she/her)" Date: Sun, 11 Jul 2021 21:51:13 +0530 Subject: [PATCH] chore: integrate pre-commit (#1117) * integrate pre-commit * run isort with profile black * run Trim Trailing Whitespace * run end-of-file-fixer * fix flake8 F401: import not used error * fix flake8 F841: local variable assigned to but never used error * fix flake8 F541: f-string is missing placeholders error * make isort black compatible * run black compatible isort * fix E712: comparison to True should be 'if cond:' error * fix E266: too many leading '#' error * fix F403: 'import *' used error * fix E402: module level import not at top of file error * remove ignored errors from .flake8 * document pre-commit and isort * ignore W503, E501 & C901 * Update README.md * Update README.md * don't remove migrate --- .coveragerc | 2 +- .flake8 | 13 +++++++ .github/CONTRIBUTING.md | 6 ++-- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/config.yml | 4 +-- .github/workflows/main.yml | 6 ++-- .isort.cfg | 9 +++++ .pre-commit-config.yaml | 21 ++++++++++++ README.md | 29 ++++++++++++++++ app/api/api_extension.py | 5 +-- app/api/dao/admin.py | 5 +-- app/api/dao/mentorship_relation.py | 6 ++-- app/api/dao/task.py | 8 ++--- app/api/dao/task_comment.py | 3 +- app/api/dao/user.py | 9 ++--- app/api/email_utils.py | 12 +++---- app/api/jwt_extension.py | 4 ++- app/api/models/admin.py | 2 +- app/api/models/mentorship_relation.py | 3 +- app/api/models/task.py | 2 +- app/api/models/task_comment.py | 2 +- app/api/models/user.py | 3 +- app/api/resources/admin.py | 16 ++++++--- app/api/resources/mentorship_relation.py | 21 ++++++++---- app/api/resources/task.py | 14 +++++--- app/api/resources/task_comment.py | 17 ++++++---- app/api/resources/user.py | 32 +++++++++++++---- app/api/validations/task_comment.py | 2 +- app/api/validations/user.py | 4 +-- app/database/db_types/JsonCustomType.py | 1 + app/database/models/mentorship_relation.py | 2 -- app/database/models/tasks_list.py | 4 +-- app/database/models/user.py | 8 +++-- .../complete_mentorship_cron_job.py | 2 +- app/utils/decorator_utils.py | 3 +- app/utils/validation_utils.py | 2 +- deploy.sh | 4 +-- dev-requirements.txt | 2 +- ...Mentorship Backend.postman_collection.json | 2 +- docs/docs/Commit-Message-Style-Guide.md | 10 +++--- docs/docs/Database-Design.md | 2 +- docs/docs/Environment-Variables.md | 8 ++--- docs/docs/Fork,-Clone-&-Remote.md | 10 +++--- docs/docs/Future-ideas.md | 1 - docs/docs/GSoC-2018-Isabel-Costa.md | 14 ++++---- docs/docs/Getting-Started.md | 2 +- docs/docs/Home.md | 2 +- docs/docs/How-to-Contribute.md | 10 +++--- docs/docs/Main-Base-Concepts.md | 2 +- docs/docs/Maintainer-Guidelines.md | 2 +- .../docs/Mentorship-Relation-Documentation.md | 3 +- docs/docs/Quality-Assurance.md | 1 - .../docs/Register-a-new-user-using-Swagger.md | 2 +- docs/docs/Tech-Stack.md | 2 +- docs/docs/Technical-Decisions.md | 4 +-- docs/docs/Using-Backend-Swagger-UI.md | 2 +- docs/environment-variables.md | 2 +- docs/features.md | 2 +- docs/manual_tests/manual_tests_PUT_user.md | 25 ++++++-------- docs/manual_tests/test_confirmation_token.md | 16 ++++----- docs/manual_tests/test_resend_email.md | 6 ++-- docs/manual_tests/user_change_password.md | 20 +++++------ docs/manual_tests/user_refresh_token.md | 20 +++++------ docs/quality-assurance-test-cases.md | 2 +- docs/reporting_guidelines.md | 2 +- docs/src/pages/styles.module.css | 4 +-- docs/test-pr-guide.md | 34 +++++++++---------- docs/troubleshoots.md | 4 +-- migrations/README | 2 +- migrations/env.py | 15 ++++---- pyproject.toml | 15 ++++++++ requirements.txt | 1 + run.py | 5 +-- tests/admin/test_api_list_admin_users.py | 8 ++--- tests/admin/test_api_remove_admin_user.py | 10 ++---- tests/admin/test_dao.py | 15 ++++---- tests/base_test_case.py | 3 +- .../test_delete_unverified_users_cron.py | 1 - .../test_mentorship_completion_cron.py | 4 +-- .../relation_base_setup.py | 2 +- .../test_api_accept_request.py | 4 +-- .../test_api_cancel_relation.py | 3 +- .../test_api_delete_request.py | 2 +- .../test_api_list_relations.py | 2 +- .../test_api_reject_request.py | 2 +- .../test_api_send_request.py | 4 --- .../test_dao_accept_request.py | 3 +- .../test_dao_cancel_relation.py | 5 ++- .../mentorship_relation/test_dao_creation.py | 2 +- .../test_dao_delete_request.py | 4 +-- tests/mentorship_relation/test_dao_listing.py | 3 +- .../test_dao_reject_mentorship_request.py | 3 +- .../test_database_model.py | 8 ++--- .../test_api_create_task_comment.py | 2 +- .../test_api_delete_task_comment.py | 2 +- .../test_api_get_task_comments.py | 2 +- .../test_api_modify_task_comment.py | 2 +- tests/task_comments/test_dao.py | 2 +- tests/tasks/tasks_base_setup.py | 2 +- tests/tasks/test_api_complete_task.py | 3 +- tests/tasks/test_api_create_task.py | 5 +-- tests/tasks/test_api_delete_task.py | 3 +- tests/tasks/test_api_list_tasks.py | 3 +- tests/tasks/test_dao_complete_task.py | 1 - tests/tasks/test_dao_delete_task.py | 1 - tests/test_app_config.py | 2 +- tests/test_flask_app.py | 3 +- tests/user_journey/test_happy_path_1.py | 13 ++----- tests/users/test_api_authentication.py | 3 +- tests/users/test_api_change_password.py | 9 +++-- tests/users/test_api_get_other_user.py | 2 +- tests/users/test_api_home_statistics.py | 4 ++- tests/users/test_api_list_users.py | 5 +-- tests/users/test_api_login.py | 5 ++- tests/users/test_api_refresh.py | 3 +- tests/users/test_api_resources.py | 10 +++--- tests/users/test_api_update_user.py | 3 +- tests/users/test_dao.py | 8 +++-- tests/users/test_dao_dashboard.py | 7 ++-- tests/users/test_database_model.py | 4 +-- tests/users/test_validation_request_data.py | 8 ++--- ...est_validation_update_user_request_data.py | 2 +- tests/utils/test_email_validation.py | 1 + .../test_get_length_validation_error_msg.py | 1 + tests/utils/test_get_stripped_string.py | 1 + tests/utils/test_name_validation.py | 1 + tests/utils/test_username_validation.py | 1 + tests/utils/test_validate_length.py | 3 +- 128 files changed, 435 insertions(+), 324 deletions(-) create mode 100644 .flake8 create mode 100644 .isort.cfg create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.coveragerc b/.coveragerc index 03649d4bc..3091db729 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,4 @@ [run] -omit = +omit = # omit everything in the tests directory tests/* diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..ea176245c --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +ignore = + # W503: line break before binary operator + # ignored as it creates inconsistency with black + W503, + # E501: line too long (> 88 characters) + # ignored till a final decision is made on what to do with long comments + E501, + # C901: variable or function name is too complex (> 18 characters) + # ignored till someone simplifies the names + C901 +max-line-length = 88 +max-complexity = 18 diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index c32c94a25..c633ac9c1 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -7,16 +7,16 @@ * When developing a new feature, include at least one test when applicable. * When submitting a PR, please follow [this template](PULL_REQUEST_TEMPLATE.md) (which will probably be already filled up once you create the PR). * When submitting a PR with changes to user interface (e.g.: new screen, or an email template), please add screenshots to the PR description. -* When you are finished with your work, please squash your commits otherwise we will squash them on your PR (this can help us maintain a clear commit history). +* When you are finished with your work, please squash your commits otherwise we will squash them on your PR (this can help us maintain a clear commit history). * When writing in-code documentation as Docstrings, please follow [this guide](https://github.com/google/styleguide/blob/gh-pages/pyguide.md#38-comments-and-docstrings). * When creating an issue to report a bug in the project, please follow our [bug_report.md](https://github.com/anitab-org/.github/blob/main/.github/ISSUE_TEMPLATE/bug_report.md) template. ## General Guidelines * If you’re just getting started work on an issue labeled “First Timers Only” in any project. Additional resources are available on our [website](http://www.systers.io). -* In an active repository (not an archived one), choose an open issue from the issue list, claim it in the comments, and a maintainer will assign it to you. +* In an active repository (not an archived one), choose an open issue from the issue list, claim it in the comments, and a maintainer will assign it to you. * After approval you must make continuous notes on your progress in the issue while working. If there is not at least one comment every 3 days, the maintainer can reassign the issue. * Create a branch specific to the issue you're working on, so that you send a PR from that branch instead of the base branch on your fork. -* If you’d like to create a new issue, please go through our issue list first (open as well as closed) and make sure the issues you are reporting do not replicate the existing issues. +* If you’d like to create a new issue, please go through our issue list first (open as well as closed) and make sure the issues you are reporting do not replicate the existing issues. * Have a short description on what has gone wrong (like a root cause analysis and description of the fix), if that information is not already present in the issue. * If you have issues on multiple pages, report them separately. Do not combine them into a single issue. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8877455b9..415e550bd 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -41,7 +41,7 @@ Fixes # [ISSUE] **Code/Quality Assurance Only** -- [ ] My changes generate no new warnings +- [ ] My changes generate no new warnings - [ ] My PR currently breaks something (fix or feature that would cause existing functionality to not work as expected) - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes diff --git a/.github/config.yml b/.github/config.yml index 664142e8d..0b37c322f 100644 --- a/.github/config.yml +++ b/.github/config.yml @@ -7,7 +7,7 @@ newIssueWelcomeComment: | Hello there!👋 Welcome to the project!💖 Thank you and congrats 🎉 for opening your very first issue in this project. - AnitaB.org Open Source is an inclusive community, committed to creating a safe and positive environment 🌸 Please follow our [Code Of Conduct](https://github.com/anitab-org/mentorship-backend/blob/develop/docs/code_of_conduct.md) 🙌 + AnitaB.org Open Source is an inclusive community, committed to creating a safe and positive environment 🌸 Please follow our [Code Of Conduct](https://github.com/anitab-org/mentorship-backend/blob/develop/docs/code_of_conduct.md) 🙌 You can learn more about the community on [our website](https://anitab-org.github.io/) and [documentation repository](https://github.com/anitab-org/documentation#readme). You may submit a PR on the same if you like! @@ -39,7 +39,7 @@ firstPRMergeComment: | Woohoo!🎊 Congrats on merging your first contribution to [mentorship-backend](https://github.com/anitab-org/mentorship-backend)!✨ Your code is officially a part of AnitaB.org Open Source now!! Time for a celebration 🙌🎉⚡️ Feel free to explore more on this project.🤗 - Join us on [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). 🤝 + Join us on [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). 🤝 We have different streams for each active repository for discussions. 👩🏽‍💻🧑🏼‍💻 Do join our weekly check-in stream to share your weekly goals and the awesome work you did here.😃 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eeb550468..8948b7da3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,12 +6,12 @@ name: Lint Code and Run Tests on: pull_request: branches: [develop] - paths-ignore: + paths-ignore: - '**.md' - /docs/CODEOWNERS push: branches: [develop] - paths-ignore: + paths-ignore: - '**.md' - /docs/CODEOWNERS @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - uses: psf/black@stable + - uses: psf/black@stable build: needs: lint diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 000000000..52d865e88 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,9 @@ +[tool.isort] +profile = "black" +multi_line_output = 3 + +[settings] +line_length = 88 +multi_line_output = 3 +include_trailing_comma = True +known_third_party = celery,django,environ,pyquery,pytz,redis,requests,rest_framework diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..eb26872f7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: 21.5b1 + hooks: + - id: black + args: [--check] +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.9.2 + hooks: + - id: flake8 +- repo: https://github.com/pycqa/isort + rev: 5.8.0 + hooks: + - id: isort + args: [--profile, black, -c] diff --git a/README.md b/README.md index 5620a3fbe..7083c4378 100644 --- a/README.md +++ b/README.md @@ -209,6 +209,35 @@ To run black: black . ``` +#### Sorting imports with isort + +We use [_isort_](https://pypi.org/project/isort/) to sort imports alphabetically, and automatically separated into +sections and by type. To install _isort_: + +``` +pip install isort +``` + +To run isort: + +``` +isort . --profile=black +``` + +#### Automate auto-formatting tools with pre-commit + +We use [_pre-commit_](https://pre-commit.com/) to check formatting before every commit message. To install _pre-commit_: + +``` +pip install pre-commit +``` + +To set up the git hook scripts: + +``` +pre-commit install +``` + ## Documentation Documentation for the project is hosted [here](https://anitab-org.github.io/mentorship-backend/). We use Docusaurus for maintaining the documentation of the project. diff --git a/app/api/api_extension.py b/app/api/api_extension.py index 8f5bce472..da985320a 100644 --- a/app/api/api_extension.py +++ b/app/api/api_extension.py @@ -1,7 +1,5 @@ from flask_restx import Api -# Adding namespaces -from app.api.resources.user import users_ns as user_namespace from app.api.resources.admin import admin_ns as admin_namespace from app.api.resources.mentorship_relation import ( mentorship_relation_ns as mentorship_namespace, @@ -9,6 +7,9 @@ from app.api.resources.task import task_ns as task_namespace from app.api.resources.task_comment import task_comment_ns as task_comment_namespace +# Adding namespaces +from app.api.resources.user import users_ns as user_namespace + def androidlink(): return "Android" diff --git a/app/api/dao/admin.py b/app/api/dao/admin.py index 46254c05c..2f82b3a3b 100644 --- a/app/api/dao/admin.py +++ b/app/api/dao/admin.py @@ -1,5 +1,6 @@ -from typing import Dict from http import HTTPStatus +from typing import Dict + from app import messages from app.database.models.user import UserModel from app.utils.decorator_utils import email_verification_required @@ -65,7 +66,7 @@ def revoke_admin_user(user_id: int, data: Dict[str, str]): """ admin_user_id = data["user_id"] - admin_count = UserModel.query.filter(UserModel.is_admin == True).count() + admin_count = UserModel.query.filter(UserModel.is_admin).count() if user_id == admin_user_id and admin_count == 1: return messages.USER_CANNOT_REVOKE_ADMIN_STATUS, HTTPStatus.FORBIDDEN diff --git a/app/api/dao/mentorship_relation.py b/app/api/dao/mentorship_relation.py index 21dd526e4..b18c9de1f 100644 --- a/app/api/dao/mentorship_relation.py +++ b/app/api/dao/mentorship_relation.py @@ -1,6 +1,7 @@ from datetime import datetime, timedelta -from typing import Dict from http import HTTPStatus +from typing import Dict + from app import messages from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel @@ -242,7 +243,6 @@ def reject_request(user_id: int, request_id: int): message: A message corresponding to the completed action; success if mentorship relation request is rejected, failure if otherwise. """ - user = UserModel.find_by_id(user_id) request = MentorshipRelationModel.find_by_id(request_id) # verify if request exists @@ -286,7 +286,6 @@ def cancel_relation(user_id: int, relation_id: int): message: A message corresponding to the completed action; success if mentorship relation is terminated, failure if otherwise. """ - user = UserModel.find_by_id(user_id) request = MentorshipRelationModel.find_by_id(relation_id) # verify if request exists @@ -325,7 +324,6 @@ def delete_request(user_id: int, request_id: int): message: A message corresponding to the completed action; success if mentorship relation request is deleted, failure if otherwise. """ - user = UserModel.find_by_id(user_id) request = MentorshipRelationModel.find_by_id(request_id) # verify if request exists diff --git a/app/api/dao/task.py b/app/api/dao/task.py index 6bf92055c..caae346d4 100644 --- a/app/api/dao/task.py +++ b/app/api/dao/task.py @@ -1,9 +1,9 @@ from datetime import datetime -from typing import Dict from http import HTTPStatus +from typing import Dict + from app import messages from app.database.models.mentorship_relation import MentorshipRelationModel -from app.database.models.user import UserModel from app.utils.decorator_utils import email_verification_required from app.utils.enum_utils import MentorshipRelationState @@ -31,7 +31,6 @@ def create_task(user_id: int, mentorship_relation_id: int, data: Dict[str, str]) description = data["description"] - user = UserModel.find_by_id(user_id) relation = MentorshipRelationModel.find_by_id(_id=mentorship_relation_id) if relation is None: return messages.MENTORSHIP_RELATION_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND @@ -68,7 +67,6 @@ def list_tasks(user_id: int, mentorship_relation_id: int): mentorship relation as a string. The last element is the HTTP response code """ - user = UserModel.find_by_id(user_id) relation = MentorshipRelationModel.find_by_id(mentorship_relation_id) if relation is None: return messages.MENTORSHIP_RELATION_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND @@ -101,7 +99,6 @@ def delete_task(user_id: int, mentorship_relation_id: int, task_id: int): task was deleted successfully or not as a string. The last element is the HTTP response code. """ - user = UserModel.find_by_id(user_id) relation = MentorshipRelationModel.find_by_id(mentorship_relation_id) if relation is None: return messages.MENTORSHIP_RELATION_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND @@ -138,7 +135,6 @@ def complete_task(user_id: int, mentorship_relation_id: int, task_id: int): if the task was set to complete successfully or not as a string. The last element is the HTTP response code. """ - user = UserModel.find_by_id(user_id) relation = MentorshipRelationModel.find_by_id(mentorship_relation_id) if relation is None: return messages.MENTORSHIP_RELATION_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND diff --git a/app/api/dao/task_comment.py b/app/api/dao/task_comment.py index e0e3c8048..c01e81a15 100644 --- a/app/api/dao/task_comment.py +++ b/app/api/dao/task_comment.py @@ -1,9 +1,10 @@ +from http import HTTPStatus + from app import messages from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.task_comment import TaskCommentModel from app.utils.decorator_utils import email_verification_required from app.utils.enum_utils import MentorshipRelationState -from http import HTTPStatus def validate_data_for_task_comment(user_id, task_id, relation_id): diff --git a/app/api/dao/user.py b/app/api/dao/user.py index c38343917..8f408a297 100644 --- a/app/api/dao/user.py +++ b/app/api/dao/user.py @@ -1,18 +1,19 @@ from datetime import datetime -from operator import itemgetter from http import HTTPStatus +from operator import itemgetter from typing import Dict + from flask_restx import marshal from sqlalchemy import func from app import messages +from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.api.email_utils import confirm_token +from app.api.models.task import list_tasks_response_body +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.user import UserModel from app.utils.decorator_utils import email_verification_required from app.utils.enum_utils import MentorshipRelationState -from app.database.models.mentorship_relation import MentorshipRelationModel -from app.api.models.task import list_tasks_response_body -from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.utils.validation_utils import is_email_valid diff --git a/app/api/email_utils.py b/app/api/email_utils.py index fe912815d..91d67ec8c 100644 --- a/app/api/email_utils.py +++ b/app/api/email_utils.py @@ -1,8 +1,8 @@ import datetime -from itsdangerous import URLSafeTimedSerializer, BadSignature -from flask_mail import Message from flask import render_template +from flask_mail import Message +from itsdangerous import BadSignature, URLSafeTimedSerializer import config from app.api.mail_extension import mail @@ -81,10 +81,10 @@ def send_email_verification_message(user_name, email): email: User email address. """ confirmation_token = generate_confirmation_token(email) - from app.api.resources.user import ( - UserEmailConfirmation, - ) # import here to avoid circular imports from app.api.api_extension import api + from app.api.resources.user import ( # import here to avoid circular imports + UserEmailConfirmation, + ) confirm_url = api.url_for( UserEmailConfirmation, token=confirmation_token, _external=True @@ -108,8 +108,8 @@ def send_email_mentorship_relation_accepted(request_id): request_id: Request id of the mentorship request. """ - from app.database.models.user import UserModel from app.database.models.mentorship_relation import MentorshipRelationModel + from app.database.models.user import UserModel # Getting the request from id. request = MentorshipRelationModel.find_by_id(request_id) diff --git a/app/api/jwt_extension.py b/app/api/jwt_extension.py index a76d76233..cef92e2c9 100644 --- a/app/api/jwt_extension.py +++ b/app/api/jwt_extension.py @@ -1,5 +1,7 @@ -from flask_jwt_extended import JWTManager from http import HTTPStatus + +from flask_jwt_extended import JWTManager + from app import messages from app.api.api_extension import api diff --git a/app/api/models/admin.py b/app/api/models/admin.py index a420a2293..1d0835129 100644 --- a/app/api/models/admin.py +++ b/app/api/models/admin.py @@ -1,4 +1,4 @@ -from flask_restx import fields, Model +from flask_restx import Model, fields def add_models_to_namespace(api_namespace): diff --git a/app/api/models/mentorship_relation.py b/app/api/models/mentorship_relation.py index bd25f4c69..441c382d6 100644 --- a/app/api/models/mentorship_relation.py +++ b/app/api/models/mentorship_relation.py @@ -1,6 +1,7 @@ -from flask_restx import fields, Model +from flask_restx import Model, fields from app.utils.enum_utils import MentorshipRelationState + from .task import create_task_request_body, list_tasks_response_body from .task_comment import task_comment_model, task_comments_model diff --git a/app/api/models/task.py b/app/api/models/task.py index d5f7b931a..05f1e36d0 100644 --- a/app/api/models/task.py +++ b/app/api/models/task.py @@ -1,4 +1,4 @@ -from flask_restx import fields, Model +from flask_restx import Model, fields def add_models_to_namespace(api_namespace): diff --git a/app/api/models/task_comment.py b/app/api/models/task_comment.py index c6f3df89f..aea41434b 100644 --- a/app/api/models/task_comment.py +++ b/app/api/models/task_comment.py @@ -1,4 +1,4 @@ -from flask_restx import fields, Model +from flask_restx import Model, fields def add_models_to_namespace(api_namespace): diff --git a/app/api/models/user.py b/app/api/models/user.py index 0e64af608..bf20bb37a 100644 --- a/app/api/models/user.py +++ b/app/api/models/user.py @@ -1,4 +1,5 @@ -from flask_restx import fields, Model +from flask_restx import Model, fields + from app.api.models.mentorship_relation import ( mentorship_request_response_body_for_user_dashboard_body, ) diff --git a/app/api/resources/admin.py b/app/api/resources/admin.py index 7b207377d..fb822909b 100644 --- a/app/api/resources/admin.py +++ b/app/api/resources/admin.py @@ -1,11 +1,17 @@ -from flask import request -from flask_restx import Resource, Namespace, marshal -from flask_jwt_extended import jwt_required, get_jwt_identity from http import HTTPStatus + +from flask import request +from flask_jwt_extended import get_jwt_identity, jwt_required +from flask_restx import Namespace, Resource, marshal + from app import messages -from app.api.dao.user import UserDAO -from app.api.models.admin import * from app.api.dao.admin import AdminDAO +from app.api.dao.user import UserDAO +from app.api.models.admin import ( + add_models_to_namespace, + assign_and_revoke_user_admin_request_body, + public_admin_user_api_model, +) from app.api.resources.common import auth_header_parser admin_ns = Namespace("Admins", description="Operations related to Admin users") diff --git a/app/api/resources/mentorship_relation.py b/app/api/resources/mentorship_relation.py index 0e6df286b..839bc4da8 100644 --- a/app/api/resources/mentorship_relation.py +++ b/app/api/resources/mentorship_relation.py @@ -1,16 +1,23 @@ -from flask import request -from flask_restx import Resource, Namespace, marshal -from flask_jwt_extended import jwt_required, get_jwt_identity from http import HTTPStatus +from flask import request +from flask_jwt_extended import get_jwt_identity, jwt_required +from flask_restx import Namespace, Resource, marshal + from app import messages -from app.api.resources.common import auth_header_parser from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.api.dao.user import UserDAO -from app.api.models.mentorship_relation import * +from app.api.email_utils import ( + send_email_mentorship_relation_accepted, + send_email_new_request, +) +from app.api.models.mentorship_relation import ( + add_models_to_namespace, + mentorship_request_response_body, + send_mentorship_request_body, +) +from app.api.resources.common import auth_header_parser from app.database.models.mentorship_relation import MentorshipRelationModel -from app.api.email_utils import send_email_mentorship_relation_accepted -from app.api.email_utils import send_email_new_request mentorship_relation_ns = Namespace( "Mentorship Relation", diff --git a/app/api/resources/task.py b/app/api/resources/task.py index a818e9a88..5c703e28b 100644 --- a/app/api/resources/task.py +++ b/app/api/resources/task.py @@ -1,13 +1,17 @@ -from flask import request -from flask_restx import Resource, Namespace, marshal -from flask_jwt_extended import jwt_required, get_jwt_identity from http import HTTPStatus +from flask import request +from flask_jwt_extended import get_jwt_identity, jwt_required +from flask_restx import Namespace, Resource, marshal + from app import messages from app.api.dao.task import TaskDAO +from app.api.models.task import ( + add_models_to_namespace, + create_task_request_body, + list_tasks_response_body, +) from app.api.resources.common import auth_header_parser -from app.api.models.task import * - task_ns = Namespace( "Task", diff --git a/app/api/resources/task_comment.py b/app/api/resources/task_comment.py index d4b048578..99ec21288 100644 --- a/app/api/resources/task_comment.py +++ b/app/api/resources/task_comment.py @@ -1,13 +1,18 @@ -from flask import request -from flask_restx import Resource, Namespace, marshal -from flask_jwt_extended import jwt_required, get_jwt_identity from http import HTTPStatus + +from flask import request +from flask_jwt_extended import get_jwt_identity, jwt_required +from flask_restx import Namespace, Resource, marshal + from app import messages +from app.api.dao.task_comment import TaskCommentDAO +from app.api.models.task_comment import ( + add_models_to_namespace, + task_comment_model, + task_comments_model, +) from app.api.resources.common import auth_header_parser - from app.api.validations.task_comment import validate_task_comment_request_data -from app.api.dao.task_comment import TaskCommentDAO -from app.api.models.task_comment import * task_comment_ns = Namespace( "Task comment", diff --git a/app/api/resources/user.py b/app/api/resources/user.py index e8fa9ce83..cb546535f 100644 --- a/app/api/resources/user.py +++ b/app/api/resources/user.py @@ -1,21 +1,39 @@ -from datetime import datetime from http import HTTPStatus + from flask import request from flask_jwt_extended import ( - jwt_required, - jwt_refresh_token_required, create_access_token, create_refresh_token, get_jwt_identity, + jwt_refresh_token_required, + jwt_required, ) -from flask_restx import Resource, marshal, Namespace +from flask_restx import Namespace, Resource, marshal from app import messages -from app.api.validations.user import * -from app.api.email_utils import send_email_verification_message -from app.api.models.user import * from app.api.dao.user import UserDAO +from app.api.email_utils import send_email_verification_message +from app.api.models.user import ( + add_models_to_namespace, + change_password_request_data_model, + dashboard_response_body_model, + full_user_api_model, + home_response_body_model, + login_request_body_model, + login_response_body_model, + public_user_api_model, + refresh_response_body_model, + register_user_api_model, + resend_email_request_body_model, + update_user_request_body_model, +) from app.api.resources.common import auth_header_parser, refresh_auth_header_parser +from app.api.validations.user import ( + validate_new_password, + validate_resend_email_request_data, + validate_update_profile_request_data, + validate_user_registration_request_data, +) users_ns = Namespace("Users", description="Operations related to users") add_models_to_namespace(users_ns) diff --git a/app/api/validations/task_comment.py b/app/api/validations/task_comment.py index 13597cd85..470065511 100644 --- a/app/api/validations/task_comment.py +++ b/app/api/validations/task_comment.py @@ -1,5 +1,5 @@ from app import messages -from app.utils.validation_utils import validate_length, get_stripped_string +from app.utils.validation_utils import get_stripped_string, validate_length COMMENT_MAX_LENGTH = 400 diff --git a/app/api/validations/user.py b/app/api/validations/user.py index a88ee6ead..02eba7bdf 100644 --- a/app/api/validations/user.py +++ b/app/api/validations/user.py @@ -1,10 +1,10 @@ from app import messages from app.utils.validation_utils import ( - is_name_valid, + get_stripped_string, is_email_valid, + is_name_valid, is_username_valid, validate_length, - get_stripped_string, ) # Field character limit diff --git a/app/database/db_types/JsonCustomType.py b/app/database/db_types/JsonCustomType.py index 1f9ed0518..36a0c4811 100644 --- a/app/database/db_types/JsonCustomType.py +++ b/app/database/db_types/JsonCustomType.py @@ -1,4 +1,5 @@ import json + from app.database.sqlalchemy_extension import db diff --git a/app/database/models/mentorship_relation.py b/app/database/models/mentorship_relation.py index d3d4be6cc..9054bd06f 100644 --- a/app/database/models/mentorship_relation.py +++ b/app/database/models/mentorship_relation.py @@ -1,5 +1,3 @@ -from datetime import date - from app.database.models.tasks_list import TasksListModel from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db diff --git a/app/database/models/tasks_list.py b/app/database/models/tasks_list.py index b69269d54..0ad78818a 100644 --- a/app/database/models/tasks_list.py +++ b/app/database/models/tasks_list.py @@ -1,8 +1,8 @@ -from enum import unique, Enum +from datetime import date +from enum import Enum, unique from app.database.db_types.JsonCustomType import JsonCustomType from app.database.sqlalchemy_extension import db -from datetime import date class TasksListModel(db.Model): diff --git a/app/database/models/user.py b/app/database/models/user.py index 075b7eb07..90cd11979 100644 --- a/app/database/models/user.py +++ b/app/database/models/user.py @@ -1,5 +1,7 @@ -from werkzeug.security import generate_password_hash, check_password_hash import time + +from werkzeug.security import check_password_hash, generate_password_hash + from app.database.sqlalchemy_extension import db @@ -59,7 +61,7 @@ class UserModel(db.Model): def __init__(self, name, username, password, email, terms_and_conditions_checked): """Initialises userModel class with name, username, password, email, and terms_and_conditions_checked.""" - ## required fields + # required fields self.name = name self.username = username @@ -74,7 +76,7 @@ def __init__(self, name, username, password, email, terms_and_conditions_checked self.is_email_verified = False self.registration_date = time.time() - ## optional fields + # optional fields self.need_mentoring = False self.available_to_mentor = False diff --git a/app/schedulers/complete_mentorship_cron_job.py b/app/schedulers/complete_mentorship_cron_job.py index 114e959c3..b01889d79 100644 --- a/app/schedulers/complete_mentorship_cron_job.py +++ b/app/schedulers/complete_mentorship_cron_job.py @@ -11,8 +11,8 @@ def complete_overdue_mentorship_relations_job(): from run import application with application.app_context(): - from app.utils.enum_utils import MentorshipRelationState from app.database.models.mentorship_relation import MentorshipRelationModel + from app.utils.enum_utils import MentorshipRelationState all_relations = filter( lambda relation: relation.state == MentorshipRelationState.ACCEPTED diff --git a/app/utils/decorator_utils.py b/app/utils/decorator_utils.py index 5d065396c..c0713bcf3 100644 --- a/app/utils/decorator_utils.py +++ b/app/utils/decorator_utils.py @@ -1,8 +1,9 @@ """ This module is used to define decorators for the app """ -from app import messages from http import HTTPStatus + +from app import messages from app.database.models.user import UserModel diff --git a/app/utils/validation_utils.py b/app/utils/validation_utils.py index 14721406a..2dbba9aef 100644 --- a/app/utils/validation_utils.py +++ b/app/utils/validation_utils.py @@ -2,7 +2,7 @@ against predetermined patterns as well as to ensure the string input is within the accepted length. For the "name" field to be valid, it may contain one or more character from: -- letter "a" to "z" and/or "A" to "Z", +- letter "a" to "z" and/or "A" to "Z", - any of the whitespace characters, and/or - special character "-". diff --git a/deploy.sh b/deploy.sh index f1bf18195..b8fcc3959 100644 --- a/deploy.sh +++ b/deploy.sh @@ -19,7 +19,7 @@ if [ "$TRAVIS_BRANCH" == "develop" ]; then elif [ "$TRAVIS_BRANCH" == "master" ]; then FLASK_ENVIRONMENT_CONFIG="prod" SERVER="Production" -else +else echo "Skip publishing, we don't publish for branches other than develop and master." exit 0 fi @@ -36,7 +36,7 @@ echo "aws_access_key_id = $AWS_ACCESS_ID" >> ~/.aws/config echo "aws_secret_access_key = $AWS_SECRET_KEY" >> ~/.aws/config # Add environment variables -eb setenv FLASK_ENVIRONMENT_CONFIG=$FLASK_ENVIRONMENT_CONFIG MAIL_DEFAULT_SENDER=$MAIL_DEFAULT_SENDER MAIL_SERVER=$MAIL_SERVER APP_MAIL_USERNAME=$APP_MAIL_USERNAME APP_MAIL_PASSWORD=$APP_MAIL_PASSWORD SECRET_KEY=$SECRET_KEY SECURITY_PASSWORD_SALT=$SECURITY_PASSWORD_SALT DB_TYPE=$DB_TYPE DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_ENDPOINT=$DB_ENDPOINT DB_NAME=$DB_NAME +eb setenv FLASK_ENVIRONMENT_CONFIG=$FLASK_ENVIRONMENT_CONFIG MAIL_DEFAULT_SENDER=$MAIL_DEFAULT_SENDER MAIL_SERVER=$MAIL_SERVER APP_MAIL_USERNAME=$APP_MAIL_USERNAME APP_MAIL_PASSWORD=$APP_MAIL_PASSWORD SECRET_KEY=$SECRET_KEY SECURITY_PASSWORD_SALT=$SECURITY_PASSWORD_SALT DB_TYPE=$DB_TYPE DB_USERNAME=$DB_USERNAME DB_PASSWORD=$DB_PASSWORD DB_ENDPOINT=$DB_ENDPOINT DB_NAME=$DB_NAME # Publishing echo "Publishing to '$SERVER' server" diff --git a/dev-requirements.txt b/dev-requirements.txt index bdad1c116..dd63f374e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,3 @@ -r requirements.txt awsebcli==3.19.0 -PyMySQL==0.10.1 \ No newline at end of file +PyMySQL==0.10.1 diff --git a/docs/Mentorship Backend.postman_collection.json b/docs/Mentorship Backend.postman_collection.json index 13cc148af..2928828cc 100644 --- a/docs/Mentorship Backend.postman_collection.json +++ b/docs/Mentorship Backend.postman_collection.json @@ -235,4 +235,4 @@ "response": [] } ] -} \ No newline at end of file +} diff --git a/docs/docs/Commit-Message-Style-Guide.md b/docs/docs/Commit-Message-Style-Guide.md index e66045604..04b89c5b7 100644 --- a/docs/docs/Commit-Message-Style-Guide.md +++ b/docs/docs/Commit-Message-Style-Guide.md @@ -44,10 +44,10 @@ or With body ``` -fix: fix crash caused by new libraries +fix: fix crash caused by new libraries -After merging PRs #126 and #130 crashes were occurring. -These crashes were because of deprecated functions. -Found a solution here (https://stackoverflow.com/questions/22718185) +After merging PRs #126 and #130 crashes were occurring. +These crashes were because of deprecated functions. +Found a solution here (https://stackoverflow.com/questions/22718185) This will resolve issue #140 -``` \ No newline at end of file +``` diff --git a/docs/docs/Database-Design.md b/docs/docs/Database-Design.md index 71d5b547a..da16b5208 100644 --- a/docs/docs/Database-Design.md +++ b/docs/docs/Database-Design.md @@ -14,4 +14,4 @@ Back in Google Summer of Code 2018, mentors and the student decided to implement Here's a discussion thread about this approach: - [Discussion starter message on Systers Open Source Slack](https://systers-opensource.slack.com/archives/C0S15BFNX/p1532623507000096/), here is the continuation [thread](https://systers-opensource.slack.com/archives/C0S15BFNX/p1532624183000470/). -- [Task Scalability issue Google Docs (not so updated)](https://docs.google.com/document/d/1Bm0SAPSKjxZNRkDsvklPdtbHxLXsHQpsPLz4m18nzC4/) (the above thread may have more useful info). \ No newline at end of file +- [Task Scalability issue Google Docs (not so updated)](https://docs.google.com/document/d/1Bm0SAPSKjxZNRkDsvklPdtbHxLXsHQpsPLz4m18nzC4/) (the above thread may have more useful info). diff --git a/docs/docs/Environment-Variables.md b/docs/docs/Environment-Variables.md index 2a1482c0f..09d2051bc 100644 --- a/docs/docs/Environment-Variables.md +++ b/docs/docs/Environment-Variables.md @@ -6,7 +6,7 @@ title: Export Environment Variables --- -To run the backend you need to export environment variables. +To run the backend you need to export environment variables. These are the needed environment variables: ``` @@ -50,13 +50,13 @@ Email verification is when a user registers into the application and to be able | APP_MAIL_USERNAME | Username of the email account used to send verification emails. This is in string format. | 'some_username' | | APP_MAIL_PASSWORD | Password of the email account used to send verification emails. This is in string format. | 'some_password' | -_Note:_ +_Note:_ - In the examples we use Gmail account example, but you are not restricted to use a Gmail account to send the verification email. If you use other email providers make sure to research about the correct SMTP server name. - The `'` character may be optional for environment variables without space on them. ## Exporting environment variables -Assume that KEY is the name of the variable and VALUE is the actual value of the environment variable. +Assume that KEY is the name of the variable and VALUE is the actual value of the environment variable. To export an environment variable you have to run: ``` export KEY=VALUE @@ -75,4 +75,4 @@ Another way to do this in flask applications is by having a file called `.env` w FLASK_ENVIRONMENT_CONFIG=dev SECRET_KEY='some_random_key' (...) -``` \ No newline at end of file +``` diff --git a/docs/docs/Fork,-Clone-&-Remote.md b/docs/docs/Fork,-Clone-&-Remote.md index d9bf503de..23a682b69 100644 --- a/docs/docs/Fork,-Clone-&-Remote.md +++ b/docs/docs/Fork,-Clone-&-Remote.md @@ -10,17 +10,17 @@ If you want to contribute to the project you will have to create your own copy o ![image showing fork symbol on GitHub](https://user-images.githubusercontent.com/17262180/44300717-53d11c80-a329-11e8-8782-5595a520446e.png) -## Clone +## Clone _**Note**: For this you need to install [git](https://git-scm.com/) on your machine. You can download the git tool from [here](https://git-scm.com/downloads)._ - - If you have forked the project, run the following command - + - If you have forked the project, run the following command - `git clone https://github.com/YOUR_GITHUB_USER_NAME/mentorship-backend` where `YOUR_GITHUB_USER_NAME` is your GitHub handle. - - If you haven't forked the project, run the following command - + - If you haven't forked the project, run the following command - `git clone https://github.com/anitab-org/mentorship-backend` @@ -28,7 +28,7 @@ where `YOUR_GITHUB_USER_NAME` is your GitHub handle. _**Note**: This is only needed if you want to contribute to the project._ -When a repository is cloned, it has a default remote named `origin` that points to your fork on GitHub, not the original repository it was forked from. To keep track of the original repository, you should add another remote named upstream. For this project it can be done by running the following command - +When a repository is cloned, it has a default remote named `origin` that points to your fork on GitHub, not the original repository it was forked from. To keep track of the original repository, you should add another remote named upstream. For this project it can be done by running the following command - `git remote add upstream https://github.com/anitab-org/mentorship-backend` @@ -39,4 +39,4 @@ origin https://github.com/YOUR_GITHUB_USER_NAME/mentorship-backend (fetch) origin https://github.com/YOUR_GITHUB_USER_NAME/mentorship-backend (push) upstream https://github.com/anitab-org/mentorship-backend.git (fetch) upstream https://github.com/anitab-org/mentorship-backend.git (push) -``` \ No newline at end of file +``` diff --git a/docs/docs/Future-ideas.md b/docs/docs/Future-ideas.md index b0d6e625b..89ed4e8c9 100644 --- a/docs/docs/Future-ideas.md +++ b/docs/docs/Future-ideas.md @@ -19,4 +19,3 @@ If you want to implement one of this ideas feel free to start a discussion about | Tutorial | A tutorial screen, explaining what a user can do in the app, in its first login in the app would be helpful | | Mentor and Mentee recommendation | Users can be recommended to each other according to their interests, skills, availability to mentor and be mentored | | Mentorship Agreements from One Mentor to Many Mentees | A mentor can mentor many mentee’s on one topic, at the same time… Group Mentoring (to be discussed: the initial idea is for the mentor to focus on one mentee only instead of sharing attention with many mentees) | - diff --git a/docs/docs/GSoC-2018-Isabel-Costa.md b/docs/docs/GSoC-2018-Isabel-Costa.md index e49136888..961701063 100644 --- a/docs/docs/GSoC-2018-Isabel-Costa.md +++ b/docs/docs/GSoC-2018-Isabel-Costa.md @@ -5,7 +5,7 @@ title: GSoC 2018 Isabel Costa ## Isabel Costa I proposed and worked on Mentorship System Backend and Android application. I was mentored by -[Dilushi](https://github.com/Dilu9218), [Murad](https://github.com/m-murad), [Roopal](https://github.com/roopalJazz) and [May](https://github.com/exactlymay) as an admin. +[Dilushi](https://github.com/Dilu9218), [Murad](https://github.com/m-murad), [Roopal](https://github.com/roopalJazz) and [May](https://github.com/exactlymay) as an admin. ## Work Hours @@ -51,12 +51,12 @@ You can find... **What issues or roadblocks have you encountered this week?** - Problems with PC. -- Thesis reunion and pending work. +- Thesis reunion and pending work. - Lack of experience with backend development with Flask. **Have they been resolved, and if so, how?** -- The PC is fixed. +- The PC is fixed. - I’m still a newbie at backend development with flask, but I’m picking up. **Do any of the issues or roadblocks still exist and what steps have been taken to resolve them?** @@ -179,7 +179,7 @@ Late on email verification and mentorship relation - Created issues reported by Murad (#33, #34, #35) - Solved above issues -- Created tests for app configurations (#37) +- Created tests for app configurations (#37) - Attended project weekly - Reviewed Mentorship Relation feature in project weekly meeting - Created issue for sending the expiry date on Login response #39 @@ -288,7 +288,7 @@ N/A **What do you plan to accomplish next week?** -1. Have completed accept/reject/cancel/complete +1. Have completed accept/reject/cancel/complete 2. Deploy Backend 3. Share the deployed backend update with the community and ask for feedback and testing 4. Refactor app to be able to test the API @@ -460,7 +460,7 @@ On time to do the Android app! - Created issue #94 and submitted PR #95 to solve user registration data validation - Submitted PR #89 imports database URI from environment variables (persistence to DB) - Submitted PR #90 that adds organization field to User (occupation was already there) -- Reviewed PR #105 regarding change password request data validation +- Reviewed PR #105 regarding change password request data validation **What issues or roadblocks have you encountered this week?** @@ -562,7 +562,7 @@ Late on the Android application 1. Had 1:1 with Murad (discussed best practices for Android) 2. Created .svg file of Current Relation icon 3. Added Travis CI support to Android repository -4. Submit PR #17 with my initial code (register, login, bottom nav) +4. Submit PR #17 with my initial code (register, login, bottom nav) 5. List Item UI of All Members list with ConstraintLayout (on my fork only) 6. My Profile Screen UI with ConstraintLayout (on my fork only) 7. Hosted AMA sessions diff --git a/docs/docs/Getting-Started.md b/docs/docs/Getting-Started.md index 32a1c1290..f5773acac 100644 --- a/docs/docs/Getting-Started.md +++ b/docs/docs/Getting-Started.md @@ -33,4 +33,4 @@ Before you start working check the [Contribution Guidelines](https://github.com/ 7. Once you finish working on your issue, submit a Pull Request (PR) [(following the template provided)](https://github.com/systers/mentorship-backend/blob/develop/.github/PULL_REQUEST_TEMPLATE.md); 8. If the reviewers request changes on your PR, make the changes (this can be a back and forth process where you make changes according to reviewers feedback); 9. Make sure when you finish your changes you squash your commits into a single commit; -10. Once the reviewers approve your PR, they can merge and your code will finally be part of the main repository. \ No newline at end of file +10. Once the reviewers approve your PR, they can merge and your code will finally be part of the main repository. diff --git a/docs/docs/Home.md b/docs/docs/Home.md index f84d8ac0c..4473b972c 100644 --- a/docs/docs/Home.md +++ b/docs/docs/Home.md @@ -32,4 +32,4 @@ See the full [Code of Conduct](http://systers.io/code-of-conduct) and the [Repor ## Contact You can reach us at [AnitaB.org Open Source Zulip](https://anitab-org.zulipchat.com/). -This project is discussed on the [#mentorship-system](https://anitab-org.zulipchat.com/#narrow/stream/222534-mentorship-system) stream. \ No newline at end of file +This project is discussed on the [#mentorship-system](https://anitab-org.zulipchat.com/#narrow/stream/222534-mentorship-system) stream. diff --git a/docs/docs/How-to-Contribute.md b/docs/docs/How-to-Contribute.md index 19c37a89d..4fd4d8dda 100644 --- a/docs/docs/How-to-Contribute.md +++ b/docs/docs/How-to-Contribute.md @@ -10,8 +10,8 @@ Issues labeled as `First Timers Only` are more oriented towards newcomers, with There are many ways you can contribute to this project. - **Test the backend for Quality Assurance** purposes and **report bugs** (if any); -- **Give feedback** on what is shared with the community (UI prototype, suggesting new features); -- **Participate in discussions** on Slack; +- **Give feedback** on what is shared with the community (UI prototype, suggesting new features); +- **Participate in discussions** on Slack; - **Solving the available issues**, implement features, fix bugs, develop tests, etc...; - **Helping others** understand the project **on Slack**; - Review pull requests (PRs), even if you're a newcomer. @@ -32,11 +32,11 @@ You can find more about [Tech Stack here](Tech-Stack). You can test the backend for bugs. We have a set of [Quality Assurance Test Cases](Quality-Assurance) to help you with test the backend to lookup these bugs. -**If you find any bug you can report** by creating an issue, using the **Bug report template**. Here's a nice [example of a Bug Report issue](https://github.com/anitab-org/mentorship-backend/issues/83). +**If you find any bug you can report** by creating an issue, using the **Bug report template**. Here's a nice [example of a Bug Report issue](https://github.com/anitab-org/mentorship-backend/issues/83). These types of reports are very important because we can detect bugs in the backend and then create issues that fix these bugs. Also if you're not comfortable with the code you can just report a bugs you find, without having to suggest a solution on it, and thats a valuable contribution to the project. **Tools** you can use to do this: -- Create disposable emails with https://temp-mail.org/ to create accounts and verify them, throught this temporary emails; +- Create disposable emails with https://temp-mail.org/ to create accounts and verify them, throught this temporary emails; - **Swagger UI** provided in root of the deployed server. You can check the deployed server link in the the README.md file of the project. You can learn more about [how to use Swagger here](Using-Backend-Swagger-UI). - [Postman](https://www.getpostman.com/) to make your HTTP requests to the backend without being limited by Swagger API. E.g.: With this you can see the results of not sending an autorization token, which with the Swagger UI you're not allowed to do it. @@ -70,4 +70,4 @@ In this backend we don't have a User interface but we have a mobile application, # One last thing... -If you have any doubts about the project or how to contribute do not hesitate to ask questions on GitHub or on [Zulip](https://anitab-org.zulipchat.com/). The community will do their best to help you out :) \ No newline at end of file +If you have any doubts about the project or how to contribute do not hesitate to ask questions on GitHub or on [Zulip](https://anitab-org.zulipchat.com/). The community will do their best to help you out :) diff --git a/docs/docs/Main-Base-Concepts.md b/docs/docs/Main-Base-Concepts.md index fd950771a..9f5cf0b8a 100644 --- a/docs/docs/Main-Base-Concepts.md +++ b/docs/docs/Main-Base-Concepts.md @@ -12,4 +12,4 @@ These are the main base concepts of the application: _**Note:** This next concept was a part of the initial proposal, not yet implemented._ -- **Meeting:** A meeting is an event agreed by mentor and mentee. Any of the users can create it, although they have to agree on it for the meeting to happen. This meeting as a date and time, and optionally a place. The meeting can have some notes attached. \ No newline at end of file +- **Meeting:** A meeting is an event agreed by mentor and mentee. Any of the users can create it, although they have to agree on it for the meeting to happen. This meeting as a date and time, and optionally a place. The meeting can have some notes attached. diff --git a/docs/docs/Maintainer-Guidelines.md b/docs/docs/Maintainer-Guidelines.md index d870ab377..9cf952a46 100644 --- a/docs/docs/Maintainer-Guidelines.md +++ b/docs/docs/Maintainer-Guidelines.md @@ -31,4 +31,4 @@ If the commit does not follow our [Commit Message Style Guide](Commit-Message-St ![Editing commit when merging](https://user-images.githubusercontent.com/11148726/76369362-33155100-632b-11ea-90d1-879dbecfb059.png) -Make sure to always leave the PR identifier, so that we can traceback a commit to a specific PR. \ No newline at end of file +Make sure to always leave the PR identifier, so that we can traceback a commit to a specific PR. diff --git a/docs/docs/Mentorship-Relation-Documentation.md b/docs/docs/Mentorship-Relation-Documentation.md index 55ed20bc0..53e2ffeec 100644 --- a/docs/docs/Mentorship-Relation-Documentation.md +++ b/docs/docs/Mentorship-Relation-Documentation.md @@ -2,7 +2,7 @@ id: Mentorship-Relation-Documentation title: Mentorship Relation Documentation --- -A **Mentorship Relation** is when two Users, a mentor, and a mentee are matched together to mentor and support each other. This is a 1 to 1 relation, involving just 2 users, during a certain period of time. +A **Mentorship Relation** is when two Users, a mentor, and a mentee are matched together to mentor and support each other. This is a 1 to 1 relation, involving just 2 users, during a certain period of time. A **Mentorship Relation request** is when a User sends a sort of contract in which the other User has to accept so that a mentorship relation can start. This contract contains notes/description, the definition of who will be the mentor and the mentee and the end date of the relation. Currently, this contract cannot be edited after sent by the User. @@ -38,4 +38,3 @@ The next table explains more of the image above. | COMPLETED | A cron job running every day 23h59 (automatically) | A cron job in the backend iterates over every mentorship relation, in the ACCEPTED state, and sets this states for relations that passed the end date | Sets only if the relation is in the ACCEPTED state | **Note:** Even though is not represented in the previous image, the User that sent the mentorship request can delete the request if its state wasn't changed by the receiving User. - diff --git a/docs/docs/Quality-Assurance.md b/docs/docs/Quality-Assurance.md index d9424b81e..66eb69236 100644 --- a/docs/docs/Quality-Assurance.md +++ b/docs/docs/Quality-Assurance.md @@ -177,4 +177,3 @@ Only admin users have access to this. | Revoke self the admin role when self is the only admin | Fail | | Revoke self the admin role when self is not the only admin | Success | | Revoking an admin user, when the current user is not an admin | Fail | - diff --git a/docs/docs/Register-a-new-user-using-Swagger.md b/docs/docs/Register-a-new-user-using-Swagger.md index 6cc529783..420af3bb1 100644 --- a/docs/docs/Register-a-new-user-using-Swagger.md +++ b/docs/docs/Register-a-new-user-using-Swagger.md @@ -32,4 +32,4 @@ For this, I tend to use https://temp-mail.org/ service. This will allow you to u 7. By clicking the above link, you'll be forwarded to this page which shold confirm you successfully confirmed your email. -![Email confirmation response](https://user-images.githubusercontent.com/11148726/50458775-a49ef480-095d-11e9-9e48-b10160f74b05.png) \ No newline at end of file +![Email confirmation response](https://user-images.githubusercontent.com/11148726/50458775-a49ef480-095d-11e9-9e48-b10160f74b05.png) diff --git a/docs/docs/Tech-Stack.md b/docs/docs/Tech-Stack.md index 150c920f7..3af84a4dd 100644 --- a/docs/docs/Tech-Stack.md +++ b/docs/docs/Tech-Stack.md @@ -10,4 +10,4 @@ title: Tech Stack - **Hosting Service:** Heroku - **Database:** Relational Database -Understand more about our technical decisions made along with this project development in [Technical Decisions page](Technical-Decisions). \ No newline at end of file +Understand more about our technical decisions made along with this project development in [Technical Decisions page](Technical-Decisions). diff --git a/docs/docs/Technical-Decisions.md b/docs/docs/Technical-Decisions.md index fdbcb2bbf..b6dbcddc5 100644 --- a/docs/docs/Technical-Decisions.md +++ b/docs/docs/Technical-Decisions.md @@ -21,7 +21,7 @@ N/A ## March 2020 - Why Development Backend is hosted on Heroku? -We were using AWS, but the Backend stopped working (500 error) after one specific deploy, which we could not investigate due to not having appropriate access for it (AnitaB.org IT team has the credentials). So [Isabel](https://github.com/isabelcosta) decided to deploy it on Heroku, so we could continue having a Swagger UI endpoint for the REST API that people could access it for testing purposes. So until we have proper access to AWS, we are using Heroku. +We were using AWS, but the Backend stopped working (500 error) after one specific deploy, which we could not investigate due to not having appropriate access for it (AnitaB.org IT team has the credentials). So [Isabel](https://github.com/isabelcosta) decided to deploy it on Heroku, so we could continue having a Swagger UI endpoint for the REST API that people could access it for testing purposes. So until we have proper access to AWS, we are using Heroku. ## August 2018 - Why use AWS? @@ -61,4 +61,4 @@ You can know more about how to use Swagger in [this page](Using-Backend-Swagger- You can learn more about how [User Authentication](User-Authentication) is done in this project. -Initially, we started using [Flask-JWT](https://pythonhosted.org/Flask-JWT/), but as the development progressed we started having challenges to solve that required a more flexible library. One of the issues that made us change to _Flask-jwt-extended_ was the need for extra verifications while login in a User into the system, specifically verifying if the user had the email verified. After looking into _flask-jwt_ source code and docs to see if this could be done easily the GSoC student concluded that it would require extra work by having to override some functions, as done before, and that this would overcomplicate code. Ultimately, it was agreed with the mentors to use _flask-jwt-extended_ that provided more flexibility to implement the Login API. The official documentation of _flask-jwt-extended_ shows an [example of the basic usage](http://flask-jwt-extended.readthedocs.io/en/latest/basic_usage.html) of the extension, where it shows the flexibility to verify extra fields and properties and provide custom error messages. \ No newline at end of file +Initially, we started using [Flask-JWT](https://pythonhosted.org/Flask-JWT/), but as the development progressed we started having challenges to solve that required a more flexible library. One of the issues that made us change to _Flask-jwt-extended_ was the need for extra verifications while login in a User into the system, specifically verifying if the user had the email verified. After looking into _flask-jwt_ source code and docs to see if this could be done easily the GSoC student concluded that it would require extra work by having to override some functions, as done before, and that this would overcomplicate code. Ultimately, it was agreed with the mentors to use _flask-jwt-extended_ that provided more flexibility to implement the Login API. The official documentation of _flask-jwt-extended_ shows an [example of the basic usage](http://flask-jwt-extended.readthedocs.io/en/latest/basic_usage.html) of the extension, where it shows the flexibility to verify extra fields and properties and provide custom error messages. diff --git a/docs/docs/Using-Backend-Swagger-UI.md b/docs/docs/Using-Backend-Swagger-UI.md index c478410e1..76d51310b 100644 --- a/docs/docs/Using-Backend-Swagger-UI.md +++ b/docs/docs/Using-Backend-Swagger-UI.md @@ -12,4 +12,4 @@ In Google Summer of Code 2018 final demo, the backend was demonstrated through S - [Log in using Swagger UI](Log-in-using-Swagger-UI); - [Register a new user using Swagger UI](Register-a-new-user-using-Swagger); -- [Live demonstration on Youtube](https://youtu.be/xRZrdR47R-w?t=672). \ No newline at end of file +- [Live demonstration on Youtube](https://youtu.be/xRZrdR47R-w?t=672). diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 0fa4c53b2..cdf144518 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -97,7 +97,7 @@ export DB_NAME= | Environment Variable | Description | Example | |----------------------|-----------------------------------------------------------------------------|-------------------| | DB_TYPE | Type of database you want to use | postgres, mysql | -| DB_USERNAME | Username of the user through which you will be doing operations in database | admin123 | +| DB_USERNAME | Username of the user through which you will be doing operations in database | admin123 | | DB_PASSWORD | Database password of the `DB_USERNAME` user | mypwd123 | | DB_ENDPOINT | Path to database or connection string connecting to database | /path/to/database.db, remote-database-url:5432 | | DB_NAME | Name of the database to which you want to connect | mentorship | diff --git a/docs/features.md b/docs/features.md index f7fedc7b9..f8b65a8f5 100644 --- a/docs/features.md +++ b/docs/features.md @@ -36,7 +36,7 @@ _**Note:** This next concept was a part of the initial proposal, not yet impleme ### Mentorship Relation -A **Mentorship Relation** is when two Users, a mentor, and a mentee are matched together to mentor and support each other. This is a 1 to 1 relation, involving just 2 users, during a certain period of time. +A **Mentorship Relation** is when two Users, a mentor, and a mentee are matched together to mentor and support each other. This is a 1 to 1 relation, involving just 2 users, during a certain period of time. A **Mentorship Relation request** is when a User sends a sort of contract in which the other User has to accept so that a mentorship relation can start. This contract contains notes/description, the definition of who will be the mentor and the mentee and the end date of the relation. Currently, this contract cannot be edited after sent by the User. diff --git a/docs/manual_tests/manual_tests_PUT_user.md b/docs/manual_tests/manual_tests_PUT_user.md index 09b6a5d38..0d8fe3d6c 100644 --- a/docs/manual_tests/manual_tests_PUT_user.md +++ b/docs/manual_tests/manual_tests_PUT_user.md @@ -1,28 +1,25 @@ -# Manual Testing for PUT/user +# Manual Testing for PUT/user Created the following users : 1. ***name:*** yash , ***username:*** cali123 and ***password:*** cali1234567@ -2. ***name:*** john , ***username:*** bo123 and ***password:*** semrush2189@ +2. ***name:*** john , ***username:*** bo123 and ***password:*** semrush2189@ + +* _TBD(Change existing username to a different username)_ -* _TBD(Change existing username to a different username)_ - Changed the username from cali123 to opt124 - + _Screenshot_: ![tbd](https://user-images.githubusercontent.com/31548778/92595965-b0ae1f80-f2c2-11ea-8a0d-7cc687f620fa.PNG) _Expected Result_: SUCCESS - + _Actual Result_: SUCCESS -* _Change username to a username already being used by another User_ - +* _Change username to a username already being used by another User_ + Tried changing the username cali123 to bo123. Since this username already exists for the name john, it failed to update username. - + _Screenshot_: ![Capture](https://user-images.githubusercontent.com/31548778/92596076-d9361980-f2c2-11ea-8922-d3b010b2ca80.PNG) - + _Expected Result_: FAIL - + _Actual Result_: FAIL - - - \ No newline at end of file diff --git a/docs/manual_tests/test_confirmation_token.md b/docs/manual_tests/test_confirmation_token.md index 40873cfd1..e4b7fea14 100644 --- a/docs/manual_tests/test_confirmation_token.md +++ b/docs/manual_tests/test_confirmation_token.md @@ -1,7 +1,7 @@ * Test 1 : Verification token entered is one sent on user's registered email within 24 hrs - _Screenshot/gif_: - + _Screenshot/gif_: + ![test_1](https://user-images.githubusercontent.com/56037184/94105745-91cd9280-fe57-11ea-90e7-6e514cb3ada2.png) @@ -12,8 +12,8 @@ * Test 2: Verification token of already confirmed users account entered - _Screenshot/gif_: - + _Screenshot/gif_: + ![test_2](https://user-images.githubusercontent.com/56037184/94105790-a90c8000-fe57-11ea-8044-aee26039567e.png) @@ -24,8 +24,8 @@ * Test 3: Verification token of un-confirmed users account entered after 24 hrs of email being sent - _Screenshot/gif_: - + _Screenshot/gif_: + ![test_3](https://user-images.githubusercontent.com/56037184/94105821-bf1a4080-fe57-11ea-9f9f-2d895a62fffb.png) @@ -38,8 +38,8 @@ * Test 4: Incorrect verification token entered in request body - _Screenshot/gif_: - + _Screenshot/gif_: + ![test_4](https://user-images.githubusercontent.com/56037184/94105890-e83ad100-fe57-11ea-92c9-95951ae57bb1.png) diff --git a/docs/manual_tests/test_resend_email.md b/docs/manual_tests/test_resend_email.md index 1e88c2af8..2a70df204 100644 --- a/docs/manual_tests/test_resend_email.md +++ b/docs/manual_tests/test_resend_email.md @@ -1,6 +1,6 @@ * Test 1 : Email is sent to registered user's email. - _Screenshot_: + _Screenshot_: ![test_1](https://user-images.githubusercontent.com/42766576/94338862-3f38d580-0013-11eb-8638-4ed46f4e9e13.png) @@ -12,7 +12,7 @@ * Test 2: Email is sent to the user who already confirmed their mail - _Screenshot_: + _Screenshot_: ![test_2](https://user-images.githubusercontent.com/42766576/94338870-57a8f000-0013-11eb-8e83-1f1740242067.png) @@ -24,7 +24,7 @@ * Test 3: Email is sent to an email that is not registered in the system - _Screenshot_: + _Screenshot_: ![test_3](https://user-images.githubusercontent.com/42766576/94338843-14e71800-0013-11eb-9993-560d36527534.png) diff --git a/docs/manual_tests/user_change_password.md b/docs/manual_tests/user_change_password.md index 6667dba8a..3e3efc52b 100644 --- a/docs/manual_tests/user_change_password.md +++ b/docs/manual_tests/user_change_password.md @@ -9,7 +9,7 @@ Change password from **test@123** to **Testing@1234** - _Screenshot_: + _Screenshot_: ![newPass](https://user-images.githubusercontent.com/64194946/92589746-a555f680-f2b8-11ea-8a90-8b551e03901b.png) ![newPassRes](https://user-images.githubusercontent.com/64194946/92589742-a424c980-f2b8-11ea-8172-4b436298f8f8.png) @@ -19,28 +19,28 @@ _Actual Result_: SUCCESS -* _Change password to a password equal to the current one_ +* _Change password to a password equal to the current one_ Change password from **Testing@1234** to **Testing@1234** - _Screenshot_: + _Screenshot_: ![samePass](https://user-images.githubusercontent.com/64194946/92589723-9ff8ac00-f2b8-11ea-81c9-f66342d91f91.png) ![samePassRes](https://user-images.githubusercontent.com/64194946/92589718-9d965200-f2b8-11ea-9950-d50930447d5a.png) - + _Expected Result_: FAIL _Actual Result_: FAIL -* _Change password to an empty password_ +* _Change password to an empty password_ Change password from **Testing@1234** to empty password. - _Screenshot_: + _Screenshot_: ![empty](https://user-images.githubusercontent.com/64194946/92595625-4b5a2e80-f2c2-11ea-8cbd-7696f38d4edc.png) - _Expected Result_: FAIL + _Expected Result_: FAIL _Actual Result_: FAIL @@ -49,9 +49,9 @@ Change password from **Testing@1234** to **Test@ 1234** - _Screenshot_: + _Screenshot_: ![space](https://user-images.githubusercontent.com/64194946/92595820-92482400-f2c2-11ea-96d0-6cac0b8a343d.png) - _Expected Result_: FAIL + _Expected Result_: FAIL - _Actual Result_: FAIL \ No newline at end of file + _Actual Result_: FAIL diff --git a/docs/manual_tests/user_refresh_token.md b/docs/manual_tests/user_refresh_token.md index de0ef05da..e35c95d7c 100644 --- a/docs/manual_tests/user_refresh_token.md +++ b/docs/manual_tests/user_refresh_token.md @@ -1,19 +1,19 @@ ## Manual testing for POST /user/refresh API #### Dummy data used: -* **username**: refresh_test, +* **username**: refresh_test, * **password**: refresh_test@1234 * _Refresh using the expired token_ Refresh token returned on login response: - - _Screenshot_: + + _Screenshot_: ![loginOnce](https://user-images.githubusercontent.com/50259869/94347905-e0e11680-0055-11eb-8569-0249b45e52e6.PNG) Entering the expired login response refresh token in the Authorization field: - - _Screenshot_: + + _Screenshot_: ![enterExpired](https://user-images.githubusercontent.com/56799401/102400371-d5273f80-4007-11eb-870e-b56b78a52eab.png) ![enterExpiredCurl](https://user-images.githubusercontent.com/50259869/94347907-e2124380-0055-11eb-982b-52e9f087540c.PNG) @@ -24,13 +24,13 @@ * _Refresh using new refresh token returned on login response_ Login again to get a new refresh token: - - _Screenshot_: + + _Screenshot_: ![loginAgain](https://user-images.githubusercontent.com/50259869/94347910-e2aada00-0055-11eb-982f-3919042cbac4.PNG) Entering the login response refresh token in the Authorization field: - - _Screenshot_: + + _Screenshot_: ![correctToken](https://user-images.githubusercontent.com/56799401/102400371-d5273f80-4007-11eb-870e-b56b78a52eab.png) ![correctTokenCurl](https://user-images.githubusercontent.com/50259869/94347912-e3437080-0055-11eb-9912-452d4a637942.PNG) @@ -72,4 +72,4 @@ _Expected Result_: FAIL - _Actual Result_: FAIL \ No newline at end of file + _Actual Result_: FAIL diff --git a/docs/quality-assurance-test-cases.md b/docs/quality-assurance-test-cases.md index 26f30d842..2e5e437f0 100644 --- a/docs/quality-assurance-test-cases.md +++ b/docs/quality-assurance-test-cases.md @@ -234,4 +234,4 @@ Only admin users have access to this. | Verification token entered is one sent on users registered email entered within 24 hrs | Success | | Verification token of already confirmed users account entered | Success | | Verification token of un-confirmed users account entered after 24 hrs of email being sent | Fail | -| Incorrect verification token entered in request body | Fail | +| Incorrect verification token entered in request body | Fail | diff --git a/docs/reporting_guidelines.md b/docs/reporting_guidelines.md index 9709bd4a6..cc3caf572 100644 --- a/docs/reporting_guidelines.md +++ b/docs/reporting_guidelines.md @@ -12,7 +12,7 @@ In your report please include: * Names (legal, nicknames, or pseudonyms) of any individuals involved. * If there were other witnesses besides you, please try to include them as well. * When and where the incident occurred. Please be as specific as possible. -* Your account of what occurred. +* Your account of what occurred. * If there is a publicly available record (e.g. a mailing list archive or a public IRC logger) please include a link. * Any extra context you believe existed for the incident. * If you believe this incident is ongoing. diff --git a/docs/src/pages/styles.module.css b/docs/src/pages/styles.module.css index 34b43ce6d..0f8f0d816 100644 --- a/docs/src/pages/styles.module.css +++ b/docs/src/pages/styles.module.css @@ -11,13 +11,13 @@ position: relative; overflow: hidden; } - + @media screen and (max-width: 966px) { .heroBanner { padding: 2rem; } } - + .buttons { display: flex; align-items: center; diff --git a/docs/test-pr-guide.md b/docs/test-pr-guide.md index ac1c0fbbf..613c5b113 100644 --- a/docs/test-pr-guide.md +++ b/docs/test-pr-guide.md @@ -3,7 +3,7 @@ 1. Follow instructions in [README](https://github.com/anitab-org/mentorship-backend/blob/develop/README.md) to setup the system running locally. -2. Check on Zulip chat if any of the PR's +2. Check on Zulip chat if any of the PR's [here](https://github.com/anitab-org/mentorship-backend/labels/Needs%20Testing) are high-priority if the priority is not set already. 3. If the PRs are not prioritized then pick any 1 PR from the list from the link in step 2 to test locally. @@ -37,23 +37,23 @@ The changes made in this PR were tested locally. Following are the results: 2. All possible responses (positive and negative tests) were tested as below: - * _Test1 Description_ - _Screenshot/gif_: - _Expected Result_: + * _Test1 Description_ + _Screenshot/gif_: + _Expected Result_: _Actual Result_: - * _Test2 Description_ - _Screenshot/gif_: - _Expected Result_: - _Actual Result_: - ... - + * _Test2 Description_ + _Screenshot/gif_: + _Expected Result_: + _Actual Result_: + ... + 3. Additional testcases covered: - * _Test1 Description_ - _Screenshot/gif_: - _Expected Result_: + * _Test1 Description_ + _Screenshot/gif_: + _Expected Result_: _Actual Result_: - + 4. Additional Comments: 5. Status of PR Changed to: Needs Review or Ready to Merge. @@ -63,10 +63,10 @@ The changes made in this PR were tested locally. Following are the results:

Registering users

-Register 3 users. Follow instructions in +Register 3 users. Follow instructions in [this video](https://www.youtube.com/watch?v=xRZrdR47R-w&feature=youtu.be&t=672) -The users used here are +The users used here are * _testusera_ * _testuserb_ @@ -76,7 +76,7 @@ The users used here are

Login as the users and capture the access tokens

-Steps to login and capture the token are shown in +Steps to login and capture the token are shown in [this video](https://www.youtube.com/watch?v=xRZrdR47R-w&feature=youtu.be&t=672) ![Login user screenshot](https://user-images.githubusercontent.com/26095715/79673507-4a582180-81a8-11ea-96ff-2268733e9673.png) diff --git a/docs/troubleshoots.md b/docs/troubleshoots.md index 0555f8e7c..c74ebf574 100644 --- a/docs/troubleshoots.md +++ b/docs/troubleshoots.md @@ -1,4 +1,4 @@ -# Troubleshoots +# Troubleshoots ## Setting up Gmail to be used as default mail server in .env @@ -13,7 +13,7 @@ Here are the steps: You will see this section: ![signing_in_settings_gmail_original](https://user-images.githubusercontent.com/29667122/80807468-a1c2ac80-8c00-11ea-9053-7e6759f4c7e6.png) -2. In the section *Signing in to Google* select **2-step verification** and follow the prompts to turn it ON. +2. In the section *Signing in to Google* select **2-step verification** and follow the prompts to turn it ON. 3. Once step 2 completed, go back to Security page and from the same section (*Signing in to Google*) select **App password**. ![signing_in_settings_gmail_2steps_on](https://user-images.githubusercontent.com/29667122/80807613-07af3400-8c01-11ea-881c-fb2944e080d4.png) diff --git a/migrations/README b/migrations/README index 98e4f9c44..2500aa1bc 100644 --- a/migrations/README +++ b/migrations/README @@ -1 +1 @@ -Generic single-database configuration. \ No newline at end of file +Generic single-database configuration. diff --git a/migrations/env.py b/migrations/env.py index d766af808..f5a37d3ee 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -3,11 +3,15 @@ import logging from logging.config import fileConfig -from sqlalchemy import engine_from_config -from sqlalchemy import pool - from alembic import context +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +from flask import current_app +from sqlalchemy import engine_from_config, pool + # this is the Alembic Config object, which provides # access to the values within the .ini file in use. config = context.config @@ -17,11 +21,6 @@ fileConfig(config.config_file_name) logger = logging.getLogger("alembic.env") -# add your model's MetaData object here -# for 'autogenerate' support -# from myapp import mymodel -# target_metadata = mymodel.Base.metadata -from flask import current_app config.set_main_option( "sqlalchemy.url", diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..34f2b0db2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.black] +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +''' diff --git a/requirements.txt b/requirements.txt index 912f584de..949eed208 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ gunicorn==20.0.4 psycopg2-binary==2.8.6 python-dotenv==0.17.1 six==1.11.0 +pre-commit diff --git a/run.py b/run.py index 6f7ab83fe..5f8eab7a1 100644 --- a/run.py +++ b/run.py @@ -1,7 +1,8 @@ from flask import Flask -from config import get_env_config from flask_migrate import Migrate +from config import get_env_config + def create_app(config_filename: str) -> Flask: app = Flask(__name__) @@ -14,7 +15,7 @@ def create_app(config_filename: str) -> Flask: db.init_app(app) - migrate = Migrate(app, db) + migrate = Migrate(app, db) # noqa: F841 from app.api.jwt_extension import jwt diff --git a/tests/admin/test_api_list_admin_users.py b/tests/admin/test_api_list_admin_users.py index 0ffcffdfb..4b132ce0e 100644 --- a/tests/admin/test_api_list_admin_users.py +++ b/tests/admin/test_api_list_admin_users.py @@ -1,20 +1,16 @@ import unittest -from datetime import datetime, timedelta +from http import HTTPStatus from flask import json from flask_restx import marshal from app import messages from app.api.models.admin import public_admin_user_api_model -from app.database.models.mentorship_relation import MentorshipRelationModel -from app.database.models.tasks_list import TasksListModel from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db -from app.utils.enum_utils import MentorshipRelationState from tests.base_test_case import BaseTestCase +from tests.test_data import test_admin_user_2, test_admin_user_3, user1 from tests.test_utils import get_test_request_header -from tests.test_data import user1, test_admin_user, test_admin_user_2, test_admin_user_3 -from http import HTTPStatus class TestListAdminUsersApi(BaseTestCase): diff --git a/tests/admin/test_api_remove_admin_user.py b/tests/admin/test_api_remove_admin_user.py index ae83d3dcf..bfe7092fc 100644 --- a/tests/admin/test_api_remove_admin_user.py +++ b/tests/admin/test_api_remove_admin_user.py @@ -1,20 +1,14 @@ import unittest -from datetime import datetime, timedelta +from http import HTTPStatus from flask import json -from flask_restx import marshal from app import messages -from app.api.models.admin import public_admin_user_api_model -from app.database.models.mentorship_relation import MentorshipRelationModel -from app.database.models.tasks_list import TasksListModel from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db -from app.utils.enum_utils import MentorshipRelationState from tests.base_test_case import BaseTestCase -from tests.test_utils import get_test_request_header from tests.test_data import test_admin_user_2, test_admin_user_3 -from http import HTTPStatus +from tests.test_utils import get_test_request_header class TestRemoveAdminUsersApi(BaseTestCase): diff --git a/tests/admin/test_dao.py b/tests/admin/test_dao.py index 39a568d6b..69d8e6637 100644 --- a/tests/admin/test_dao.py +++ b/tests/admin/test_dao.py @@ -1,13 +1,12 @@ import unittest - -from tests.base_test_case import BaseTestCase -from tests.test_data import user1 +from http import HTTPStatus from app import messages -from app.database.models.user import UserModel from app.api.dao.admin import AdminDAO +from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db -from http import HTTPStatus +from tests.base_test_case import BaseTestCase +from tests.test_data import user1 class TestAdminDao(BaseTestCase): @@ -119,7 +118,7 @@ def test_dao_assign_admin_role_to_admin_user(self): ) """ - Checks if a user tries to self-assign admin role. + Checks if a user tries to self-assign admin role. """ def test_dao_assign_admin_role_to_myself(self): @@ -152,7 +151,7 @@ def test_dao_assign_admin_role_to_myself(self): ) """ - Checks whether a user is trying to revoke other user's admin priviledges. + Checks whether a user is trying to revoke other user's admin priviledges. """ def test_dao_revoke_admin_role_to_valid_user(self): @@ -181,7 +180,7 @@ def test_dao_revoke_admin_role_to_valid_user(self): self.assertFalse(user.is_admin) """ - Checks whether a user is trying to revoke other user's admin privileges. + Checks whether a user is trying to revoke other user's admin privileges. """ def test_dao_revoke_admin_role_by_non_admin_user(self): diff --git a/tests/base_test_case.py b/tests/base_test_case.py index b7ea2f9fb..70bb21c3a 100644 --- a/tests/base_test_case.py +++ b/tests/base_test_case.py @@ -1,9 +1,8 @@ from flask_testing import TestCase from app.database.models.user import UserModel -from run import application from app.database.sqlalchemy_extension import db - +from run import application from tests.test_data import test_admin_user diff --git a/tests/cron_job_functions/test_delete_unverified_users_cron.py b/tests/cron_job_functions/test_delete_unverified_users_cron.py index fa141cac8..c3ae48f5a 100644 --- a/tests/cron_job_functions/test_delete_unverified_users_cron.py +++ b/tests/cron_job_functions/test_delete_unverified_users_cron.py @@ -1,5 +1,4 @@ import time -from datetime import datetime from unittest.mock import patch import config diff --git a/tests/cron_job_functions/test_mentorship_completion_cron.py b/tests/cron_job_functions/test_mentorship_completion_cron.py index f5366a3e7..ac8cabfb5 100644 --- a/tests/cron_job_functions/test_mentorship_completion_cron.py +++ b/tests/cron_job_functions/test_mentorship_completion_cron.py @@ -2,14 +2,14 @@ from datetime import datetime, timedelta from unittest.mock import patch +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel +from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel from app.schedulers.complete_mentorship_cron_job import ( complete_overdue_mentorship_relations_job, ) from app.utils.enum_utils import MentorshipRelationState -from app.database.models.user import UserModel from tests.base_test_case import BaseTestCase from tests.test_data import user1, user2 diff --git a/tests/mentorship_relation/relation_base_setup.py b/tests/mentorship_relation/relation_base_setup.py index 3b39b9846..da53ab76b 100644 --- a/tests/mentorship_relation/relation_base_setup.py +++ b/tests/mentorship_relation/relation_base_setup.py @@ -1,7 +1,7 @@ from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db from tests.base_test_case import BaseTestCase -from tests.test_data import * +from tests.test_data import user1, user2, user3 class MentorshipRelationBaseTestCase(BaseTestCase): diff --git a/tests/mentorship_relation/test_api_accept_request.py b/tests/mentorship_relation/test_api_accept_request.py index c1351bce5..3c7edf310 100644 --- a/tests/mentorship_relation/test_api_accept_request.py +++ b/tests/mentorship_relation/test_api_accept_request.py @@ -1,13 +1,13 @@ import json import unittest -from unittest.mock import patch from datetime import datetime, timedelta from http import HTTPStatus +from unittest.mock import patch from app import messages +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase from tests.test_utils import get_test_request_header diff --git a/tests/mentorship_relation/test_api_cancel_relation.py b/tests/mentorship_relation/test_api_cancel_relation.py index 3574f1f95..588bf12b3 100644 --- a/tests/mentorship_relation/test_api_cancel_relation.py +++ b/tests/mentorship_relation/test_api_cancel_relation.py @@ -4,13 +4,12 @@ from http import HTTPStatus from app import messages +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase from tests.test_utils import get_test_request_header -from datetime import timedelta class TestCancelMentorshipRelationApi(MentorshipRelationBaseTestCase): diff --git a/tests/mentorship_relation/test_api_delete_request.py b/tests/mentorship_relation/test_api_delete_request.py index ac5cbe800..406d2a422 100644 --- a/tests/mentorship_relation/test_api_delete_request.py +++ b/tests/mentorship_relation/test_api_delete_request.py @@ -4,9 +4,9 @@ from http import HTTPStatus from app import messages +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase from tests.test_utils import get_test_request_header diff --git a/tests/mentorship_relation/test_api_list_relations.py b/tests/mentorship_relation/test_api_list_relations.py index 9305439f0..63d818eb6 100644 --- a/tests/mentorship_relation/test_api_list_relations.py +++ b/tests/mentorship_relation/test_api_list_relations.py @@ -6,9 +6,9 @@ from flask_restx import marshal from app.api.models.mentorship_relation import mentorship_request_response_body +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase from tests.test_utils import get_test_request_header diff --git a/tests/mentorship_relation/test_api_reject_request.py b/tests/mentorship_relation/test_api_reject_request.py index 89d62ce14..0c324306e 100644 --- a/tests/mentorship_relation/test_api_reject_request.py +++ b/tests/mentorship_relation/test_api_reject_request.py @@ -4,9 +4,9 @@ from http import HTTPStatus from app import messages +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase from tests.test_utils import get_test_request_header diff --git a/tests/mentorship_relation/test_api_send_request.py b/tests/mentorship_relation/test_api_send_request.py index cda0268ac..53c19bae7 100644 --- a/tests/mentorship_relation/test_api_send_request.py +++ b/tests/mentorship_relation/test_api_send_request.py @@ -4,10 +4,6 @@ from http import HTTPStatus from app import messages -from app.database.models.tasks_list import TasksListModel -from app.database.sqlalchemy_extension import db -from app.database.models.mentorship_relation import MentorshipRelationModel -from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase from tests.test_utils import get_test_request_header diff --git a/tests/mentorship_relation/test_dao_accept_request.py b/tests/mentorship_relation/test_dao_accept_request.py index 6b434b3e8..3077f6a8a 100644 --- a/tests/mentorship_relation/test_dao_accept_request.py +++ b/tests/mentorship_relation/test_dao_accept_request.py @@ -5,10 +5,9 @@ from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel +from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase -from app.database.sqlalchemy_extension import db - # TODO test when a user is in a current relation and tries to accept another relation # TODO test when a user tries to accept a relation where this user is not involved diff --git a/tests/mentorship_relation/test_dao_cancel_relation.py b/tests/mentorship_relation/test_dao_cancel_relation.py index d10c54bef..084e92076 100644 --- a/tests/mentorship_relation/test_dao_cancel_relation.py +++ b/tests/mentorship_relation/test_dao_cancel_relation.py @@ -3,13 +3,12 @@ from app import messages from app.api.dao.mentorship_relation import MentorshipRelationDAO -from app.database.models.tasks_list import TasksListModel -from app.utils.enum_utils import MentorshipRelationState from app.database.models.mentorship_relation import MentorshipRelationModel +from app.database.models.tasks_list import TasksListModel from app.database.sqlalchemy_extension import db +from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase - # TODO test when a user tries to cancel a relation where this user is not involved diff --git a/tests/mentorship_relation/test_dao_creation.py b/tests/mentorship_relation/test_dao_creation.py index bd665edc8..a14e069a9 100644 --- a/tests/mentorship_relation/test_dao_creation.py +++ b/tests/mentorship_relation/test_dao_creation.py @@ -6,9 +6,9 @@ from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel +from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase -from app.database.sqlalchemy_extension import db class TestMentorshipRelationCreationDAO(MentorshipRelationBaseTestCase): diff --git a/tests/mentorship_relation/test_dao_delete_request.py b/tests/mentorship_relation/test_dao_delete_request.py index c7321a695..a8ddcd7f9 100644 --- a/tests/mentorship_relation/test_dao_delete_request.py +++ b/tests/mentorship_relation/test_dao_delete_request.py @@ -3,11 +3,11 @@ from app import messages from app.api.dao.mentorship_relation import MentorshipRelationDAO -from app.database.models.tasks_list import TasksListModel -from app.utils.enum_utils import MentorshipRelationState from app.database.models.mentorship_relation import MentorshipRelationModel +from app.database.models.tasks_list import TasksListModel from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db +from app.utils.enum_utils import MentorshipRelationState from tests.base_test_case import BaseTestCase from tests.test_data import user1, user2 diff --git a/tests/mentorship_relation/test_dao_listing.py b/tests/mentorship_relation/test_dao_listing.py index 32046d696..190f968b7 100644 --- a/tests/mentorship_relation/test_dao_listing.py +++ b/tests/mentorship_relation/test_dao_listing.py @@ -5,10 +5,9 @@ from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel +from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase -from app.database.sqlalchemy_extension import db - # TODO test combination of parameters while listing relations diff --git a/tests/mentorship_relation/test_dao_reject_mentorship_request.py b/tests/mentorship_relation/test_dao_reject_mentorship_request.py index 5a9480098..3e3776830 100644 --- a/tests/mentorship_relation/test_dao_reject_mentorship_request.py +++ b/tests/mentorship_relation/test_dao_reject_mentorship_request.py @@ -5,10 +5,9 @@ from app.api.dao.mentorship_relation import MentorshipRelationDAO from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel +from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.mentorship_relation.relation_base_setup import MentorshipRelationBaseTestCase -from app.database.sqlalchemy_extension import db - # TODO test when a user tries to reject a relation where this user is not involved diff --git a/tests/mentorship_relation/test_database_model.py b/tests/mentorship_relation/test_database_model.py index 654d874ed..886823f40 100644 --- a/tests/mentorship_relation/test_database_model.py +++ b/tests/mentorship_relation/test_database_model.py @@ -1,16 +1,14 @@ import unittest from datetime import datetime +from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel -from app.utils.enum_utils import MentorshipRelationState -from tests.base_test_case import BaseTestCase from app.database.models.user import UserModel -from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.sqlalchemy_extension import db - +from app.utils.enum_utils import MentorshipRelationState +from tests.base_test_case import BaseTestCase from tests.test_data import user1, user2 - # Testing Mentorship Relation database model # # Tests: diff --git a/tests/task_comments/test_api_create_task_comment.py b/tests/task_comments/test_api_create_task_comment.py index b12165807..23388d7e9 100644 --- a/tests/task_comments/test_api_create_task_comment.py +++ b/tests/task_comments/test_api_create_task_comment.py @@ -1,5 +1,6 @@ import json import unittest +from http import HTTPStatus from app import messages from app.api.dao.task_comment import TaskCommentDAO @@ -7,7 +8,6 @@ from app.utils.validation_utils import get_length_validation_error_message from tests.tasks.tasks_base_setup import TasksBaseTestCase from tests.test_utils import get_test_request_header -from http import HTTPStatus class TestCreateTaskCommentApi(TasksBaseTestCase): diff --git a/tests/task_comments/test_api_delete_task_comment.py b/tests/task_comments/test_api_delete_task_comment.py index 217bcb579..a36cb640e 100644 --- a/tests/task_comments/test_api_delete_task_comment.py +++ b/tests/task_comments/test_api_delete_task_comment.py @@ -1,12 +1,12 @@ import json import unittest +from http import HTTPStatus from app import messages from app.api.dao.task_comment import TaskCommentDAO from app.database.sqlalchemy_extension import db from tests.tasks.tasks_base_setup import TasksBaseTestCase from tests.test_utils import get_test_request_header -from http import HTTPStatus class TestDeleteTaskCommentApi(TasksBaseTestCase): diff --git a/tests/task_comments/test_api_get_task_comments.py b/tests/task_comments/test_api_get_task_comments.py index 55e3ec217..08fe3bf5e 100644 --- a/tests/task_comments/test_api_get_task_comments.py +++ b/tests/task_comments/test_api_get_task_comments.py @@ -1,5 +1,6 @@ import json import unittest +from http import HTTPStatus from flask_restx import marshal @@ -8,7 +9,6 @@ from app.api.models.mentorship_relation import task_comments_model from tests.tasks.tasks_base_setup import TasksBaseTestCase from tests.test_utils import get_test_request_header -from http import HTTPStatus class TestGetTaskCommentsApi(TasksBaseTestCase): diff --git a/tests/task_comments/test_api_modify_task_comment.py b/tests/task_comments/test_api_modify_task_comment.py index 3a5841af4..7376deb98 100644 --- a/tests/task_comments/test_api_modify_task_comment.py +++ b/tests/task_comments/test_api_modify_task_comment.py @@ -1,5 +1,6 @@ import json import unittest +from http import HTTPStatus from app import messages from app.api.dao.task_comment import TaskCommentDAO @@ -8,7 +9,6 @@ from app.utils.validation_utils import get_length_validation_error_message from tests.tasks.tasks_base_setup import TasksBaseTestCase from tests.test_utils import get_test_request_header -from http import HTTPStatus class TestModifyTaskCommentApi(TasksBaseTestCase): diff --git a/tests/task_comments/test_dao.py b/tests/task_comments/test_dao.py index f465a9f98..5ed211516 100644 --- a/tests/task_comments/test_dao.py +++ b/tests/task_comments/test_dao.py @@ -1,9 +1,9 @@ import unittest +from http import HTTPStatus from app import messages from app.api.dao.task_comment import TaskCommentDAO from tests.tasks.tasks_base_setup import TasksBaseTestCase -from http import HTTPStatus class TestTaskCommentDao(TasksBaseTestCase): diff --git a/tests/tasks/tasks_base_setup.py b/tests/tasks/tasks_base_setup.py index 543086307..3d1f0faa2 100644 --- a/tests/tasks/tasks_base_setup.py +++ b/tests/tasks/tasks_base_setup.py @@ -1,4 +1,4 @@ -from datetime import timedelta, datetime +from datetime import datetime, timedelta from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel diff --git a/tests/tasks/test_api_complete_task.py b/tests/tasks/test_api_complete_task.py index 041068f38..4eb6ebf8c 100644 --- a/tests/tasks/test_api_complete_task.py +++ b/tests/tasks/test_api_complete_task.py @@ -1,7 +1,8 @@ import unittest -from flask import json from http import HTTPStatus +from flask import json + from app import messages from app.database.models.mentorship_relation import MentorshipRelationModel from tests.tasks.tasks_base_setup import TasksBaseTestCase diff --git a/tests/tasks/test_api_create_task.py b/tests/tasks/test_api_create_task.py index 75fe3928e..1f92c0f3f 100644 --- a/tests/tasks/test_api_create_task.py +++ b/tests/tasks/test_api_create_task.py @@ -1,11 +1,12 @@ import unittest -from flask import json +from datetime import timedelta from http import HTTPStatus +from flask import json + from app import messages from tests.tasks.tasks_base_setup import TasksBaseTestCase from tests.test_utils import get_test_request_header -from datetime import timedelta class TestCreateTaskApi(TasksBaseTestCase): diff --git a/tests/tasks/test_api_delete_task.py b/tests/tasks/test_api_delete_task.py index d97bcdcf2..18661d8bb 100644 --- a/tests/tasks/test_api_delete_task.py +++ b/tests/tasks/test_api_delete_task.py @@ -1,7 +1,8 @@ import unittest -from flask import json from http import HTTPStatus +from flask import json + from app import messages from tests.tasks.tasks_base_setup import TasksBaseTestCase from tests.test_utils import get_test_request_header diff --git a/tests/tasks/test_api_list_tasks.py b/tests/tasks/test_api_list_tasks.py index eeceef327..c057ae055 100644 --- a/tests/tasks/test_api_list_tasks.py +++ b/tests/tasks/test_api_list_tasks.py @@ -1,7 +1,8 @@ import unittest +from http import HTTPStatus + from flask import json from flask_restx import marshal -from http import HTTPStatus from app import messages from app.api.models.mentorship_relation import list_tasks_response_body diff --git a/tests/tasks/test_dao_complete_task.py b/tests/tasks/test_dao_complete_task.py index 02416ddf1..2029ffe88 100644 --- a/tests/tasks/test_dao_complete_task.py +++ b/tests/tasks/test_dao_complete_task.py @@ -3,7 +3,6 @@ from app import messages from app.api.dao.task import TaskDAO -from http import HTTPStatus from tests.tasks.tasks_base_setup import TasksBaseTestCase diff --git a/tests/tasks/test_dao_delete_task.py b/tests/tasks/test_dao_delete_task.py index d148bbc87..45783bb08 100644 --- a/tests/tasks/test_dao_delete_task.py +++ b/tests/tasks/test_dao_delete_task.py @@ -3,7 +3,6 @@ from app import messages from app.api.dao.task import TaskDAO -from http import HTTPStatus from tests.tasks.tasks_base_setup import TasksBaseTestCase diff --git a/tests/test_app_config.py b/tests/test_app_config.py index 6f33475d0..c79ad63fe 100644 --- a/tests/test_app_config.py +++ b/tests/test_app_config.py @@ -1,5 +1,5 @@ -import unittest import os +import unittest from datetime import timedelta from flask import current_app diff --git a/tests/test_flask_app.py b/tests/test_flask_app.py index 75fcc14f7..70d8b5639 100644 --- a/tests/test_flask_app.py +++ b/tests/test_flask_app.py @@ -1,6 +1,7 @@ -from tests.base_test_case import BaseTestCase import unittest +from tests.base_test_case import BaseTestCase + class TestFlaskApp(BaseTestCase): def test_index(self): diff --git a/tests/user_journey/test_happy_path_1.py b/tests/user_journey/test_happy_path_1.py index 82ceafc91..dad631545 100644 --- a/tests/user_journey/test_happy_path_1.py +++ b/tests/user_journey/test_happy_path_1.py @@ -3,20 +3,13 @@ from http import HTTPStatus from flask import json -from flask_restx import marshal -from app import messages -from app.api.models.user import public_user_api_model -from app.database.models.mentorship_relation import MentorshipRelationModel -from app.utils.enum_utils import MentorshipRelationState -from app.database.models.tasks_list import TasksListModel from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.base_test_case import BaseTestCase +from tests.test_data import user1, user2 from tests.test_utils import get_test_request_header -from tests.test_data import user1, user2, user3 -from app.api.models.mentorship_relation import mentorship_request_response_body class TestHappyPath1(BaseTestCase): @@ -110,10 +103,10 @@ def test_happy_path_1(self): self.assertEqual(HTTPStatus.OK, accept_response.status_code) mentee_current_relation = self.client.get( - f"/mentorship_relations/current", headers=mentee_auth_header + "/mentorship_relations/current", headers=mentee_auth_header ) mentor_current_relation = self.client.get( - f"/mentorship_relations/current", headers=mentor_auth_header + "/mentorship_relations/current", headers=mentor_auth_header ) self.assertEqual(HTTPStatus.OK, mentee_current_relation.status_code) diff --git a/tests/users/test_api_authentication.py b/tests/users/test_api_authentication.py index 889aded28..b158292c1 100644 --- a/tests/users/test_api_authentication.py +++ b/tests/users/test_api_authentication.py @@ -1,13 +1,14 @@ import unittest from datetime import timedelta from http import HTTPStatus + from flask import json from flask_restx import marshal from app import messages from app.api.models.user import full_user_api_model -from app.database.sqlalchemy_extension import db from app.database.models.user import UserModel +from app.database.sqlalchemy_extension import db from tests.base_test_case import BaseTestCase from tests.test_data import user1 from tests.test_utils import get_test_request_header diff --git a/tests/users/test_api_change_password.py b/tests/users/test_api_change_password.py index 626de8093..db47efa69 100644 --- a/tests/users/test_api_change_password.py +++ b/tests/users/test_api_change_password.py @@ -2,22 +2,21 @@ import json import unittest from http import HTTPStatus -from app.api.validations.user import PASSWORD_MIN_LENGTH, PASSWORD_MAX_LENGTH + +from app.api.validations.user import PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db from app.messages import ( - PASSWORD_SUCCESSFULLY_UPDATED, - USER_INPUTS_SPACE_IN_PASSWORD, AUTHORISATION_TOKEN_IS_MISSING, + PASSWORD_SUCCESSFULLY_UPDATED, TOKEN_HAS_EXPIRED, + USER_INPUTS_SPACE_IN_PASSWORD, ) from app.utils.validation_utils import get_length_validation_error_message from tests.base_test_case import BaseTestCase - from tests.test_data import user1 from tests.test_utils import get_test_request_header - # Testing /PUT/ Change User's Password diff --git a/tests/users/test_api_get_other_user.py b/tests/users/test_api_get_other_user.py index 7533cb1bf..7757ef386 100644 --- a/tests/users/test_api_get_other_user.py +++ b/tests/users/test_api_get_other_user.py @@ -1,8 +1,8 @@ import unittest +from http import HTTPStatus from flask import json from flask_restx import marshal -from http import HTTPStatus from app import messages from app.api.models.user import public_user_api_model diff --git a/tests/users/test_api_home_statistics.py b/tests/users/test_api_home_statistics.py index dbae59c89..a15c03996 100644 --- a/tests/users/test_api_home_statistics.py +++ b/tests/users/test_api_home_statistics.py @@ -1,6 +1,8 @@ from datetime import datetime, timedelta -from flask import json from http import HTTPStatus + +from flask import json + from app import messages from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel diff --git a/tests/users/test_api_list_users.py b/tests/users/test_api_list_users.py index 7c49d08c7..48704f73d 100644 --- a/tests/users/test_api_list_users.py +++ b/tests/users/test_api_list_users.py @@ -1,6 +1,7 @@ import unittest from datetime import datetime, timedelta from http import HTTPStatus + from flask import json from flask_restx import marshal @@ -12,8 +13,8 @@ from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.base_test_case import BaseTestCase -from tests.test_utils import get_test_request_header from tests.test_data import user1, user2, user3 +from tests.test_utils import get_test_request_header class TestListUsersApi(BaseTestCase): @@ -128,7 +129,7 @@ def test_list_users_api_with_search_with_special_characters_resource_auth(self): auth_header = get_test_request_header(self.admin_user.id) expected_response = [marshal(self.second_user, public_user_api_model)] actual_response = self.client.get( - f"/users?search=s_t-r%24a%2Fn'ge", + "/users?search=s_t-r%24a%2Fn'ge", follow_redirects=True, headers=auth_header, ) diff --git a/tests/users/test_api_login.py b/tests/users/test_api_login.py index 53be679b0..876ff682d 100644 --- a/tests/users/test_api_login.py +++ b/tests/users/test_api_login.py @@ -1,14 +1,13 @@ import unittest +from http import HTTPStatus from flask import json from app import messages +from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db from tests.base_test_case import BaseTestCase -from app.database.models.user import UserModel -from http import HTTPStatus - # Testing User API resources # # TODO tests: diff --git a/tests/users/test_api_refresh.py b/tests/users/test_api_refresh.py index 4b51931ec..3e406e7c0 100644 --- a/tests/users/test_api_refresh.py +++ b/tests/users/test_api_refresh.py @@ -1,11 +1,12 @@ import unittest from datetime import timedelta from http import HTTPStatus + from flask import json from app import messages -from app.database.sqlalchemy_extension import db from app.database.models.user import UserModel +from app.database.sqlalchemy_extension import db from tests.base_test_case import BaseTestCase from tests.test_data import user1 from tests.test_utils import get_test_request_header diff --git a/tests/users/test_api_resources.py b/tests/users/test_api_resources.py index 88bf42780..b6aced478 100644 --- a/tests/users/test_api_resources.py +++ b/tests/users/test_api_resources.py @@ -2,18 +2,18 @@ from unittest.mock import patch from flask import json -from tests.base_test_case import BaseTestCase + from app.database.models.user import UserModel from app.messages import ( - USER_WAS_CREATED_SUCCESSFULLY, - USERNAME_HAS_INVALID_LENGTH, + EMAIL_INPUT_BY_USER_IS_INVALID, PASSWORD_INPUT_BY_USER_HAS_INVALID_LENGTH, + TERMS_AND_CONDITIONS_ARE_NOT_CHECKED, USER_INPUTS_SPACE_IN_PASSWORD, - EMAIL_INPUT_BY_USER_IS_INVALID, USER_USES_A_USERNAME_THAT_ALREADY_EXISTS, USER_USES_AN_EMAIL_ID_THAT_ALREADY_EXISTS, - TERMS_AND_CONDITIONS_ARE_NOT_CHECKED, + USERNAME_HAS_INVALID_LENGTH, ) +from tests.base_test_case import BaseTestCase # Testing User API resources # diff --git a/tests/users/test_api_update_user.py b/tests/users/test_api_update_user.py index 1763f4df6..b57ac7f7c 100644 --- a/tests/users/test_api_update_user.py +++ b/tests/users/test_api_update_user.py @@ -1,7 +1,8 @@ import unittest +from http import HTTPStatus from random import SystemRandom from string import ascii_lowercase -from http import HTTPStatus + from flask import json from app import messages diff --git a/tests/users/test_dao.py b/tests/users/test_dao.py index c6595fe11..182628cb8 100644 --- a/tests/users/test_dao.py +++ b/tests/users/test_dao.py @@ -1,14 +1,16 @@ import datetime import unittest -from werkzeug.security import check_password_hash from http import HTTPStatus + +from werkzeug.security import check_password_hash + from app import messages -from app.api.email_utils import generate_confirmation_token from app.api.dao.user import UserDAO +from app.api.email_utils import generate_confirmation_token from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel -from app.database.sqlalchemy_extension import db from app.database.models.user import UserModel +from app.database.sqlalchemy_extension import db from app.utils.enum_utils import MentorshipRelationState from tests.base_test_case import BaseTestCase from tests.test_data import user2 diff --git a/tests/users/test_dao_dashboard.py b/tests/users/test_dao_dashboard.py index f2aed4b05..058969325 100644 --- a/tests/users/test_dao_dashboard.py +++ b/tests/users/test_dao_dashboard.py @@ -1,9 +1,10 @@ import unittest +from datetime import datetime, timedelta + from flask_restx import marshal + +from app.api.dao.user import DashboardRelationResponseModel, UserDAO from app.api.models.mentorship_relation import list_tasks_response_body -from app.api.email_utils import generate_confirmation_token -from app.api.dao.user import UserDAO, DashboardRelationResponseModel -from datetime import timedelta, datetime from app.database.models.mentorship_relation import MentorshipRelationModel from app.database.models.tasks_list import TasksListModel from app.database.models.user import UserModel diff --git a/tests/users/test_database_model.py b/tests/users/test_database_model.py index c183d5aef..92cd7b2b5 100644 --- a/tests/users/test_database_model.py +++ b/tests/users/test_database_model.py @@ -1,10 +1,10 @@ import unittest + from werkzeug.security import check_password_hash -from tests.base_test_case import BaseTestCase from app.database.models.user import UserModel from app.database.sqlalchemy_extension import db - +from tests.base_test_case import BaseTestCase from tests.test_data import test_admin_user # Testing User database model diff --git a/tests/users/test_validation_request_data.py b/tests/users/test_validation_request_data.py index 76aa08442..464a68696 100644 --- a/tests/users/test_validation_request_data.py +++ b/tests/users/test_validation_request_data.py @@ -4,14 +4,14 @@ from app import messages from app.api.validations.user import ( - validate_user_registration_request_data, - NAME_MIN_LENGTH, NAME_MAX_LENGTH, - USERNAME_MIN_LENGTH, - USERNAME_MAX_LENGTH, + NAME_MIN_LENGTH, PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH, + USERNAME_MAX_LENGTH, + USERNAME_MIN_LENGTH, validate_new_password, + validate_user_registration_request_data, ) from app.utils.validation_utils import get_length_validation_error_message from tests.test_data import user1 diff --git a/tests/users/test_validation_update_user_request_data.py b/tests/users/test_validation_update_user_request_data.py index a0dd7211f..c8ffda830 100644 --- a/tests/users/test_validation_update_user_request_data.py +++ b/tests/users/test_validation_update_user_request_data.py @@ -4,11 +4,11 @@ from app import messages from app.api.validations.user import ( - validate_update_profile_request_data, OCCUPATION_MAX_LENGTH, ORGANIZATION_MAX_LENGTH, USERNAME_MAX_LENGTH, USERNAME_MIN_LENGTH, + validate_update_profile_request_data, ) from app.utils.validation_utils import get_length_validation_error_message diff --git a/tests/utils/test_email_validation.py b/tests/utils/test_email_validation.py index b670deb60..9d12cab5e 100644 --- a/tests/utils/test_email_validation.py +++ b/tests/utils/test_email_validation.py @@ -1,4 +1,5 @@ import unittest + from app.utils.validation_utils import is_email_valid diff --git a/tests/utils/test_get_length_validation_error_msg.py b/tests/utils/test_get_length_validation_error_msg.py index 44c4fac5d..bb835d336 100644 --- a/tests/utils/test_get_length_validation_error_msg.py +++ b/tests/utils/test_get_length_validation_error_msg.py @@ -1,4 +1,5 @@ import unittest + from app.utils.validation_utils import get_length_validation_error_message diff --git a/tests/utils/test_get_stripped_string.py b/tests/utils/test_get_stripped_string.py index ebb709bd7..6533b91b8 100644 --- a/tests/utils/test_get_stripped_string.py +++ b/tests/utils/test_get_stripped_string.py @@ -1,4 +1,5 @@ import unittest + from app.utils.validation_utils import get_stripped_string diff --git a/tests/utils/test_name_validation.py b/tests/utils/test_name_validation.py index ad5642b5c..312ab9406 100644 --- a/tests/utils/test_name_validation.py +++ b/tests/utils/test_name_validation.py @@ -1,4 +1,5 @@ import unittest + from app.utils.validation_utils import is_name_valid diff --git a/tests/utils/test_username_validation.py b/tests/utils/test_username_validation.py index 6b7817189..447a47451 100644 --- a/tests/utils/test_username_validation.py +++ b/tests/utils/test_username_validation.py @@ -1,4 +1,5 @@ import unittest + from app.utils.validation_utils import is_username_valid diff --git a/tests/utils/test_validate_length.py b/tests/utils/test_validate_length.py index 7acea8b68..4d9a65756 100644 --- a/tests/utils/test_validate_length.py +++ b/tests/utils/test_validate_length.py @@ -1,7 +1,8 @@ import unittest + from app.utils.validation_utils import ( - validate_length, get_length_validation_error_message, + validate_length, )