Skip to content

Commit

Permalink
#119: Edit DB backend tests to use camelCase
Browse files Browse the repository at this point in the history
- Most DB tests pass now, but a decision needs to be made regarding foreign keys to allow the tests in test_entity_helper.py to pass
  • Loading branch information
MRichards99 committed Jan 25, 2021
1 parent 58ae900 commit 279681a
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 181 deletions.
6 changes: 3 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def flask_test_app_db():
@pytest.fixture()
def valid_db_credentials_header():
session = SESSION()
session.ID = "Test"
session.EXPIREDATETIME = datetime.now() + timedelta(hours=1)
session.id = "Test"
session.expireDateTime = datetime.now() + timedelta(hours=1)
session.username = "Test User"

insert_row_into_table(SESSION, session)

yield {"Authorization": f"Bearer {session.ID}"}
yield {"Authorization": f"Bearer {session.id}"}

delete_row_by_id(SESSION, "Test")
60 changes: 30 additions & 30 deletions test/db/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

def set_meta_attributes(entity):
db_meta_attributes = {
"CREATE_TIME": Constants.TEST_MOD_CREATE_DATETIME,
"MOD_TIME": Constants.TEST_MOD_CREATE_DATETIME,
"CREATE_ID": "test create id",
"MOD_ID": "test mod id",
"createTime": Constants.TEST_MOD_CREATE_DATETIME,
"modTime": Constants.TEST_MOD_CREATE_DATETIME,
"createId": "test create id",
"modId": "test mod id",
}

for attr, value in db_meta_attributes.items():
Expand All @@ -33,17 +33,17 @@ def create_investigation_db_data(num_entities=1):

