Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit integration docker #23

Open
wants to merge 8 commits into
base: initial-bit-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,66 @@ name: Run tests

on:
push:
branches: [ develop ]
branches: [ bit ]
pull_request:
branches: [ develop ]
branches: [ bit ]

jobs:
build:

runs-on: ubuntu-latest

env:
DB_TYPE: postgresql+psycopg2
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_ENDPOINT: localhost:5432
DB_TEST_NAME: bit_schema_test
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v2
- name: Connect to PostgreSQL
run: |
PGPASSWORD=postgres psql -h localhost -c 'CREATE DATABASE bit_schema_test;' -U postgres
PGPASSWORD=postgres psql -h localhost -c 'CREATE SCHEMA bitschema;' -U postgres -d bit_schema_test
PGPASSWORD=postgres psql -h localhost -c 'CREATE SCHEMA test_schema;' -U postgres -d bit_schema_test
PGPASSWORD=postgres psql -h localhost -c 'create SCHEMA test_schema_2;' -U postgres -d bit_schema_test
PGPASSWORD=postgres psql -h localhost -c '\dn;' -U postgres -d bit_schema_test
PGPASSWORD=postgres psql -h localhost -c 'show search_path;' -U postgres -d bit_schema_test
PGPASSWORD=postgres psql -h localhost -c "ALTER DATABASE bit_schema_test SET search_path TO bitschema,public;" -U postgres -d bit_schema_test
PGPASSWORD=postgres psql -h localhost -c 'show search_path;' -U postgres -d bit_schema_test
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
- name: Set up Python 3.6
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install dependencies
run: |
python -m pip install --upgrade pip
sudo -H python -m pip install --upgrade pip
pip --version
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests
run: |
python -m unittest discover tests -v

- name: Generate coverage report
run: |
pip install pytest
pip install pytest-cov
pytest --cov=./ --cov-report=xml
pytest --cov tests/ --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ COPY ./requirements.txt /dockerBuild/requirements.txt
WORKDIR /dockerBuild
RUN pip install --no-cache-dir -r requirements.txt
COPY . /dockerBuild
ENV DB_TYPE=postgresql
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to use the same docker env for db postgres that being used in BIT backend?
Screen Shot 2021-03-10 at 9 56 02 pm

Bcoz that's how the 2 backends connect to the postgres locally.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is the same host. Let me see where the POSTGRES_HOST and the POSTGRES_PORT and being used and i'll get back to you , but what I can tell you is that they are connected to the same postgre database.

ENV DB_USERNAME=postgres
ENV DB_PASSWORD=postgres
ENV DB_ENDPOINT=postgres:5432
ENV DB_TEST_ENDPOINT=test_postgres:5432
ENV DB_TEST_NAME=bit_schema_test
ENV DB_NAME=bit_schema
ENV FLASK_APP=run.py
CMD ["flask", "run", "--host", "0.0.0.0"]
8 changes: 4 additions & 4 deletions app/api/dao/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ def update_user_profile(user_id: int, data: Dict[str, str]):
else:
user.occupation = None

if "organization" in data:
if data["organization"]:
user.organization = data["organization"]
if "current_organization" in data:
if data["current_organization"]:
user.current_organization = data["current_organization"]
else:
user.organization = None
user.current_organization = None

if "slack_username" in data:
if data["slack_username"]:
Expand Down
4 changes: 3 additions & 1 deletion app/api/models/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=True, description="User bio"),
"location": fields.String(required=True, description="User location"),
"occupation": fields.String(required=True, description="User occupation"),
"organization": fields.String(required=True, description="User organization"),
"current_organization": fields.String(
required=True, description="User current organization"
),
"skills": fields.String(required=True, description="User skills"),
},
)
12 changes: 9 additions & 3 deletions app/api/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=True, description="User bio"),
"location": fields.String(required=True, description="User location"),
"occupation": fields.String(required=True, description="User occupation"),
"organization": fields.String(required=True, description="User organization"),
"current_organization": fields.String(
required=True, description="User current_organization"
),
"interests": fields.String(required=True, description="User interests"),
"skills": fields.String(required=True, description="User skills"),
"need_mentoring": fields.Boolean(
Expand Down Expand Up @@ -91,7 +93,9 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=False, description="User bio"),
"location": fields.String(required=False, description="User location"),
"occupation": fields.String(required=False, description="User occupation"),
"organization": fields.String(required=False, description="User organization"),
"current_organization": fields.String(
required=False, description="User current_organization"
),
"slack_username": fields.String(
required=False, description="User slack username"
),
Expand Down Expand Up @@ -179,7 +183,9 @@ def add_models_to_namespace(api_namespace):
"bio": fields.String(required=False, description="User bio"),
"location": fields.String(required=False, description="User location"),
"occupation": fields.String(required=False, description="User occupation"),
"organization": fields.String(required=False, description="User organization"),
"current_organization": fields.String(
required=False, description="User current_organization"
),
"slack_username": fields.String(
required=False, description="User slack username"
),
Expand Down
2 changes: 1 addition & 1 deletion app/api/resources/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get(cls):
A admin user with valid access token can view the list of all admins. The endpoint
doesn't take any other input. A JSON array having an object for each admin user is
returned. The array contains id, username, name, slack_username, bio,
location, occupation, organization, skills.
location, occupation, current_organization, skills.
The current admin user's details are not returned.
"""
user_id = get_jwt_identity()
Expand Down
9 changes: 4 additions & 5 deletions app/api/resources/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def get(cls):
A user with valid access token can view the list of users. The endpoint
doesn't take any other input. A JSON array having an object for each user is
returned. The array contains id, username, name, slack_username, bio,
location, occupation, organization, interests, skills, need_mentoring,
available_to_mentor, registration_date. The current user's details are not returned.
location, occupation, current_organization, interests, skills, need_mentoring,
available_to_mentor. The current user's details are not returned.
"""

