Skip to content

Commit

Permalink
Merge pull request #30 from brighthive/feat/HIVE-877/expose-vendor-cr…
Browse files Browse the repository at this point in the history
…eation-date

Feat/hive 877/expose vendor creation date
  • Loading branch information
johnosullivan authored Jul 22, 2020
2 parents 307ef13 + 562ae2b commit 801f7ec
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 62 deletions.
5 changes: 3 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pycodestyle = "*"
"autopep8" = "*"
flask = "*"
flask-restful = "*"
gunicorn = {extras = ["gevent"], version = "*"}
gunicorn = {extras = ["gevent"],version = "*"}
flask-sqlalchemy = "*"
flask-migrate = "*"
"psycopg2-binary" = "*"
brighthive-authlib = "*"
requests = "*"
gevent = "*"
mci-database = {editable = true, ref = "master", git = "https://github.com/brighthive/mci-database.git"}
mci-database = {editable = true,ref = "master",git = "https://github.com/brighthive/mci-database.git"}

[dev-packages]
expects = "*"
Expand All @@ -25,6 +25,7 @@ docker = "*"
sphinx = "*"
pytest-mock = "*"
requests-mock = "*"
mock = "*"

[requires]
python_version = "3.8"
111 changes: 61 additions & 50 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
mci:
image: brighthive/master-client-index:1.0.1
image: brighthive/master-client-index:latest
ports:
- "8001:8000"
environment:
Expand All @@ -11,24 +11,23 @@ services:
- POSTGRES_DATABASE=mci_dev
- POSTGRES_HOSTNAME=postgres_mci
- POSTGRES_PORT=5432
- MATCHING_SERVICE_URI=http://mci-matching-service:8000/compute-match
depends_on:
- postgres_mci
postgres_mci:
image: postgres:11.1
environment:
- APP_ENV=DEVELOPMENT
- POSTGRES_USER=brighthive
- POSTGRES_PASSWORD=test_password
- POSTGRES_DB=mci_dev
- MATCHING_SERVICE_URI=http://localhost:8000/compute-match
ports:
- "5436:5432"
- "5432:5432"
# Spinning up postgres (when decoupled from the app)
# assigns the db files to postgres.
#
# postgres_mci_1 | The files belonging to this database system will be owned by user "postgres".
# postgres_mci_1 | This user must also own the server process.
#
# postgres_mci_1 | This user must also own the server process.
#
# Without a designated user, the container does not have an (unprivileged, i.e., not "root")
# who owns the server process. That's a problem! Because the mci container
# cannot connect to the database and run migrations.
Expand All @@ -37,3 +36,13 @@ services:
image: 396527728813.dkr.ecr.us-east-2.amazonaws.com/brighthive/mci-matching-service:latest
ports:
- "8888:8000"
environment:
- APP_ENV=PRODUCTION
- POSTGRES_USER=brighthive
- POSTGRES_PASSWORD=test_password
- POSTGRES_DATABASE=mci_dev
- POSTGRES_HOSTNAME=postgres_mci
- POSTGRES_PORT=5432
networks:
mci_network:
external: true
10 changes: 7 additions & 3 deletions mci/api/v1_0_0/user_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UserHandler(object):

def create_user_blob(self, mci_id: str):
"""
Creates an object with data of an existing user.
Creates an object with data of an existing user.
Called when GETing the `user` endpoint with an MCI ID.
Args:
Expand All @@ -48,6 +48,7 @@ def create_user_blob(self, mci_id: str):
'mci_id': user_obj.mci_id,
'vendor_id': '' if user_obj.vendor_id is None else user_obj.vendor_id,
'registration_date': '' if user_obj.registration_date is None else datetime.strftime(user_obj.registration_date, '%Y-%m-%d'),
'vendor_creation_date': '' if user_obj.vendor_creation_date is None else datetime.strftime(user_obj.vendor_creation_date, '%Y-%m-%d'),
# 'ssn': '' if user_obj.ssn is None else user_obj.ssn,
'first_name': '' if user_obj.first_name is None else user_obj.first_name,
'suffix': '' if user_obj.suffix is None else user_obj.suffix,
Expand All @@ -67,7 +68,7 @@ def create_user_blob(self, mci_id: str):

def create_new_user(self, user_object):
"""
Creates a new user.
Creates a new user.
Called when POSTing to the `users` endpoint.
"""
errors = []
Expand Down Expand Up @@ -169,6 +170,9 @@ def create_new_user(self, user_object):
else:
new_user.dispositions.append(disposition['object'])

if 'vendor_creation_date' in user.keys():
new_user.vendor_creation_date = user['vendor_creation_date']

if len(errors) == 0:
matching_service_uri = config.get_matching_service_uri()
new_user_json = json.dumps(new_user.as_dict, default=str)
Expand All @@ -186,7 +190,7 @@ def create_new_user(self, user_object):
}, 400

def get_all_users(self, offset=0, limit=20):
"""
"""
Retrieve all users.
Called when GETing the `users` endpoint.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_user_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_users_endpoint_empty(self, mocker, database, test_client):
'''
response = test_client.get('/users')

assert response.status_code == 404
assert response.status_code == 200
assert response.json['users'] == []

@mock.patch('brighthive_authlib.providers.AuthZeroProvider.validate_token', return_value=True)
Expand Down

0 comments on commit 801f7ec

Please sign in to comment.