for i in range(num_entities):
investigation = INVESTIGATION()
investigation.NAME = f"Test Data for DataGateway API Testing (DB) {i}"
investigation.TITLE = f"Title for DataGateway API Testing (DB) {i}"
investigation.STARTDATE = datetime(
investigation.name = f"Test Data for DataGateway API Testing (DB) {i}"
investigation.title = f"Title for DataGateway API Testing (DB) {i}"
investigation.startDate = datetime(
year=2020, month=1, day=4, hour=1, minute=1, second=1,
)
investigation.ENDDATE = datetime(
investigation.endDate = datetime(
year=2020, month=1, day=8, hour=1, minute=1, second=1,
)
investigation.VISIT_ID = str(uuid.uuid1())
investigation.FACILITY_ID = 1
investigation.TYPE_ID = 1
investigation.visitId = str(uuid.uuid1())
investigation.facility = 1
investigation.type = 1

set_meta_attributes(investigation)

Expand All @@ -63,7 +63,7 @@ def single_investigation_test_data_db():

yield investigation

delete_row_by_id(INVESTIGATION, investigation.ID)
delete_row_by_id(INVESTIGATION, investigation.id)


@pytest.fixture()
Expand All @@ -73,57 +73,57 @@ def multiple_investigation_test_data_db():
yield investigations

for investigation in investigations:
delete_row_by_id(INVESTIGATION, investigation.ID)
delete_row_by_id(INVESTIGATION, investigation.id)


@pytest.fixture()
def isis_specific_endpoint_data_db():
facility_cycle = FACILITYCYCLE()
facility_cycle.NAME = "Test cycle for DG API testing (DB)"
facility_cycle.STARTDATE = datetime(
facility_cycle.name = "Test cycle for DG API testing (DB)"
facility_cycle.startDate = datetime(
year=2020, month=1, day=1, hour=1, minute=1, second=1,
)
facility_cycle.ENDDATE = datetime(
facility_cycle.endDate = datetime(
year=2020, month=2, day=1, hour=1, minute=1, second=1,
)
facility_cycle.FACILITY_ID = 1
facility_cycle.facility = 1
set_meta_attributes(facility_cycle)
insert_row_into_table(FACILITYCYCLE, facility_cycle)

investigation = create_investigation_db_data()

instrument = INSTRUMENT()
instrument.NAME = "Test Instrument for DataGateway API Endpoint Testing (DB)"
instrument.FACILITY_ID = 1
instrument.name = "Test Instrument for DataGateway API Endpoint Testing (DB)"
instrument.facility = 1
set_meta_attributes(instrument)
insert_row_into_table(INSTRUMENT, instrument)

investigation_instrument = INVESTIGATIONINSTRUMENT()
investigation_instrument.INVESTIGATION_ID = investigation.ID
investigation_instrument.INSTRUMENT_ID = instrument.ID
investigation_instrument.investigation = investigation.id
investigation_instrument.instrument = instrument.id
set_meta_attributes(investigation_instrument)

insert_row_into_table(INVESTIGATIONINSTRUMENT, investigation_instrument)

yield (instrument.ID, facility_cycle, investigation)
yield (instrument.id, facility_cycle, investigation)

delete_row_by_id(INVESTIGATIONINSTRUMENT, investigation_instrument.ID)
delete_row_by_id(FACILITYCYCLE, facility_cycle.ID)
delete_row_by_id(INVESTIGATION, investigation.ID)
delete_row_by_id(INSTRUMENT, instrument.ID)
delete_row_by_id(INVESTIGATIONINSTRUMENT, investigation_instrument.id)
delete_row_by_id(FACILITYCYCLE, facility_cycle.id)
delete_row_by_id(INVESTIGATION, investigation.id)
delete_row_by_id(INSTRUMENT, instrument.id)


@pytest.fixture()
def final_instrument_id(flask_test_app_db, valid_db_credentials_header):
final_instrument_result = flask_test_app_db.get(
'/instruments/findone?order="ID DESC"', headers=valid_db_credentials_header,
'/instruments/findone?order="id DESC"', headers=valid_db_credentials_header,
)
return final_instrument_result.json["ID"]
return final_instrument_result.json["id"]


@pytest.fixture()
def final_facilitycycle_id(flask_test_app_db, valid_db_credentials_header):
final_facilitycycle_result = flask_test_app_db.get(
'/facilitycycles/findone?order="ID DESC"', headers=valid_db_credentials_header,
'/facilitycycles/findone?order="id DESC"', headers=valid_db_credentials_header,
)
return final_facilitycycle_result.json["ID"]
return final_facilitycycle_result.json["id"]
4 changes: 2 additions & 2 deletions test/db/endpoints/test_count_with_filters_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_valid_count_with_filters(
self, flask_test_app_db, valid_db_credentials_header,
):
test_response = flask_test_app_db.get(
'/investigations/count?where={"TITLE": {"like": "Title for DataGateway API'
'/investigations/count?where={"title": {"like": "Title for DataGateway API'
' Testing (DB)"}}',
headers=valid_db_credentials_header,
)
Expand All @@ -18,7 +18,7 @@ def test_valid_no_results_count_with_filters(
self, flask_test_app_db, valid_db_credentials_header,
):
test_response = flask_test_app_db.get(
'/investigations/count?where={"TITLE": {"like": "This filter should cause a'
'/investigations/count?where={"title": {"like": "This filter should cause a'
'404 for testing purposes..."}}',
headers=valid_db_credentials_header,
)
Expand Down
4 changes: 2 additions & 2 deletions test/db/endpoints/test_findone_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_valid_findone_with_filters(
single_investigation_test_data_db,
):
test_response = flask_test_app_db.get(
'/investigations/findone?where={"TITLE": {"like": "Title for DataGateway'
'/investigations/findone?where={"title": {"like": "Title for DataGateway'
' API Testing (DB)"}}',
headers=valid_db_credentials_header,
)
Expand All @@ -17,7 +17,7 @@ def test_valid_no_results_findone_with_filters(
self, flask_test_app_db, valid_db_credentials_header,
):
test_response = flask_test_app_db.get(
'/investigations/findone?where={"TITLE": {"eq": "This filter should cause a'
'/investigations/findone?where={"title": {"eq": "This filter should cause a'
'404 for testing purposes..."}}',
headers=valid_db_credentials_header,
)
Expand Down
8 changes: 4 additions & 4 deletions test/db/endpoints/test_get_by_id_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def test_valid_get_with_id(
):
# Need to identify the ID given to the test data
investigation_data = flask_test_app_db.get(
'/investigations?where={"TITLE": {"like": "Title for DataGateway API'
'/investigations?where={"title": {"like": "Title for DataGateway API'
' Testing (DB)"}}',
headers=valid_db_credentials_header,
)
test_data_id = investigation_data.json[0]["ID"]
test_data_id = investigation_data.json[0]["id"]

test_response = flask_test_app_db.get(
f"/investigations/{test_data_id}", headers=valid_db_credentials_header,
Expand All @@ -23,10 +23,10 @@ def test_invalid_get_with_id(
self, flask_test_app_db, valid_db_credentials_header,
):
final_investigation_result = flask_test_app_db.get(
'/investigations/findone?order="ID DESC"',
'/investigations/findone?order="id DESC"',
headers=valid_db_credentials_header,
)
test_data_id = final_investigation_result.json["ID"]
test_data_id = final_investigation_result.json["id"]

# Adding 100 onto the ID to the most recent result should ensure a 404
test_response = flask_test_app_db.get(
Expand Down
14 changes: 7 additions & 7 deletions test/db/endpoints/test_get_with_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_valid_get_with_filters(
single_investigation_test_data_db,
):
test_response = flask_test_app_db.get(
'/investigations?where={"TITLE": {"like": "Title for DataGateway API'
'/investigations?where={"title": {"like": "Title for DataGateway API'
' Testing (DB)"}}',
headers=valid_db_credentials_header,
)
Expand All @@ -20,7 +20,7 @@ def test_valid_no_results_get_with_filters(
self, flask_test_app_db, valid_db_credentials_header,
):
test_response = flask_test_app_db.get(
'/investigations?where={"TITLE": {"eq": "This filter should cause a 404 for'
'/investigations?where={"title": {"eq": "This filter should cause a 404 for'
'testing purposes..."}}',
headers=valid_db_credentials_header,
)
Expand All @@ -32,13 +32,13 @@ def test_valid_get_with_filters_distinct(
self, flask_test_app_db, valid_db_credentials_header,
):
test_response = flask_test_app_db.get(
'/investigations?where={"TITLE": {"like": "Title for DataGateway API'
' Testing (DB)"}}&distinct="TITLE"',
'/investigations?where={"title": {"like": "Title for DataGateway API'
' Testing (DB)"}}&distinct="title"',
headers=valid_db_credentials_header,
)

expected = [
{"TITLE": f"Title for DataGateway API Testing (DB) {i}"} for i in range(5)
{"title": f"Title for DataGateway API Testing (DB) {i}"} for i in range(5)
]

for title in expected:
Expand All @@ -54,9 +54,9 @@ def test_limit_skip_merge_get_with_filters(
limit_value = 2

test_response = flask_test_app_db.get(
'/investigations?where={"TITLE": {"like": "Title for DataGateway API'
'/investigations?where={"title": {"like": "Title for DataGateway API'
' Testing (DB)"}}'
f'&skip={skip_value}&limit={limit_value}&order="ID ASC"',
f'&skip={skip_value}&limit={limit_value}&order="id ASC"',
headers=valid_db_credentials_header,
)

Expand Down
4 changes: 2 additions & 2 deletions test/db/endpoints/test_table_endpoints_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_valid_get_investigations_with_filters(
):
test_response = flask_test_app_db.get(
f"/instruments/{isis_specific_endpoint_data_db[0]}/facilitycycles/"
f"{isis_specific_endpoint_data_db[1].to_dict()['ID']}/investigations",
f"{isis_specific_endpoint_data_db[1].to_dict()['id']}/investigations",
headers=valid_db_credentials_header,
)

Expand Down Expand Up @@ -87,7 +87,7 @@ def test_valid_get_investigations_count_with_filters(
):
test_response = flask_test_app_db.get(
f"/instruments/{isis_specific_endpoint_data_db[0]}/facilitycycles/"
f"{isis_specific_endpoint_data_db[1].to_dict()['ID']}/investigations/count",
f"{isis_specific_endpoint_data_db[1].to_dict()['id']}/investigations/count",
headers=valid_db_credentials_header,
)

Expand Down
Loading

0 comments on commit 279681a

Please sign in to comment.