page = request.args.get("page", default=UserDAO.DEFAULT_PAGE, type=int)
Expand Down Expand Up @@ -158,7 +158,7 @@ def put(cls):

A user with valid access token can use this endpoint to edit his/her own
user details. The endpoint takes any of the given parameters (name, username,
bio, location, occupation, organization, slack_username, social_media_links,
bio, location, occupation, current_organization, slack_username, social_media_links,
skills, interests, resume_url, photo_url, need_mentoring, available_to_mentor).
The response contains a success message.
"""
Expand Down Expand Up @@ -269,7 +269,7 @@ def get(cls):
A user with valid access token can view the list of verified users. The endpoint
doesn't take any other input. A JSON array having an object for each user is
returned. The array contains id, username, name, slack_username, bio,
location, occupation, organization, interests, skills, need_mentoring,
location, occupation, current_organization, interests, skills, need_mentoring,
available_to_mentor. The current user's details are not returned.
"""

Expand Down Expand Up @@ -337,7 +337,6 @@ def post(cls):

if result[1] is HTTPStatus.CREATED:
send_email_verification_message(data["name"], data["email"])

return result


Expand Down
8 changes: 4 additions & 4 deletions app/api/validations/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ def validate_update_profile_request_data(data):
if not is_valid[0]:
return is_valid[1]

organization = data.get("organization", None)
if organization:
current_organization = data.get("current_organization", None)
if current_organization:
is_valid = validate_length(
len(get_stripped_string(organization)),
len(get_stripped_string(current_organization)),
0,
ORGANIZATION_MAX_LENGTH,
"organization",
"current_organization",
)
if not is_valid[0]:
return is_valid[1]
Expand Down
16 changes: 8 additions & 8 deletions app/database/models/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class MentorshipRelationModel(db.Model):
action_user_id: integer indicates id of action user.
mentor: relationship between UserModel and mentorship_relation.
mentee: relationship between UserModel and mentorship_relation.
creation_date: float that defines the date of creation of the mentorship.
accept_date: float that indicates the date of acceptance of mentorship.
start_date: float that indicates the starting date of mentorship.
end_date: float that indicates the ending date of mentorship.
creation_date: numeric that defines the date of creation of the mentorship.
accept_date: numeric that indicates the date of acceptance of mentorship.
start_date: numeric that indicates the starting date of mentorship.
end_date: numeric that indicates the ending date of mentorship.
state: enumeration that indicates state of mentorship.
notes: string that indicates any notes.
tasks_list_id: integer indicates the id of the tasks_list
Expand Down Expand Up @@ -47,10 +47,10 @@ class MentorshipRelationModel(db.Model):
primaryjoin="MentorshipRelationModel.mentee_id == UserModel.id",
)

creation_date = db.Column(db.Float, nullable=False)
accept_date = db.Column(db.Float)
start_date = db.Column(db.Float)
end_date = db.Column(db.Float)
creation_date = db.Column(db.Numeric("16,6", asdecimal=False), nullable=False)
accept_date = db.Column(db.Numeric("16,6", asdecimal=False))
start_date = db.Column(db.Numeric("16,6", asdecimal=False))
end_date = db.Column(db.Numeric("16,6", asdecimal=False))

