Skip to content

Commit

Permalink
merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
gcarvellas committed Oct 26, 2023
2 parents 5b4f34e + 62a3a92 commit 002860b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Main workflow

on:
pull_request:
push:

jobs:
test:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false

steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: make check
run: |
pip install -r requirements.txt
make check
4 changes: 2 additions & 2 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def __init__(self) -> None:

def get_contract_limit(self, key: str) -> int:
value = self._config['contract_limits'].get(key)
assert type(value) == int, "Invalid config file. Contract limits can only be integers."
assert type(value) is int, "Invalid config file. Contract limits can only be integers."
return value

def get_docusign_config(self, key: str) -> str:
value = self._config['docusign'].get(key)
assert type(value) == str, "Invalid docusign config"
assert type(value) is str, "Invalid docusign config"
return value
2 changes: 1 addition & 1 deletion config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def load_env(input: str) -> str:
data = os.getenv(input)
assert type(data) == str and len(data) > 0, f"Invalid or no '{input}' environment variable."
assert type(data) is str and len(data) > 0, f"Invalid or no '{input}' environment variable."
return data


Expand Down
5 changes: 5 additions & 0 deletions controllers/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ async def post(self, item: PostItem, current_user: CognitoClaims = Depends(get_c
status_code=status.HTTP_409_CONFLICT,
detail='Cannot make contract since there is nobody to approve the contract'
)
except NotImplementedError:
raise HTTPException(
status_code=status.HTTP_501_NOT_IMPLEMENTED,
detail='Unable to create contract of specified type'
)

return JSONResponse(
status_code=status.HTTP_200_OK,
Expand Down
9 changes: 8 additions & 1 deletion controllers/me.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing_extensions import TypedDict
import uuid
from database.users import UsersDB
from pymongo.errors import DuplicateKeyError


class PostItem(BaseModel):
Expand Down Expand Up @@ -70,7 +71,13 @@ async def patch(self, current_user: CognitoClaims = Depends(get_current_user)) -
)

async def post(self, item: PostItem, current_user: CognitoClaims = Depends(get_current_user)) -> Response: # type: ignore[no-any-unimported]
ret: bool = await MeManager().create_user(current_user.sub, current_user.username, str(item.vendor_type))
try:
ret: bool = await MeManager().create_user(current_user.sub, current_user.username, str(item.vendor_type))
except DuplicateKeyError:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Specified user already exists"
)
if not ret:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down
7 changes: 1 addition & 6 deletions database/base_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase, AsyncIOMotorCollection
from config.env import MONGO_URI, MONGO_DB_NAME
import logging
from typing import Optional, List
from utilities.types import MongoMappingType, JSONDict

Expand All @@ -18,11 +17,7 @@ def _get_client(cls) -> AsyncIOMotorClient: # type: ignore[no-any-unimported]

@classmethod
def _verify_connection(cls, client: AsyncIOMotorClient) -> None: # type: ignore[no-any-unimported]
try:
client.server_info()
except Exception as e:
logging.critical("Cannot connect to db.")
raise e
client.server_info()

@classmethod
def get_database(cls) -> AsyncIOMotorDatabase: # type: ignore[no-any-unimported]
Expand Down
2 changes: 1 addition & 1 deletion database/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def _get_random_reviewer(cls, role: str) -> Optional[MongoMappingType]:
results = await cls.get_random(cls.get_collection(), 1, query)
if len(results) == 0:
return None
assert len(results) == 1
assert len(results) == 1, "Recieved too many results"
return results[0]

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions managers/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ async def create_contract(

# TODO the approver_name should be the user's name, not username

assert type(approver_email) == str
assert type(approver_name) == str
assert type(approver_email) is str, "Expected a string for approver email"
assert type(approver_name) is str, "Expected a string for approver name"

data = ContractData(
num_additional_chairs=num_additional_chairs,
Expand Down
7 changes: 3 additions & 4 deletions services/docusign/docusign.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from .envelope import Contract
from services.docusign import ContractData
from docusign_esign import ApiClient
Expand Down Expand Up @@ -61,7 +60,7 @@ def _handle_consent(cls, err: ApiException, callback: Callable[[ApiClient, str,
return callback(api_client, private_key, contract_data)

logging.error(body)
sys.exit("Failed to grant consent") # TODO can this sys.exit be removed?
raise Exception("Consent could not be aquired")

@classmethod
def _run(cls, api_client: ApiClient, private_key: str, contract_data: ContractData) -> str: # type: ignore[no-any-unimported]
Expand All @@ -74,11 +73,11 @@ def _run(cls, api_client: ApiClient, private_key: str, contract_data: ContractDa

envelope_data: Dict[str, str] = Contract(access_token, base_path, account_id).make_contract(contract_data)

assert type(envelope_data) == dict, f"Invalid envelope response: {envelope_data}"
assert type(envelope_data) is dict, f"Invalid envelope response: {envelope_data}"
assert "envelope_id" in envelope_data, f"Envelope does not contain ID: {envelope_data}"

envelope_id: Optional[str] = envelope_data["envelope_id"]
assert type(envelope_id) == str, f"Invalid envelope id {envelope_id} of type {type(envelope_id)}"
assert type(envelope_id) is str, f"Invalid envelope id {envelope_id} of type {type(envelope_id)}"

return envelope_id

Expand Down

0 comments on commit 002860b

Please sign in to comment.