state = db.Column(db.Enum(MentorshipRelationState), nullable=False)
notes = db.Column(db.String(400))
Expand Down
8 changes: 4 additions & 4 deletions app/database/models/task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class TaskCommentModel(db.Model):
task_id: An integer for storing the task's id.
user_id: An integer for storing the user's id.
relation_id: An integer for storing the relation's id.
creation_date: A float indicating comment's creation date.
modification_date: A float indicating the modification date.
creation_date: A numeric indicating comment's creation date.
modification_date: A numeric indicating the modification date.
comment: A string indicating the comment.
"""

Expand All @@ -24,8 +24,8 @@ class TaskCommentModel(db.Model):
user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
task_id = db.Column(db.Integer, db.ForeignKey("tasks_list.id"))
relation_id = db.Column(db.Integer, db.ForeignKey("mentorship_relations.id"))
creation_date = db.Column(db.Float, nullable=False)
modification_date = db.Column(db.Float)
creation_date = db.Column(db.Numeric("16,6", asdecimal=False), nullable=False)
modification_date = db.Column(db.Numeric("16,6", asdecimal=False))
comment = db.Column(db.String(COMMENT_MAX_LENGTH), nullable=False)

def __init__(self, user_id, task_id, relation_id, comment):
Expand Down
4 changes: 2 additions & 2 deletions app/database/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class UserModel(db.Model):
bio = db.Column(db.String(500))
location = db.Column(db.String(80))
occupation = db.Column(db.String(80))
organization = db.Column(db.String(80))
current_organization = db.Column(db.String(80))
slack_username = db.Column(db.String(80))
social_media_links = db.Column(db.String(500))
skills = db.Column(db.String(500))
Expand Down Expand Up @@ -97,7 +97,7 @@ def json(self):
"bio": self.bio,
"location": self.location,
"occupation": self.occupation,
"organization": self.organization,
"current_organization": self.current_organization,
"slack_username": self.slack_username,
"social_media_links": self.social_media_links,
"skills": self.skills,
Expand Down
33 changes: 19 additions & 14 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class BaseConfig(object):
DB_PASSWORD = os.getenv("DB_PASSWORD")
DB_ENDPOINT = os.getenv("DB_ENDPOINT")
DB_NAME = os.getenv("DB_NAME")
DB_TEST_NAME = os.getenv("DB_TEST_NAME")
DB_TEST_ENDPOINT = os.getenv("DB_TEST_ENDPOINT", DB_ENDPOINT)

UNVERIFIED_USER_THRESHOLD = 2592000 # 30 days

Expand Down Expand Up @@ -84,15 +86,17 @@ def build_db_uri(
db_endpoint_arg=DB_ENDPOINT,
db_name_arg=DB_NAME,
):
"""Build remote database uri using specific environment variables."""

return "{db_type}://{db_user}:{db_password}@{db_endpoint}/{db_name}".format(
db_type=db_type_arg,
db_user=db_user_arg,
db_password=db_password_arg,
db_endpoint=db_endpoint_arg,
db_name=db_name_arg,
)
return f"{db_type_arg}://{db_user_arg}:{db_password_arg}@{db_endpoint_arg}/{db_name_arg}"

@staticmethod
def build_db_test_uri(
db_type_arg=DB_TYPE,
db_user_arg=DB_USERNAME,
db_password_arg=DB_PASSWORD,
db_endpoint_arg=DB_TEST_ENDPOINT,
db_name_arg=DB_TEST_NAME,
):
return f"{db_type_arg}://{db_user_arg}:{db_password_arg}@{db_endpoint_arg}/{db_name_arg}"


class ProductionConfig(BaseConfig):
Expand Down Expand Up @@ -121,9 +125,7 @@ class LocalConfig(BaseConfig):
"""Local configuration."""

DEBUG = True

# Using a local sqlite database
SQLALCHEMY_DATABASE_URI = "sqlite:///local_data.db"
SQLALCHEMY_DATABASE_URI = BaseConfig.build_db_uri()


class TestingConfig(BaseConfig):
Expand All @@ -132,8 +134,11 @@ class TestingConfig(BaseConfig):
TESTING = True
MOCK_EMAIL = True

# Use in-memory SQLite database for testing
SQLALCHEMY_DATABASE_URI = "sqlite://"
# Using a local postgre database on MacOS
# SQLALCHEMY_DATABASE_URI = "postgresql:///bit_schema_test"

# Using a local postgre database on other OS
SQLALCHEMY_DATABASE_URI = BaseConfig.build_db_test_uri()


def get_env_config() -> str:
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
postgres:
image: postgres
environment:
POSTGRES_PASSWORD: postgres
#Default_DB that will be connected
POSTGRES_DB: bit_schema
web:
build: .
ports:
- 4000:5000




1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
APScheduler==3.6.3
coverage==5.3
Flask==1.0.2
Flask-Cors==3.0.9
Flask-JWT-Extended==3.25.0
Flask-Mail==0.9.1
Flask-Migrate==2.5.3
Expand Down
Loading