From 82e42b7233f4923b0919a2a97fd8cafa632d7e88 Mon Sep 17 00:00:00 2001 From: adafia Date: Thu, 28 Nov 2019 13:26:15 +0200 Subject: [PATCH] CV3-68-refactor(fixtures): refactor fixtures folder - split fixture files in question to query and response - add output builder to dynamically build fixture outputs [Finishes CV3-68] --- .../analytics/analytics_query_responses.py | 180 +++++ .../analytics/query_all_analytics_fixtures.py | 187 ------ fixtures/block/create_block_fixtures.py | 202 +----- .../block/create_block_response_fixtures.py | 60 ++ fixtures/channels/channel_fixtures.py | 21 - .../channels/channel_responses_fixtures.py | 20 + fixtures/devices/devices_fixtures.py | 141 +--- .../devices/devices_fixtures_responses.py | 110 ++++ fixtures/events/end_event_fixtures.py | 23 - .../events/end_event_responses_fixtures.py | 22 + fixtures/events/event_checkin_fixtures.py | 38 -- .../event_checkin_responses_fixtures.py | 27 + fixtures/events/events_by_room_fixtures.py | 30 - .../events_by_room_responses_fixtures.py | 29 + .../events/events_query_by_date_fixtures.py | 36 - ...events_query_by_date_responses_fixtures.py | 35 + fixtures/events/events_ratios_fixtures.py | 78 --- .../events_ratios_responses_fixtures.py | 70 ++ fixtures/events/sync_events_data_fixture.py | 16 - .../sync_events_data_responses_fixture.py | 15 + fixtures/location/all_locations_fixtures.py | 22 +- .../location/rooms_in_location_fixtures.py | 8 +- fixtures/location/update_location_fixtures.py | 26 +- fixtures/office/office_fixtures.py | 203 ++---- fixtures/office/office_responses_fixtures.py | 79 +++ fixtures/output/Error.py | 34 + fixtures/output/OutputBuilder.py | 67 ++ .../questions/create_questions_fixtures.py | 84 +-- .../create_questions_responses_fixtures.py | 66 ++ fixtures/questions/get_question_fixtures.py | 149 ----- .../get_question_responses_fixtures.py | 148 +++++ .../questions/questions_fixtures_helper.py | 24 + .../response/archive_response_fixtures.py | 61 +- .../room_all_resolved_response_fixture.py | 36 + .../response/room_filter_response_fixture.py | 49 ++ .../response/room_mark_response_fixture.py | 216 ++++++ .../response/room_query_response_fixture.py | 77 +++ fixtures/response/room_response_fixture.py | 615 ------------------ .../response/room_search_response_fixture.py | 143 ++++ .../response/room_summary_response_fixture.py | 61 ++ fixtures/response/user_response_check.py | 53 +- fixtures/response/user_response_fixtures.py | 87 +-- fixtures/role/role_fixtures.py | 32 +- fixtures/room/create_room_fixtures.py | 338 ---------- fixtures/room/create_room_query_fixtures.py | 167 +++++ .../room/create_room_responses_fixtures.py | 115 ++++ fixtures/room/daily_room_events_fixture.py | 56 -- .../daily_room_events_responses_fixture.py | 57 ++ fixtures/room/delete_room_fixtures.py | 47 +- fixtures/room/filter_room_fixtures.py | 121 ---- .../room/filter_room_responses_fixtures.py | 108 +++ fixtures/room/query_room_fixtures.py | 52 +- .../room_analytics_bookings_count_fixtures.py | 59 +- .../room/room_analytics_duration_fixtures.py | 53 +- .../get_rooms_with_resource_fixtures.py | 31 +- fixtures/room_resource/resource_fixture.py | 59 +- .../room_resource/update_resource_fixtures.py | 52 +- fixtures/structure/structures_fixtures.py | 59 +- fixtures/tags/create_tags_fixtures.py | 89 +-- fixtures/user/add_user_fixture.py | 31 +- fixtures/user/user_fixture.py | 406 ++---------- fixtures/user/user_fixture_response.py | 175 +++++ fixtures/user_role/user_role_fixtures.py | 59 +- fixtures/wing/wing_fixtures.py | 87 +-- .../test_all_analytics_query.py | 7 +- .../test_authentication.py | 5 +- tests/test_channels/test_channels.py | 7 +- tests/test_devices/test_all_devices.py | 4 +- tests/test_devices/test_create_device.py | 5 +- tests/test_devices/test_delete_device.py | 4 +- tests/test_devices/test_specific_device.py | 8 +- tests/test_events/test_end_event.py | 12 +- tests/test_events/test_event_checkin.py | 8 +- .../test_query_all_events_by_date.py | 6 +- .../test_query_all_events_by_room.py | 7 +- tests/test_events/test_sync_events_data.py | 6 +- tests/test_healthcheck/test_db.py | 8 +- tests/test_questions/test_create_question.py | 4 +- tests/test_questions/test_delete_question.py | 4 +- tests/test_questions/test_update_question.py | 12 +- tests/test_questions/test_view_question.py | 12 +- .../test_response/test_resolved_responses.py | 16 +- tests/test_response/test_room_response.py | 30 +- tests/test_rooms/test_create_room.py | 19 +- tests/test_rooms/test_query_rooms.py | 5 +- tests/test_rooms/test_room_filter.py | 16 +- tests/test_user/test_change_user_location.py | 10 +- tests/test_user/test_change_user_role.py | 9 +- tests/test_user/test_create_user.py | 5 +- tests/test_user/test_invite_email.py | 7 +- tests/test_user/test_query_user.py | 21 +- tests/test_user/test_set_user_location.py | 9 +- 92 files changed, 2878 insertions(+), 3289 deletions(-) create mode 100644 fixtures/analytics/analytics_query_responses.py create mode 100644 fixtures/block/create_block_response_fixtures.py create mode 100644 fixtures/channels/channel_responses_fixtures.py create mode 100644 fixtures/devices/devices_fixtures_responses.py create mode 100644 fixtures/events/end_event_responses_fixtures.py create mode 100644 fixtures/events/event_checkin_responses_fixtures.py create mode 100644 fixtures/events/events_by_room_responses_fixtures.py create mode 100644 fixtures/events/events_query_by_date_responses_fixtures.py create mode 100644 fixtures/events/events_ratios_responses_fixtures.py create mode 100644 fixtures/events/sync_events_data_responses_fixture.py create mode 100644 fixtures/office/office_responses_fixtures.py create mode 100644 fixtures/output/Error.py create mode 100644 fixtures/output/OutputBuilder.py create mode 100644 fixtures/questions/create_questions_responses_fixtures.py create mode 100644 fixtures/questions/get_question_responses_fixtures.py create mode 100644 fixtures/questions/questions_fixtures_helper.py create mode 100644 fixtures/response/room_all_resolved_response_fixture.py create mode 100644 fixtures/response/room_filter_response_fixture.py create mode 100644 fixtures/response/room_mark_response_fixture.py create mode 100644 fixtures/response/room_query_response_fixture.py create mode 100644 fixtures/response/room_search_response_fixture.py create mode 100644 fixtures/response/room_summary_response_fixture.py create mode 100644 fixtures/room/create_room_query_fixtures.py create mode 100644 fixtures/room/create_room_responses_fixtures.py create mode 100644 fixtures/room/daily_room_events_responses_fixture.py create mode 100644 fixtures/room/filter_room_responses_fixtures.py create mode 100644 fixtures/user/user_fixture_response.py diff --git a/fixtures/analytics/analytics_query_responses.py b/fixtures/analytics/analytics_query_responses.py new file mode 100644 index 000000000..ce1294fcd --- /dev/null +++ b/fixtures/analytics/analytics_query_responses.py @@ -0,0 +1,180 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +null = None +all_analytics_query_response = { + "data": { + "allAnalytics": { + "checkinsPercentage": 0.0, + "appBookingsPercentage": 0.0, + "autoCancellationsPercentage": 0.0, + "cancellationsPercentage": 0.0, + "bookings": 1, + "analytics": [ + { + "roomName": "Entebbe", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 1, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 100.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 45 + } + ] + }, + { + "roomName": "Tana", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 0, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 0.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 0 + } + ] + } + ], + "bookingsCount": [ + { + "totalBookings": 1, + "period": "Jul 11 2018" + }, + { + 'totalBookings': 0, + 'period': 'Jul 12 2018' + } + ] + } + } +} + +aaq_error = error_item +aaq_error.message = "Location Id does not exist" +aaq_error.locations = [{"line": 3, "column": 7}] +aaq_error.path = ["allAnalytics"] +aaq_data = {"allAnalytics": None} + +all_analytics_query_response_super_admin_with_invalid_locationid = build( + aaq_error.build_error(aaq_error), + aaq_data +) +all_analytics_query_response_super_admin = { + "data": { + "allAnalytics": { + "checkinsPercentage": 0.0, + "appBookingsPercentage": 0.0, + "autoCancellationsPercentage": 0.0, + "cancellationsPercentage": 0.0, + "bookings": 12, + "analytics": [ + { + "roomName": "Oculus", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 6, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 50.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 890 + } + ] + }, + { + "roomName": "Krypton", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 3, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 25.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 155 + } + ] + }, + { + "roomName": "Bujumbura", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 3, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 25.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 92 + } + ] + }, + { + "roomName": "Kampala", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 0, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 0.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 0 + } + ] + }, + { + "roomName": "Algiers", + "cancellations": 0, + "cancellationsPercentage": 0.0, + "autoCancellations": 0, + "numberOfBookings": 0, + "checkins": 0, + "checkinsPercentage": 0.0, + "bookingsPercentageShare": 0.0, + "appBookings": 0, + "appBookingsPercentage": 0.0, + "events": [ + { + "durationInMinutes": 0 + } + ] + } + ], + "bookingsCount": [ + { + "totalBookings": 7, + "period": "Jul 11 2018" + }, + { + "totalBookings": 5, + "period": "Jul 12 2018" + } + ] + } + } +} diff --git a/fixtures/analytics/query_all_analytics_fixtures.py b/fixtures/analytics/query_all_analytics_fixtures.py index f7b05fc61..41e59a438 100644 --- a/fixtures/analytics/query_all_analytics_fixtures.py +++ b/fixtures/analytics/query_all_analytics_fixtures.py @@ -59,193 +59,6 @@ } ''' -all_analytics_query_response = { - "data": { - "allAnalytics": { - "checkinsPercentage": 0.0, - "appBookingsPercentage": 0.0, - "autoCancellationsPercentage": 0.0, - "cancellationsPercentage": 0.0, - "bookings": 1, - "analytics": [ - { - "roomName": "Entebbe", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 1, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 100.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 45 - } - ] - }, - { - "roomName": "Tana", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 0, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 0.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 0 - } - ] - } - ], - "bookingsCount": [ - { - "totalBookings": 1, - "period": "Jul 11 2018" - }, - { - 'totalBookings': 0, - 'period': 'Jul 12 2018' - } - ] - } - } -} - -all_analytics_query_response_super_admin_with_invalid_locationid = { - "errors": [ - { - "message": "Location Id does not exist", - "locations": [ - { - "line": 3, - "column": 7 - } - ], - "path": [ - "allAnalytics" - ] - } - ], - "data": { - "allAnalytics": None - } -} - -all_analytics_query_response_super_admin = { - "data": { - "allAnalytics": { - "checkinsPercentage": 0.0, - "appBookingsPercentage": 0.0, - "autoCancellationsPercentage": 0.0, - "cancellationsPercentage": 0.0, - "bookings": 12, - "analytics": [ - { - "roomName": "Oculus", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 6, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 50.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 890 - } - ] - }, - { - "roomName": "Krypton", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 3, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 25.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 155 - } - ] - }, - { - "roomName": "Bujumbura", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 3, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 25.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 92 - } - ] - }, - { - "roomName": "Kampala", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 0, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 0.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 0 - } - ] - }, - { - "roomName": "Algiers", - "cancellations": 0, - "cancellationsPercentage": 0.0, - "autoCancellations": 0, - "numberOfBookings": 0, - "checkins": 0, - "checkinsPercentage": 0.0, - "bookingsPercentageShare": 0.0, - "appBookings": 0, - "appBookingsPercentage": 0.0, - "events": [ - { - "durationInMinutes": 0 - } - ] - } - ], - "bookingsCount": [ - { - "totalBookings": 7, - "period": "Jul 11 2018" - }, - { - "totalBookings": 5, - "period": "Jul 12 2018" - } - ] - } - } -} - analytics_query_for_date_ranges = ''' query { allAnalytics(startDate:"jul 11 2020", endDate:"jul 12 2018") { diff --git a/fixtures/block/create_block_fixtures.py b/fixtures/block/create_block_fixtures.py index 169350b47..88611a0c3 100644 --- a/fixtures/block/create_block_fixtures.py +++ b/fixtures/block/create_block_fixtures.py @@ -1,8 +1,6 @@ -null = None - -create_block_query = ''' +create_block_sample_string = ''' mutation{ - createBlock(officeId:2, name:"blask" ) { + createBlock(officeId:%d, name:"%s" ) { block{ officeId name @@ -10,94 +8,9 @@ } } ''' - -create_block_response = { - "data": { - "createBlock": { - "block": { - "officeId": 2, - "name": "Blask" - } - } - } -} - -block_mutation_query_without_name = ''' - mutation{ - createBlock(officeId:2, name:"" ) { - block{ - officeId - name - } - } -} -''' - -block_creation_with_duplicate_name = ''' +delete_block_sample_string = ''' mutation{ - createBlock(officeId:2 name:"Ec" ) { - block{ - officeId - name - } - } -} -''' - -block_creation_with_duplicate_name_response = { - "errors": [ - { - "message": "Ec Block already exists", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "createBlock" - ] - } - ], - "data": { - "createBlock": null - } -} - -create_block_with_non_existing_office = ''' -mutation{ - createBlock(officeId:56 name:"Block F" ) { - block{ - officeId - name - } - } -} -''' - -create_block_with_non_existing_office_response = { - "errors": [ - { - "message": "Office not found", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "createBlock" - ] - } - ], - "data": { - "createBlock": null - } -} - -update_block = ''' -mutation{ - updateBlock(name: "Block A", blockId: 1){ + DeleteBlock(blockId:%s){ block{ name id @@ -105,22 +18,9 @@ } } ''' - - -update_block_response = { - "data": { - "updateBlock": { - "block": { - "name": "Block A", - "id": "1" - } - } - } -} - -delete_block = ''' +update_block_sample_string = ''' mutation{ - DeleteBlock(blockId:1){ + updateBlock(name: "%d", blockId: %s){ block{ name id @@ -129,88 +29,22 @@ } ''' -delete_block_response = { - "data": { - "DeleteBlock": { - "block": { - "name": "Ec", - "id": "1" - } - } - } -} +create_block_query = create_block_sample_string % (2, "blask") -delete_non_existent_block = ''' -mutation{ - DeleteBlock(blockId:431){ - block{ - name - id - } - } -} -''' +block_mutation_query_without_name = create_block_sample_string % (2, "") -delete_non_existent_block_response = { - "errors": [ - { - "message": "Block not found", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "DeleteBlock" - ] - } - ], - "data": { - "DeleteBlock": null - } -} +block_creation_with_duplicate_name = create_block_sample_string % (2, "Ec") +create_block_with_non_existing_office = create_block_sample_string % ( + 56, "Block F") -update_non_existent_block = ''' -mutation{ - updateBlock(name: "Block A", blockId: 423){ - block{ - name - id - } - } -} -''' +update_block = update_block_sample_string % ("Block A", 1) -update_non_existent_block_response = { - "errors": [ - { - "message": "Block not found", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "updateBlock" - ] - } - ], - "data": { - "updateBlock": null - } -} +delete_block = delete_block_sample_string % (1) -create_block_outside_nairobi = ''' - mutation{ - createBlock(officeId:1, name:"Block D" ) { - block{ - officeId - name - } - } -} -''' +delete_non_existent_block = delete_block_sample_string % (431) + +update_non_existent_block = update_block_sample_string % ("Block A", 423) + +create_block_outside_nairobi = create_block_sample_string % (1, "Block D") diff --git a/fixtures/block/create_block_response_fixtures.py b/fixtures/block/create_block_response_fixtures.py new file mode 100644 index 000000000..54c0775f7 --- /dev/null +++ b/fixtures/block/create_block_response_fixtures.py @@ -0,0 +1,60 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +null = None + +cbr_data = {"createBlock": {"block": {"officeId": 2, "name": "Blask"}}} +create_block_response = build( + data=cbr_data +) + +bc_error = error_item +bc_error.message = "Ec Block already exists" +bc_error.locations = [{"line": 3, "column": 3}] +bc_error.path = ["createBlock"] +bc_data = {"createBlock": null} + +block_creation_with_duplicate_name_response = build( + error=bc_error.build_error(bc_error), + data=bc_data +) + +cb_error = error_item +cb_error.message = "Office not found" +cb_error.locations = [{"line": 3, "column": 3}] +cb_error.path = ["createBlock"] +cb_data = {"createBlock": null} +create_block_with_non_existing_office_response = build( + cb_error.build_error(cb_error), + cb_data +) + +ub_data = {"updateBlock": {"block": {"name": "Block A", "id": "1"}}} +update_block_response = build( + data=ub_data +) + +db_data = {"DeleteBlock": {"block": {"name": "Ec", "id": "1"}}} +delete_block_response = build( + data=db_data +) + +dne_error = error_item +dne_error.message = "Block not found" +dne_error.locations = [{"line": 3, "column": 3}] +dne_error.path = ["DeleteBlock"] +dne_data = {"DeleteBlock": null} +delete_non_existent_block_response = build( + dne_error.build_error(dne_error), + dne_data +) + +une_error = error_item +une_error.message = "Block not found" +une_error.locations = [{"line": 3, "column": 3}] +une_error.path = ["updateBlock"] +une_data = {"updateBlock": null} +update_non_existent_block_response = build( + une_error.build_error(une_error), + une_data +) diff --git a/fixtures/channels/channel_fixtures.py b/fixtures/channels/channel_fixtures.py index 2424f1375..5f47cc900 100644 --- a/fixtures/channels/channel_fixtures.py +++ b/fixtures/channels/channel_fixtures.py @@ -1,5 +1,3 @@ -null = None - channels_query = ''' query { allChannels { @@ -10,22 +8,3 @@ } } ''' - -channels_response = { - "data": { - "allChannels": { - "channels": [ - { - "calendarId": "andela.com_3630363835303531343031" - "@resource.calendar.google.com", - "firebaseToken": null - }, - { - "calendarId": "andela.com_3730313534393638323232" - "@resource.calendar.google.com", - "firebaseToken": null - } - ] - } - } -} diff --git a/fixtures/channels/channel_responses_fixtures.py b/fixtures/channels/channel_responses_fixtures.py new file mode 100644 index 000000000..de839ca40 --- /dev/null +++ b/fixtures/channels/channel_responses_fixtures.py @@ -0,0 +1,20 @@ +null = None + +channels_response = { + "data": { + "allChannels": { + "channels": [ + { + "calendarId": "andela.com_3630363835303531343031" + "@resource.calendar.google.com", + "firebaseToken": null + }, + { + "calendarId": "andela.com_3730313534393638323232" + "@resource.calendar.google.com", + "firebaseToken": null + } + ] + } + } +} diff --git a/fixtures/devices/devices_fixtures.py b/fixtures/devices/devices_fixtures.py index 51bcc086a..c1e9bb38d 100644 --- a/fixtures/devices/devices_fixtures.py +++ b/fixtures/devices/devices_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None query_devices = ''' @@ -12,20 +15,6 @@ } ''' -expected_response_devices = { - "data": { - "allDevices": [ - { - "id": "1", - "lastSeen": "2018-06-08T11:17:58.785136", # noqa: E501 - "dateAdded": "2018-06-08T11:17:58.785136", # noqa: E501 - "name": "Samsung", - "location": "Kampala" - } - ] - } - } - query_devices_with_filter = ''' { allDevices(deviceLabels: "1st Floor"){ @@ -38,19 +27,6 @@ } ''' -expected_response_devices_with_filter = { - "data": { - "allDevices": [ - { - "dateAdded": "2018-06-08T11:17:58.785136", - "id": "1", - "lastSeen": "2018-06-08T11:17:58.785136", - "location": "Kampala", - "name": "Samsung" - } - ] - } - } query_device = ''' { @@ -64,18 +40,6 @@ } ''' -expected_response_device = { - "data": { - "specificDevice": { - "id": "1", - "lastSeen": "2018-06-08T11:17:58.785136", # noqa: E501 - "dateAdded": "2018-06-08T11:17:58.785136", # noqa: E501 - "name": "Samsung", - "location": "Kampala" - } - } - } - query_non_existent_device = ''' { specificDevice(deviceId: 10000){ @@ -87,26 +51,15 @@ } } ''' - -expected_error_non_existent_device_id = { - "errors": [ - { - "message": "Device not found", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "specificDevice" - ] - } - ], - "data": { - "specificDevice": null - } -} +een_error = error_item +een_error.message = "Device not found" +een_error.locations = [{"line": 3, "column": 9}] +een_error.path = ["specificDevice"] +een_data = {"specificDevice": null} +expected_error_non_existent_device_id = build( + error=een_error.build_error(een_error), + data=een_data +) create_devices_query = ''' mutation{ @@ -124,18 +77,6 @@ } ''' -expected_create_devices_response = { - "data": { - "createDevice": { - "device": { - "name": "Apple tablet", - "location": "Kampala", - "deviceType": "External Display" # noqa : E501 - } - } - } - } - create_device_non_existant_room_id = ''' mutation{ createDevice( @@ -151,27 +92,7 @@ } } ''' -expected_non_existant_room_response = ''' -{ - "errors": [ - { - "message": "Room not found", - "locations": [ - { - "line": 2, - "column": 13 - } - ], - "path": [ - "createDevice" - ] - } - ], - "data": { - "createDevice": null - } -} -''' + update_device_query = ''' mutation{ updateDevice( @@ -190,19 +111,6 @@ } ''' - -expected_update_device_response = { - "data": { - "updateDevice": { - "device": { - "name": "Apple tablet", - "location": "Kenya", - "deviceType": "External Display" - } - } - } -} - query_with_non_existant_id = ''' mutation{ updateDevice( @@ -233,16 +141,6 @@ } ''' -delete_device_response = { - "data": { - "deleteDevice": { - "device": { - "id": "1" - } - } - } -} - create_device_query_invalid_room = ''' mutation{ createDevice( @@ -259,7 +157,6 @@ } ''' -non_existant_id_response = "DeviceId not found" devices_query = '/mrm?query='+create_devices_query search_device_by_name = ''' @@ -281,15 +178,3 @@ } } ''' -search_non_existing_device_response = {'data': {'deviceByName': []}} - -search_device_by_name_expected_response = { - 'data': { - 'deviceByName': [{ - 'id': '1', - 'name': 'Samsung', - 'deviceType': 'External Display' - }] - } - } -devices_query_response = b'{"data":{"createDevice":{"device":{"name":"Apple tablet","location":"Kampala","deviceType":"External Display"}}}}' # noqaE501 diff --git a/fixtures/devices/devices_fixtures_responses.py b/fixtures/devices/devices_fixtures_responses.py new file mode 100644 index 000000000..8a9110f88 --- /dev/null +++ b/fixtures/devices/devices_fixtures_responses.py @@ -0,0 +1,110 @@ +expected_response_devices = { + "data": { + "allDevices": [ + { + "id": "1", + "lastSeen": "2018-06-08T11:17:58.785136", # noqa: E501 + "dateAdded": "2018-06-08T11:17:58.785136", # noqa: E501 + "name": "Samsung", + "location": "Kampala" + } + ] + } + } + +expected_response_device = { + "data": { + "specificDevice": { + "id": "1", + "lastSeen": "2018-06-08T11:17:58.785136", # noqa: E501 + "dateAdded": "2018-06-08T11:17:58.785136", # noqa: E501 + "name": "Samsung", + "location": "Kampala" + } + } + } + +expected_create_devices_response = { + "data": { + "createDevice": { + "device": { + "name": "Apple tablet", + "location": "Kampala", + "deviceType": "External Display" # noqa : E501 + } + } + } + } + +expected_non_existant_room_response = ''' +{ + "errors": [ + { + "message": "Room not found", + "locations": [ + { + "line": 2, + "column": 13 + } + ], + "path": [ + "createDevice" + ] + } + ], + "data": { + "createDevice": null + } +} +''' + +expected_update_device_response = { + "data": { + "updateDevice": { + "device": { + "name": "Apple tablet", + "location": "Kenya", + "deviceType": "External Display" + } + } + } +} + +delete_device_response = { + "data": { + "deleteDevice": { + "device": { + "id": "1" + } + } + } +} + +non_existant_id_response = "DeviceId not found" + +search_non_existing_device_response = {'data': {'deviceByName': []}} + +search_device_by_name_expected_response = { + 'data': { + 'deviceByName': [{ + 'id': '1', + 'name': 'Samsung', + 'deviceType': 'External Display' + }] + } +} +devices_query_response = b'{"data":{"createDevice":{"device":{"name":"Apple tablet","location":"Kampala","deviceType":"External Display"}}}}' # noqaE501 + +expected_response_devices_with_filter = { + "data": { + "allDevices": [ + { + "dateAdded": "2018-06-08T11:17:58.785136", + "id": "1", + "lastSeen": "2018-06-08T11:17:58.785136", + "location": "Kampala", + "name": "Samsung" + } + ] + } +} diff --git a/fixtures/events/end_event_fixtures.py b/fixtures/events/end_event_fixtures.py index ef48ee520..72db7d791 100644 --- a/fixtures/events/end_event_fixtures.py +++ b/fixtures/events/end_event_fixtures.py @@ -20,25 +20,6 @@ } ''' -end_event_mutation_response = { - "data": { - "endEvent": { - "event": { - "eventId": "test_id5", - "eventTitle": "Onboarding", - "checkedIn": True, - "cancelled": False, - "meetingEndTime": "2018-07-10T09:45:00Z", - "room": { - "id": "1", - "name": "Entebbe", - "calendarId": "andela.com_3630363835303531343031@resource.calendar.google.com" # noqa: E501 - } - } - } - } -} - end_unchecked_in_event_mutation = '''mutation { endEvent(calendarId:"andela.com_3630363835303531343031@resource.calendar.google.com", eventId:"test_id5", @@ -61,10 +42,6 @@ } ''' -end_unchecked_in_event_mutation_response = "Event yet to be checked in" - -end_event_twice_mutation_response = "Event has already ended" - wrong_calendar_id_end_event_mutation = '''mutation { endEvent(calendarId:"invalid_calendar_id", eventId:"test_id5", diff --git a/fixtures/events/end_event_responses_fixtures.py b/fixtures/events/end_event_responses_fixtures.py new file mode 100644 index 000000000..ae8deeac7 --- /dev/null +++ b/fixtures/events/end_event_responses_fixtures.py @@ -0,0 +1,22 @@ +end_event_mutation_response = { + "data": { + "endEvent": { + "event": { + "eventId": "test_id5", + "eventTitle": "Onboarding", + "checkedIn": True, + "cancelled": False, + "meetingEndTime": "2018-07-10T09:45:00Z", + "room": { + "id": "1", + "name": "Entebbe", + "calendarId": "andela.com_3630363835303531343031@resource.calendar.google.com" # noqa: E501 + } + } + } + } +} + +end_unchecked_in_event_mutation_response = "Event yet to be checked in" + +end_event_twice_mutation_response = "Event has already ended" diff --git a/fixtures/events/event_checkin_fixtures.py b/fixtures/events/event_checkin_fixtures.py index 00ebf16a7..557c4ad5e 100644 --- a/fixtures/events/event_checkin_fixtures.py +++ b/fixtures/events/event_checkin_fixtures.py @@ -20,24 +20,6 @@ } ''' -event_checkin_response = { - "data": { - "eventCheckin": { - "event": { - "eventId": "test_id5", - "roomId": 1, - "checkedIn": True, - "cancelled": False, - "room": { - "id": "1", - "name": "Entebbe", - "calendarId": "andela.com_3630363835303531343031@resource.calendar.google.com" # noqa - } - } - } - } -} - event_2_checkin_mutation = '''mutation { eventCheckin( calendarId:"andela.com_3730313534393638323232@resource.calendar.google.com", @@ -104,8 +86,6 @@ } ''' -cancel_event_respone = "Event cancelled but email not sent" - cancel_event_invalid_start_time = ''' mutation { cancelEvent( @@ -149,21 +129,3 @@ } } ''' - -response_for_event_existing_in_db_checkin = { - "data": { - "eventCheckin": { - "event": { - "eventId": "test_id5", - "roomId": 1, - "checkedIn": True, - "cancelled": False, - "room": { - "id": "1", - "name": "Entebbe", - "calendarId": "andela.com_3630363835303531343031@resource.calendar.google.com" # noqa - } - } - } - } -} diff --git a/fixtures/events/event_checkin_responses_fixtures.py b/fixtures/events/event_checkin_responses_fixtures.py new file mode 100644 index 000000000..2b666c616 --- /dev/null +++ b/fixtures/events/event_checkin_responses_fixtures.py @@ -0,0 +1,27 @@ +from ..output.OutputBuilder import build + +event_checkin_data = { + "eventCheckin": { + "event": { + "eventId": "test_id5", + "roomId": 1, + "checkedIn": True, + "cancelled": False, + "room": { + "id": "1", + "name": "Entebbe", + "calendarId": "andela.com_3630363835303531343031@resource.calendar.google.com" # noqa + } + } + } + } + +event_checkin_response = build( + data=event_checkin_data +) + +cancel_event_respone = "Event cancelled but email not sent" + +response_for_event_existing_in_db_checkin = build( + data=event_checkin_data +) diff --git a/fixtures/events/events_by_room_fixtures.py b/fixtures/events/events_by_room_fixtures.py index 91a8fa679..b69f1d914 100644 --- a/fixtures/events/events_by_room_fixtures.py +++ b/fixtures/events/events_by_room_fixtures.py @@ -14,21 +14,6 @@ ''' -query_all_events_by_room_with_dates_response = { - "data": { - "allEventsByRoom": { - "events": [ - { - "eventTitle": "Onboarding", - "roomId": 1, - "startTime": "2018-07-11T09:00:00Z", - "endTime": "2018-07-11T09:45:00Z", - } - ] - } - } -} - query_all_events_by_room_without_dates = ''' query{ allEventsByRoom(calendarId:"andela.com_3630363835303531343031@resource.calendar.google.com"){ @@ -43,21 +28,6 @@ ''' -query_all_events_by_room_without_dates_response = { - "data": { - "allEventsByRoom": { - "events": [ - { - "eventTitle": "Onboarding", - "roomId": 1, - "startTime": "2018-07-11T09:00:00Z", - "endTime": "2018-07-11T09:45:00Z", - } - ] - } - } -} - query_all_events_by_room_without_callendar_id = ''' query{ allEventsByRoom{ diff --git a/fixtures/events/events_by_room_responses_fixtures.py b/fixtures/events/events_by_room_responses_fixtures.py new file mode 100644 index 000000000..32c72c771 --- /dev/null +++ b/fixtures/events/events_by_room_responses_fixtures.py @@ -0,0 +1,29 @@ +query_all_events_by_room_with_dates_response = { + "data": { + "allEventsByRoom": { + "events": [ + { + "eventTitle": "Onboarding", + "roomId": 1, + "startTime": "2018-07-11T09:00:00Z", + "endTime": "2018-07-11T09:45:00Z", + } + ] + } + } +} + +query_all_events_by_room_without_dates_response = { + "data": { + "allEventsByRoom": { + "events": [ + { + "eventTitle": "Onboarding", + "roomId": 1, + "startTime": "2018-07-11T09:00:00Z", + "endTime": "2018-07-11T09:45:00Z", + } + ] + } + } +} diff --git a/fixtures/events/events_query_by_date_fixtures.py b/fixtures/events/events_query_by_date_fixtures.py index b545a1fad..61bae220b 100644 --- a/fixtures/events/events_query_by_date_fixtures.py +++ b/fixtures/events/events_query_by_date_fixtures.py @@ -47,24 +47,6 @@ } ''' -event_query_with_pagination_response = { - 'data': { - 'allEvents': { - 'events': [{ - 'id': '1', - 'roomId': 1, - 'room': { - 'name': 'Entebbe' - } - }], - 'hasNext': False, - 'hasPrevious': False, - 'pages': 1, - 'queryTotal': 1 - } - } -} - query_events_page_without_per_page = ''' query{ allEvents( @@ -199,24 +181,6 @@ } ''' -event_query_without_page_and_per_page_response = { - 'data': { - 'allEvents': { - 'events': [{ - 'id': '1', - 'roomId': 1, - 'room': { - 'name': 'Entebbe' - } - }], - 'hasNext': None, - 'hasPrevious': None, - 'pages': None, - 'queryTotal': None - } - } -} - query_events_without_start_and_end_date = ''' query{ allEvents(perPage: 1, page: 3){ diff --git a/fixtures/events/events_query_by_date_responses_fixtures.py b/fixtures/events/events_query_by_date_responses_fixtures.py new file mode 100644 index 000000000..f99ae1902 --- /dev/null +++ b/fixtures/events/events_query_by_date_responses_fixtures.py @@ -0,0 +1,35 @@ +event_query_with_pagination_response = { + 'data': { + 'allEvents': { + 'events': [{ + 'id': '1', + 'roomId': 1, + 'room': { + 'name': 'Entebbe' + } + }], + 'hasNext': False, + 'hasPrevious': False, + 'pages': 1, + 'queryTotal': 1 + } + } +} + +event_query_without_page_and_per_page_response = { + 'data': { + 'allEvents': { + 'events': [{ + 'id': '1', + 'roomId': 1, + 'room': { + 'name': 'Entebbe' + } + }], + 'hasNext': None, + 'hasPrevious': None, + 'pages': None, + 'queryTotal': None + } + } +} diff --git a/fixtures/events/events_ratios_fixtures.py b/fixtures/events/events_ratios_fixtures.py index bf53029be..5f428b98d 100644 --- a/fixtures/events/events_ratios_fixtures.py +++ b/fixtures/events/events_ratios_fixtures.py @@ -11,20 +11,6 @@ } ''' -event_ratio_response = { - "data": { - "analyticsRatios": { - "bookings": 1, - "checkins": 0, - "cancellations": 0, - "cancellationsPercentage": 0, - "checkinsPercentage": 0, - 'appBookings': 0, - 'appBookingsPercentage': 0 - } - } -} - event_ratio_for_one_day_query = '''query { analyticsRatios(startDate:"Jul 11 2018"){ bookings @@ -52,25 +38,6 @@ } }''' -event_ratio_per_room_response = { - 'data': { - 'analyticsRatiosPerRoom': { - 'ratios': [ - { - 'roomName': 'Entebbe', - 'bookings': 1, - 'checkins': 0, - 'checkinsPercentage': 0, - 'cancellations': 0, - 'cancellationsPercentage': 0, - 'appBookings': 0, - 'appBookingsPercentage': 0 - } - ] - } - } -} - event_ratio_percentage_cancellation_query = '''query { analyticsRatios(startDate:"Jul 10 2018", endDate:"Jul 29 2018"){ cancellationsPercentage @@ -78,14 +45,6 @@ } ''' -event_ratio_percentage_cancellation_response = { - "data": { - "analyticsRatios": { - "cancellationsPercentage": 33.33333333333333 - } - } -} - event_ratio_single_room_query = '''query{ analyticsRatiosPerRoom(startDate:"Mar 1 2019", endDate:"Mar 27 2019", roomId:1){ @@ -102,23 +61,6 @@ } }''' -event_ratio_single_room_response = { - "data": { - "analyticsRatiosPerRoom": { - "ratio": { - "roomName": "Entebbe", - "bookings": 0, - "checkins": 0, - "checkinsPercentage": 0.0, - "cancellations": 0, - "cancellationsPercentage": 0.0, - "appBookings": 0, - "appBookingsPercentage": 0.0 - } - } - } -} - event_ratio_single_room_query_with_non_existing_id = '''query{ analyticsRatiosPerRoom(startDate:"Mar 1 2019", endDate:"Mar 27 2019", roomId:5){ @@ -134,23 +76,3 @@ } } }''' - -event_ratio_single_room_with_non_existing_id_response = { - "errors": [ - { - "message": "Room not found", - "locations": [ - { - "line": 2, - "column": 5 - } - ], - "path": [ - "analyticsRatiosPerRoom" - ] - } - ], - "data": { - "analyticsRatiosPerRoom": None - } -} diff --git a/fixtures/events/events_ratios_responses_fixtures.py b/fixtures/events/events_ratios_responses_fixtures.py new file mode 100644 index 000000000..bb0e4aa72 --- /dev/null +++ b/fixtures/events/events_ratios_responses_fixtures.py @@ -0,0 +1,70 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +event_ratio_response = { + "data": { + "analyticsRatios": { + "bookings": 1, + "checkins": 0, + "cancellations": 0, + "cancellationsPercentage": 0, + "checkinsPercentage": 0, + 'appBookings': 0, + 'appBookingsPercentage': 0 + } + } +} + +event_ratio_per_room_response = { + 'data': { + 'analyticsRatiosPerRoom': { + 'ratios': [ + { + 'roomName': 'Entebbe', + 'bookings': 1, + 'checkins': 0, + 'checkinsPercentage': 0, + 'cancellations': 0, + 'cancellationsPercentage': 0, + 'appBookings': 0, + 'appBookingsPercentage': 0 + } + ] + } + } +} + +event_ratio_percentage_cancellation_response = { + "data": { + "analyticsRatios": { + "cancellationsPercentage": 33.33333333333333 + } + } +} + +event_ratio_single_room_response = { + "data": { + "analyticsRatiosPerRoom": { + "ratio": { + "roomName": "Entebbe", + "bookings": 0, + "checkins": 0, + "checkinsPercentage": 0.0, + "cancellations": 0, + "cancellationsPercentage": 0.0, + "appBookings": 0, + "appBookingsPercentage": 0.0 + } + } + } +} + +ers_error = error_item +ers_error.message = "Room not found" +ers_error.locations = [{'line': 2, 'column': 5}] +ers_error.path = ['analyticsRatiosPerRoom'] +ers_data = {'analyticsRatiosPerRoom': None} +event_ratio_single_room_with_non_existing_id_response = build( + ers_error.build_error(ers_error), + ers_data +) diff --git a/fixtures/events/sync_events_data_fixture.py b/fixtures/events/sync_events_data_fixture.py index 53ff1556a..eb61f3221 100644 --- a/fixtures/events/sync_events_data_fixture.py +++ b/fixtures/events/sync_events_data_fixture.py @@ -6,14 +6,6 @@ } """ -sync_data_response = { - "data": { - "syncEventData": { - "message": "success" - } - } -} - notification_mutation = """ mutation{ mrmNotification(calendarId: \ @@ -22,11 +14,3 @@ } } """ - -notification_response = { - "data": { - "mrmNotification": { - "message": "success" - } - } -} diff --git a/fixtures/events/sync_events_data_responses_fixture.py b/fixtures/events/sync_events_data_responses_fixture.py new file mode 100644 index 000000000..df7909d9e --- /dev/null +++ b/fixtures/events/sync_events_data_responses_fixture.py @@ -0,0 +1,15 @@ +sync_data_response = { + "data": { + "syncEventData": { + "message": "success" + } + } +} + +notification_response = { + "data": { + "mrmNotification": { + "message": "success" + } + } +} diff --git a/fixtures/location/all_locations_fixtures.py b/fixtures/location/all_locations_fixtures.py index 9ad244615..46d423d4e 100644 --- a/fixtures/location/all_locations_fixtures.py +++ b/fixtures/location/all_locations_fixtures.py @@ -100,17 +100,17 @@ expected_all_location_no_hierachy = { 'data': {'allLocations': [ {'rooms': [ - { - 'name': 'Entebbe', - 'roomType': 'meeting', - 'capacity': 6 - }, - { - 'name': 'Tana', - 'roomType': 'meeting', - 'capacity': 14 - }, - ]}, + { + 'name': 'Entebbe', + 'roomType': 'meeting', + 'capacity': 6 + }, + { + 'name': 'Tana', + 'roomType': 'meeting', + 'capacity': 14 + }, + ]}, {'rooms': []}, {'rooms': []} ] diff --git a/fixtures/location/rooms_in_location_fixtures.py b/fixtures/location/rooms_in_location_fixtures.py index 55ab82317..c1557a087 100644 --- a/fixtures/location/rooms_in_location_fixtures.py +++ b/fixtures/location/rooms_in_location_fixtures.py @@ -9,9 +9,7 @@ } ''' -expected_query_get_rooms_in_location = { -"data": { - "getRoomsInALocation": [ +rooms_sample = [ { "name": "Entebbe", "capacity": 6, @@ -25,5 +23,9 @@ "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 } ] + +expected_query_get_rooms_in_location = { + "data": { + "getRoomsInALocation": rooms_sample } } diff --git a/fixtures/location/update_location_fixtures.py b/fixtures/location/update_location_fixtures.py index 7aad85e61..f03b493d3 100644 --- a/fixtures/location/update_location_fixtures.py +++ b/fixtures/location/update_location_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None query_update_all_fields = '''mutation{ updateLocation(locationId: 1, name: "Kampala", country: "Kenya", abbreviation: "KE"){ # noqa: E501 @@ -36,20 +39,15 @@ } } ''' -expected_location_id_non_existant_query = { - "errors": [{ - "message": "Location not found", - "locations": [ - { - "line": 2, - "column": 3 - } - ], - "path": ["updateLocation"] - }], - "data": { - "updateLocation": null} -} +eli_error = error_item +eli_error.message = "Location not found" +eli_error.locations = [{"line": 2, "column": 3}] +eli_error.path = ["updateLocation"] +eli_data = {"updateLocation": null} +expected_location_id_non_existant_query = build( + error=eli_error.build_error(eli_error), + data=eli_data +) query_update_location_invalid_timezone = '''mutation { updateLocation( diff --git a/fixtures/office/office_fixtures.py b/fixtures/office/office_fixtures.py index d2f8ad6c3..33b3a442a 100644 --- a/fixtures/office/office_fixtures.py +++ b/fixtures/office/office_fixtures.py @@ -1,7 +1,6 @@ -null = None -office_mutation_query = ''' +office_mutation_sample_string = ''' mutation { - createOffice(name: "The Crest", locationId:1 ) { + createOffice(name: "%d", locationId:%s ) { office { name locationId @@ -13,10 +12,22 @@ } } ''' - -get_office_by_name = ''' +paginated_offices_sample_string = ''' +query { + allOffices(page:%d, perPage:%s){ + offices{ + name + id + } + hasNext + hasPrevious + pages + } +} +''' +get_office_by_name_sample_string = ''' query{ - getOfficeByName(name:"St. catherines"){ + getOfficeByName(name:"%s"){ name id blocks{ @@ -34,53 +45,22 @@ } ''' -get_office_by_name_response = { - 'data': { - 'getOfficeByName': [{ - 'name': 'St. catherines', - 'id': '1', - 'blocks': [{ - 'name': 'Ec', - 'floors': [{ - 'name': '3rd', - 'id': '4', - 'rooms': [{ - 'name': 'Entebbe', - 'id': '1'}] - }] - }] - }] - } -} -office_mutation_query_Different_Location = ''' - mutation { - createOffice(name: "The Crest", locationId:2 ) { - office { - name - locationId - blocks { - id - name - } - } - } - } -''' -office_mutation_query_non_existant_ID = ''' - mutation { - createOffice(name: "The Crest", locationId:10 ) { - office { - name - locationId - blocks { - id - name - } - } - } - } -''' +office_mutation_query = office_mutation_sample_string % ( + "The Crest", 1 +) + +get_office_by_name = get_office_by_name_sample_string % ( + "St. catherines" +) + +office_mutation_query_Different_Location = office_mutation_sample_string % ( + "The Crest", 2 +) + +office_mutation_query_non_existant_ID = office_mutation_sample_string % ( + "The Crest", 10 +) office_mutation_query_duplicate_name = ''' mutation { @@ -92,63 +72,9 @@ } ''' -office_mutation_query_duplicate_name_responce = { - "errors": [ - { - "message": "St. catherines Office already exists", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createOffice" - ] - } - ], - "data": { - "createOffice": null - } -} - - -paginated_offices_query = ''' -query { - allOffices(page:1, perPage:3){ - offices{ - name - id - } - hasNext - hasPrevious - pages - } -} -''' -offices_query_response = { - "data": { - "allOffices": { - "offices": [ - { - "name": "Dojo", - "id": "2" - }, - { - "name": "Epic tower", - "id": "3" - }, - { - "name": "St. catherines", - "id": "1" - } - ], - "hasNext": False, - "hasPrevious": False, - "pages": 1 - } - } -} +paginated_offices_query = paginated_offices_sample_string % ( + 1, 3 +) offices_query = ''' query { @@ -160,58 +86,11 @@ } } ''' -all_offices_query_response = { - "data": { - "allOffices": { - "offices": [ - { - "name": "Dojo", - "id": "2" - }, - { - "name": "Epic tower", - "id": "3" - }, - { - "name": "St. catherines", - "id": "1" - }, - ] - } - } -} -paginated_offices_non_existing_page_query = ''' -query { - allOffices(page:5, perPage:3){ - offices{ - name - id - } - hasNext - hasPrevious - pages - } -} -''' -office_mutation_query_response = {'data': {'createOffice': {'office': {'name': 'The Crest', 'locationId': 1, 'blocks': [{'id': '3', 'name': 'The Crest'}]}}}} # noqa +paginated_offices_non_existing_page_query = paginated_offices_sample_string % ( + 5, 3 +) -get_office_by_invalid_name = ''' -query{ - getOfficeByName(name:"No name"){ - name - id - blocks{ - name - floors{ - name - id - rooms{ - name - id - } - } - } - } - } -''' +get_office_by_invalid_name = get_office_by_name_sample_string % ( + "No name" +) diff --git a/fixtures/office/office_responses_fixtures.py b/fixtures/office/office_responses_fixtures.py new file mode 100644 index 000000000..4f24e41b2 --- /dev/null +++ b/fixtures/office/office_responses_fixtures.py @@ -0,0 +1,79 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +null = None +get_office_by_name_response = { + 'data': { + 'getOfficeByName': [{ + 'name': 'St. catherines', + 'id': '1', + 'blocks': [{ + 'name': 'Ec', + 'floors': [{ + 'name': '3rd', + 'id': '4', + 'rooms': [{ + 'name': 'Entebbe', + 'id': '1'}] + }] + }] + }] + } +} + +omq_error = error_item +omq_error.message = "St. catherines Office already exists" +omq_error.locations = [{"line": 3, "column": 9}] +omq_error.path = ["createOffice"] +omq_data = {"createOffice": null} +office_mutation_query_duplicate_name_responce = build( + omq_error.build_error(omq_error), + omq_data +) + +offices_query_response = { + "data": { + "allOffices": { + "offices": [ + { + "name": "Dojo", + "id": "2" + }, + { + "name": "Epic tower", + "id": "3" + }, + { + "name": "St. catherines", + "id": "1" + } + ], + "hasNext": False, + "hasPrevious": False, + "pages": 1 + } + } +} + +all_offices_query_response = { + "data": { + "allOffices": { + "offices": [ + { + "name": "Dojo", + "id": "2" + }, + { + "name": "Epic tower", + "id": "3" + }, + { + "name": "St. catherines", + "id": "1" + }, + ] + } + } +} + +office_mutation_query_response = {'data': {'createOffice': {'office': {'name': 'The Crest', 'locationId': 1, 'blocks': [{'id': '3', 'name': 'The Crest'}]}}}} # noqa diff --git a/fixtures/output/Error.py b/fixtures/output/Error.py new file mode 100644 index 000000000..04dae3da0 --- /dev/null +++ b/fixtures/output/Error.py @@ -0,0 +1,34 @@ +class Error: + """ + About: Builds an error object for fixtures test + How to use: import the error_item into the file + that needs an error object built. + After assigning the prefered values + for the error message, location and + path, call the build_error method and + passing the error_item. + (see docstring in build method) + """ + + def __init__(self, **kwargs): + self.message = kwargs.get('message') + self.locations = kwargs.get('locations') + self.path = kwargs.get('path') + + def build_error(self): + """Builds the error output + + Args: + self: This the the instance of the class + + Returns: + An error object of type dictionary + """ + return { + "message": self.message, + "locations": self.locations, + "path": self.path + } + + +error_item = Error diff --git a/fixtures/output/OutputBuilder.py b/fixtures/output/OutputBuilder.py new file mode 100644 index 000000000..7ecf0a98e --- /dev/null +++ b/fixtures/output/OutputBuilder.py @@ -0,0 +1,67 @@ +class OutputBuilder(): + """ + About: Builds fixture outputs for tests + How to use: import the build method and provide + the arguments that are required (see + docstring in build method) to build + the desired output. + """ + + def __init__(self): + self.errors = [] + self.data = {} + self.responses = {} + + @staticmethod + def item(): + return OutputBuilder() + + def in_errors(self, output): + self.errors.append(output) + return self + + def in_data(self, output): + self.data = output + return self + + def in_responses(self, output): + self.responses = output + return self + + def package(self): + """Packages the output object based on what is provided + + Args: + self: This the the instance of the class + Returns: + A packaged output object of type dictionary + """ + output_obj = { + "errors": self.errors, + "data": self.data, + "responses": self.responses + } + + if len(self.errors) == 1 and self.errors[0] is None: + del output_obj["errors"] + if self.data is None: + del output_obj["data"] + if self.responses is None: + del output_obj["responses"] + + return output_obj + + +def build(error=None, data=None, response=None): + """Builds the output that has been packaged by the package method + + Args: + error: This is a list of error dictionaries [optional] + data: A dictionary that forms part of the output object [optional] + response: A dictionary that forms part of the output object [optional] + + Returns: + A built output object of type dictionary + """ + return OutputBuilder.item().in_errors( + error).in_data(data).in_responses(response).package() diff --git a/fixtures/questions/create_questions_fixtures.py b/fixtures/questions/create_questions_fixtures.py index 7cd2927fd..59457f394 100644 --- a/fixtures/questions/create_questions_fixtures.py +++ b/fixtures/questions/create_questions_fixtures.py @@ -1,18 +1,6 @@ -import datetime - -start_date = ( - datetime.datetime.now().replace(microsecond=0) + datetime.timedelta(days=1) -).isoformat() -end_date = ( - datetime.datetime.now().replace(microsecond=0) + datetime.timedelta(days=2) -).isoformat() -wrong_start_date = ( - datetime.datetime.now().replace(microsecond=0) + datetime.timedelta(days=-1) -).isoformat() -wrong_end_date = ( - datetime.datetime.now().replace(microsecond=0) + datetime.timedelta(days=1) -).isoformat() - +from .questions_fixtures_helper import ( + start_date, end_date, wrong_start_date, wrong_end_date +) create_question_query = ''' mutation{{ @@ -32,27 +20,13 @@ '''.format(start_date, end_date) create_question_query_with_early_startDate = create_question_query.replace( - start_date, wrong_start_date + start_date, wrong_start_date ) create_question_query_with_early_endDate = create_question_query.replace( - end_date, wrong_end_date + end_date, wrong_end_date ) -create_question_response = { - "data": { - "createQuestion": { - "question": { - "id": "5", - "question": "How will you rate the cleanliness of the room", - "questionType": "rate", - "startDate": start_date.replace('T', ' '), - "endDate": end_date.replace('T', ' ') - } - } - } -} - question_mutation_query_without_name = ''' mutation{{ createQuestion(questionType:"", @@ -101,18 +75,6 @@ }} '''.format(start_date, end_date) -update_question_response = { - "data": { - "updateQuestion": { - "question": { - "id": "1", - "startDate": start_date.replace('T', ' '), - "endDate": end_date.replace('T', ' '), - } - } - } -} - update_question_invalidId = ''' mutation{ updateQuestion(questionId:100, @@ -151,16 +113,6 @@ } ''' -delete_question_response = { - "data": { - "deleteQuestion": { - "question": { - "id": "1" - } - } - } -} - delete_question_invalidId = ''' mutation{ deleteQuestion(questionId:100) { @@ -179,32 +131,6 @@ } } ''' -all_questions_response = { - "data": { - "allQuestions": [ - { - "question": "How will you rate the brightness of the room", - "id": "1", - "questionType": "rate" - }, - { - 'question': 'Is there anything missing in the room', - 'id': '2', - 'questionType': 'check' - }, - { - 'question': 'Any other suggestion', - 'id': '3', - 'questionType': 'input' - }, - { - 'question': 'Anything missing in the room?', - 'id': '4', - 'questionType': 'check' - } - ] - } -} query_update_total_views_of_questions = ''' mutation{ diff --git a/fixtures/questions/create_questions_responses_fixtures.py b/fixtures/questions/create_questions_responses_fixtures.py new file mode 100644 index 000000000..0237cf62e --- /dev/null +++ b/fixtures/questions/create_questions_responses_fixtures.py @@ -0,0 +1,66 @@ +from .questions_fixtures_helper import ( + start_date, end_date +) + +create_question_response = { + "data": { + "createQuestion": { + "question": { + "id": "5", + "question": "How will you rate the cleanliness of the room", + "questionType": "rate", + "startDate": start_date.replace('T', ' '), + "endDate": end_date.replace('T', ' ') + } + } + } +} + +update_question_response = { + "data": { + "updateQuestion": { + "question": { + "id": "1", + "startDate": start_date.replace('T', ' '), + "endDate": end_date.replace('T', ' '), + } + } + } +} + +delete_question_response = { + "data": { + "deleteQuestion": { + "question": { + "id": "1" + } + } + } +} + +all_questions_response = { + "data": { + "allQuestions": [ + { + "question": "How will you rate the brightness of the room", + "id": "1", + "questionType": "rate" + }, + { + 'question': 'Is there anything missing in the room', + 'id': '2', + 'questionType': 'check' + }, + { + 'question': 'Any other suggestion', + 'id': '3', + 'questionType': 'input' + }, + { + 'question': 'Anything missing in the room?', + 'id': '4', + 'questionType': 'check' + } + ] + } +} diff --git a/fixtures/questions/get_question_fixtures.py b/fixtures/questions/get_question_fixtures.py index f35e43de0..baa33be26 100644 --- a/fixtures/questions/get_question_fixtures.py +++ b/fixtures/questions/get_question_fixtures.py @@ -24,65 +24,6 @@ } ''' -all_questions_query_response = { - 'data': { - 'questions': { - 'questions': [{ - 'id': '1', - 'questionType': 'rate', - 'questionTitle': 'Rating Feedback', - 'question': 'How will you rate the brightness of the room', - 'startDate': '20 Nov 2018', - 'endDate': '28 Nov 2018', - 'questionResponseCount': 1, - 'response': [{ - 'id': '1', - 'questionId': 1, - 'roomId': 1 - }] - }, - { - 'id': '2', - 'questionType': 'check', - 'questionTitle': 'check Feedback', - 'question': 'Is there anything missing in the room', - 'startDate': '20 Nov 2018', - 'endDate': '30 Nov 2018', - 'questionResponseCount': 1, - 'response': [{ - 'id': '2', - 'questionId': 2, - 'roomId': 1 - }] - }, - { - 'id': '3', - 'questionType': 'input', - 'questionTitle': 'input Feedback', - 'question': 'Any other suggestion', - 'startDate': '20 Nov 2018', - 'endDate': '28 Nov 2018', - 'questionResponseCount': 0, - 'response': [] - }, - { - 'id': '4', - 'questionType': 'check', - 'questionTitle': 'Missing item', - 'question': 'Anything missing in the room?', - 'startDate': '20 Nov 2018', - 'endDate': '30 Nov 2018', - 'questionResponseCount': 1, - 'response': [{ - 'id': '3', - 'questionId': 4, - 'roomId': 2 - }] - }] - } - } -} - paginated_all_questions_query = ''' query { questions(page:1, perPage:2){ @@ -123,46 +64,6 @@ } ''' -paginated_all_questions_query_response = { - 'data': { - 'questions': { - 'questions': [{ - 'id': - '1', - 'questionType': - 'rate', - 'question': - 'How will you rate the brightness of the room', - 'startDate': - '20 Nov 2018', - 'endDate': - '28 Nov 2018', - 'questionResponseCount': - 1, - 'response': [{ - 'id': '1', - 'questionId': 1, - 'roomId': 1 - }] - }, - { - 'id': '2', - 'questionType': 'check', - 'question': - 'Is there anything missing in the room', - 'startDate': '20 Nov 2018', - 'endDate': '30 Nov 2018', - 'questionResponseCount': 1, - 'response': [{ - 'id': '2', - 'questionId': 2, - 'roomId': 1 - }] - }] - } - } -} - get_question_by_id_query = ''' query { question(id:1){ @@ -181,24 +82,6 @@ } ''' -get_question_by_id_query_response = { - 'data': { - 'question': { - 'id': '1', - 'questionType': 'rate', - 'question': 'How will you rate the brightness of the room', - 'startDate': '20 Nov 2018', - 'endDate': '28 Nov 2018', - 'questionResponseCount': 1, - 'response': [{ - 'id': '1', - 'questionId': 1, - 'roomId': 1 - }] - } - } -} - get_question_invalid_id_query = ''' query { question(id:122){ @@ -225,19 +108,6 @@ } ''' -get_all_questions_query_response = { - "data": { - "allQuestions": [ - { - "questionType": "rate" - }, - { - "questionType": "input" - } - ] - } -} - all_questions_higher_start_date_query = ''' query { allQuestions(startDate: "2018 Nov 28", endDate: "2018 Nov 20"){ @@ -253,22 +123,3 @@ } } ''' - -all_questions_query_no_date_range_response = { - "data": { - "allQuestions": [ - { - "questionType": "rate" - }, - { - "questionType": "check" - }, - { - "questionType": "input" - }, - { - "questionType": "check" - } - ] - } -} diff --git a/fixtures/questions/get_question_responses_fixtures.py b/fixtures/questions/get_question_responses_fixtures.py new file mode 100644 index 000000000..81a055f59 --- /dev/null +++ b/fixtures/questions/get_question_responses_fixtures.py @@ -0,0 +1,148 @@ +all_questions_query_response = { + 'data': { + 'questions': { + 'questions': [{ + 'id': '1', + 'questionType': 'rate', + 'questionTitle': 'Rating Feedback', + 'question': 'How will you rate the brightness of the room', + 'startDate': '20 Nov 2018', + 'endDate': '28 Nov 2018', + 'questionResponseCount': 1, + 'response': [{ + 'id': '1', + 'questionId': 1, + 'roomId': 1 + }] + }, + { + 'id': '2', + 'questionType': 'check', + 'questionTitle': 'check Feedback', + 'question': 'Is there anything missing in the room', + 'startDate': '20 Nov 2018', + 'endDate': '30 Nov 2018', + 'questionResponseCount': 1, + 'response': [{ + 'id': '2', + 'questionId': 2, + 'roomId': 1 + }] + }, + { + 'id': '3', + 'questionType': 'input', + 'questionTitle': 'input Feedback', + 'question': 'Any other suggestion', + 'startDate': '20 Nov 2018', + 'endDate': '28 Nov 2018', + 'questionResponseCount': 0, + 'response': [] + }, + { + 'id': '4', + 'questionType': 'check', + 'questionTitle': 'Missing item', + 'question': 'Anything missing in the room?', + 'startDate': '20 Nov 2018', + 'endDate': '30 Nov 2018', + 'questionResponseCount': 1, + 'response': [{ + 'id': '3', + 'questionId': 4, + 'roomId': 2 + }] + }] + } + } +} + +paginated_all_questions_query_response = { + 'data': { + 'questions': { + 'questions': [{ + 'id': + '1', + 'questionType': + 'rate', + 'question': + 'How will you rate the brightness of the room', + 'startDate': + '20 Nov 2018', + 'endDate': + '28 Nov 2018', + 'questionResponseCount': + 1, + 'response': [{ + 'id': '1', + 'questionId': 1, + 'roomId': 1 + }] + }, + { + 'id': '2', + 'questionType': 'check', + 'question': + 'Is there anything missing in the room', + 'startDate': '20 Nov 2018', + 'endDate': '30 Nov 2018', + 'questionResponseCount': 1, + 'response': [{ + 'id': '2', + 'questionId': 2, + 'roomId': 1 + }] + }] + } + } +} + +get_question_by_id_query_response = { + 'data': { + 'question': { + 'id': '1', + 'questionType': 'rate', + 'question': 'How will you rate the brightness of the room', + 'startDate': '20 Nov 2018', + 'endDate': '28 Nov 2018', + 'questionResponseCount': 1, + 'response': [{ + 'id': '1', + 'questionId': 1, + 'roomId': 1 + }] + } + } +} + +get_all_questions_query_response = { + "data": { + "allQuestions": [ + { + "questionType": "rate" + }, + { + "questionType": "input" + } + ] + } +} + +all_questions_query_no_date_range_response = { + "data": { + "allQuestions": [ + { + "questionType": "rate" + }, + { + "questionType": "check" + }, + { + "questionType": "input" + }, + { + "questionType": "check" + } + ] + } +} diff --git a/fixtures/questions/questions_fixtures_helper.py b/fixtures/questions/questions_fixtures_helper.py new file mode 100644 index 000000000..7d6edf859 --- /dev/null +++ b/fixtures/questions/questions_fixtures_helper.py @@ -0,0 +1,24 @@ +import datetime + + +def date_maker(offset): + """Takes in an offset value with unit days and + creates a datetime object which is offset by + the value provided + + Args: + offset: An integer representation of the number + of days to offset the datetime object + + Returns: A datetime object + """ + return ( + datetime.datetime.now().replace(microsecond=0) + + datetime.timedelta(days=offset) + ).isoformat() + + +start_date = date_maker(1) +end_date = date_maker(2) +wrong_start_date = date_maker(-1) +wrong_end_date = date_maker(1) diff --git a/fixtures/response/archive_response_fixtures.py b/fixtures/response/archive_response_fixtures.py index 8ecc39879..bc4c543d8 100644 --- a/fixtures/response/archive_response_fixtures.py +++ b/fixtures/response/archive_response_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None true = True @@ -39,26 +42,15 @@ } } ''' - -archive_unresolved_response_response = { - "errors": [ - { - "message": "The specified response does not exist or hasn't been resolved yet.", # noqa: E501 - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "archiveResolvedResponse" - ] - } - ], - "data": { - "archiveResolvedResponse": null - } -} +aur_error = error_item +aur_error.message = "The specified response does not exist or hasn't been resolved yet." # noqa: E501 +aur_error.locations = [{"line": 3, "column": 3}] +aur_error.path = ["archiveResolvedResponse"] +aur_data = {"archiveResolvedResponse": null} +archive_unresolved_response_response = build( + error=aur_error.build_error(aur_error), + data=aur_data +) archive_non_existing_response_mutation = ''' mutation{ @@ -72,26 +64,15 @@ } } ''' - -archive_non_existing_response_response = { - "errors": [ - { - "message": "The specified response does not exist or hasn't been resolved yet.", # noqa: E501 - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "archiveResolvedResponse" - ] - } - ], - "data": { - "archiveResolvedResponse": null - } -} +ane_error = error_item +ane_error.message = "The specified response does not exist or hasn't been resolved yet." # noqa: E501 +ane_error.locations = [{"line": 3, "column": 3}] +ane_error.path = ["archiveResolvedResponse"] +ane_data = {"archiveResolvedResponse": null} +archive_non_existing_response_response = build( + error=ane_error.build_error(ane_error), + data=ane_data +) filter_archived_responses_query = ''' { diff --git a/fixtures/response/room_all_resolved_response_fixture.py b/fixtures/response/room_all_resolved_response_fixture.py new file mode 100644 index 000000000..a2df45c0f --- /dev/null +++ b/fixtures/response/room_all_resolved_response_fixture.py @@ -0,0 +1,36 @@ +from ..output.OutputBuilder import build +from .room_search_response_fixture import room_response_data + +all_resolved_room_response_query = '''{ + allRoomResponses(resolved:true) { + responses { + roomName, + totalResponses, + response { + id, + response { + ... on Rate{ + rate + } + ... on SelectedOptions{ + options + } + ... on TextArea{ + suggestion + } + ... on MissingItems{ + missingItems{ + name + id + } + } + } + } + } + } +} +''' + +all_resolved_room_response_data = build( + data=room_response_data +) diff --git a/fixtures/response/room_filter_response_fixture.py b/fixtures/response/room_filter_response_fixture.py new file mode 100644 index 000000000..050f7c2fd --- /dev/null +++ b/fixtures/response/room_filter_response_fixture.py @@ -0,0 +1,49 @@ +filter_by_response_query = ''' +query{ + allRoomResponses(upperLimitCount: 3, lowerLimitCount: 0 ){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' + +filter_by_response_invalid_query = ''' +query{ + allRoomResponses(upperLimitCount: 2){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' + +filter_by_response_data = { + 'data': { + 'allRoomResponses': { + 'responses': [ + { + 'response': [ + { + 'id': 2, + }, + { + 'id': 1, + } + + ], + 'roomName': 'Entebbe', + 'totalResponses': 2, + } + ] + } + } +} diff --git a/fixtures/response/room_mark_response_fixture.py b/fixtures/response/room_mark_response_fixture.py new file mode 100644 index 000000000..8bf9d88ee --- /dev/null +++ b/fixtures/response/room_mark_response_fixture.py @@ -0,0 +1,216 @@ +from ..output.OutputBuilder import build + +mark_response_as_resolved_mutation = ''' + mutation{ + resolveRoomResponse(responseId:1){ + roomResponse{ + resolved + id + response{ + ... on Rate{ + rate + } + ... on TextArea{ + suggestion + } + ... on SelectedOptions{ + options + } + ... on MissingItems{ + missingItems{ + name + } + } + } + roomId + } + } +} +''' + +user_response_data_resolved = { + "resolveRoomResponse": { + "roomResponse": { + "resolved": True, + "id": 1, + "response": { + "rate": 1 + }, + "roomId": 1 + } + } +} + +mark_user_response_as_resolved_mutation_response = build( + data=user_response_data_resolved +) + +mark_response_as_resolved_mutation_with_an_invalid_response_id = ''' + mutation{ + resolveRoomResponse(responseId:4){ + roomResponse{ + resolved + id + response{ + ... on Rate{ + rate + } + ... on TextArea{ + suggestion + } + ... on SelectedOptions{ + options + } + ... on MissingItems{ + missingItems{ + name + } + } + } + roomId + } + } +} +''' + +mark_a_user_response_as_unresolved_mutation = ''' + mutation{ + resolveRoomResponse(responseId:2){ + roomResponse{ + resolved + id + roomId + } + } +} +''' + +mark_a_user_response_as_unresolved_mutation_response = { + "data": { + "resolveRoomResponse": { + "roomResponse": { + "resolved": False, + "id": 2, + "roomId": 1, + } + } + } +} + +mark_multiple_as_resolved_mutation = ''' + mutation{ + resolveMultipleResponses(responses:[1], resolved:true){ + handledResponses{ + responses{ + id + resolved + response{ + ... on Rate{ + rate + } + ... on TextArea{ + suggestion + } + ... on SelectedOptions{ + options + } + ... on MissingItems{ + missingItems{ + name + } + } + } + } + totalResponses + } + } +} +''' + +mark_multiple_response_data = { + "resolveMultipleResponses": { + "handledResponses": { + "responses": [ + { + "id": 1, + "resolved": True, + "response": { + "rate": 1 + } + } + ], + "totalResponses": 1 + } + } +} +mark_multiple_as_resolved_response = build( + data=mark_multiple_response_data +) + +mark_multiple_as_unresolved_mutation = ''' + mutation{ + resolveMultipleResponses(responses:[1], resolved:false){ + handledResponses{ + responses{ + id + resolved + response{ + ... on Rate{ + rate + } + ... on TextArea{ + suggestion + } + ... on SelectedOptions{ + options + } + ... on MissingItems{ + missingItems{ + name + } + } + } + } + totalResponses + } + } +} +''' + +mark_multiple_as_unresolved_response = { + "data": { + "resolveMultipleResponses": { + "handledResponses": { + "responses": [ + { + "id": 1, + "resolved": False, + "response": { + "rate": 1 + } + } + ], + "totalResponses": 1 + } + } + } +} + +mark_multiple_as_resolved_with_invalid_id = ''' + mutation{ + resolveMultipleResponses(responses:[36], resolved:true){ + handledResponses{ + responses{ + id + resolved + response{ + ... on TextArea{ + suggestion + } + } + } + totalResponses + } + } +} +''' diff --git a/fixtures/response/room_query_response_fixture.py b/fixtures/response/room_query_response_fixture.py new file mode 100644 index 000000000..ecf006ca1 --- /dev/null +++ b/fixtures/response/room_query_response_fixture.py @@ -0,0 +1,77 @@ +from .room_summary_response_fixture import response_sample + +query_paginated_responses_empty_page = ''' + query{ + allRoomResponses(page:5, perPage:2){ + responses { + roomName, + totalResponses, + response { + id, + response{ + ... on Rate{ + rate + } + ... on TextArea{ + suggestion + } + ... on SelectedOptions{ + options + } + ... on MissingItems{ + missingItems{ + name + } + } + } + } + } + hasNext + hasPrevious + pages +} +} +''' +query_paginated_responses_response = { + "data": { + "allRoomResponses": { + "responses": response_sample, + "hasNext": False, + "hasPrevious": False, + "pages": 1 + } + } +} + +query_paginated_responses = ''' + query{ + allRoomResponses(page:1, perPage:2){ + responses { + roomName, + totalResponses, + response { + id, + response { + ... on Rate{ + rate + } + ... on SelectedOptions{ + options + } + ... on TextArea{ + suggestion + } + ... on MissingItems{ + missingItems{ + name + } + } + } + } + } + hasNext + hasPrevious + pages +} +} +''' diff --git a/fixtures/response/room_response_fixture.py b/fixtures/response/room_response_fixture.py index d73de27c6..97ebf5152 100644 --- a/fixtures/response/room_response_fixture.py +++ b/fixtures/response/room_response_fixture.py @@ -241,618 +241,3 @@ } } ''' - -summary_room_response_query = '''{ - allRoomResponses { - responses { - roomName, - totalResponses, - response { - id, - response { - ... on Rate{ - rate - } - ... on SelectedOptions{ - options - } - ... on TextArea{ - suggestion - } - ... on MissingItems{ - missingItems{ - name - id - } - } - } - } - } - } -} -''' - -summary_room_response_data = { - "data": { - "allRoomResponses": { - "responses": [ - { - "roomName": "Entebbe", - "totalResponses": 2, - "response": [ - { - "id": 2, - "response": { - "options": [ - "marker pen", - "apple tv" - ] - } - }, - { - "id": 1, - "response": { - "rate": 1 - } - } - ] - } - ] - } - } -} - -all_resolved_room_response_query = '''{ - allRoomResponses(resolved:true) { - responses { - roomName, - totalResponses, - response { - id, - response { - ... on Rate{ - rate - } - ... on SelectedOptions{ - options - } - ... on TextArea{ - suggestion - } - ... on MissingItems{ - missingItems{ - name - id - } - } - } - } - } - } -} -''' - -all_resolved_room_response_data = { - "data": { - "allRoomResponses": { - "responses": [ - { - "roomName": "Entebbe", - "totalResponses": 1, - "response": [ - { - "id": 2, - "response": { - "options": [ - "marker pen", - "apple tv" - ] - } - } - ] - } - ] - } - } -} - -filter_by_response_query = ''' -query{ - allRoomResponses(upperLimitCount: 3, lowerLimitCount: 0 ){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -filter_by_response_invalid_query = ''' -query{ - allRoomResponses(upperLimitCount: 2){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -search_response_by_room_query = ''' - query{ - allRoomResponses(lowerLimitCount: 1, upperLimitCount: 3, room:"Entebbe"){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -search_response_by_room_beyond_limits_query = ''' -query{ - allRoomResponses(upperLimitCount: 7, lowerLimitCount: 5, room:"Entebbe"){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -search_response_by_room_invalid_room_query = ''' -query{ - allRoomResponses(upperLimitCount: 2, lowerLimitCount: 0, room:"Entebbes"){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -search_response_by_room_only = ''' -query{ - allRoomResponses(room:"Entebbe"){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -search_response_by_invalid_room = ''' -query{ - allRoomResponses(room:"Mubende"){ - responses{ - totalResponses - roomName - response{ - id - } - } - } -} -''' - -search_response_by_room_no_response = ''' -query{ - allRoomResponses(room:"Kampala"){ - responses{ - totalResponses - roomId - roomName - response{ - id - } - } - } -} -''' - -filter_by_response_data = { - 'data': { - 'allRoomResponses': { - 'responses': [ - { - 'response': [ - { - 'id': 2, - }, - { - 'id': 1, - } - - ], - 'roomName': 'Entebbe', - 'totalResponses': 2, - } - ] - } - } -} - -search_resolved_responses_by_room_name = ''' -query{ - allRoomResponses(room:"Entebbe", resolved:true){ - responses{ - totalResponses - roomName - response{ - id - response { - ... on Rate{ - rate - } - ... on SelectedOptions{ - options - } - ... on TextArea{ - suggestion - } - ... on MissingItems{ - missingItems{ - name - id - } - } - } - } - } - } -} -''' - -search_resolved_responses_by_room_name_data = { - "data": { - "allRoomResponses": { - "responses": [ - { - "roomName": "Entebbe", - "totalResponses": 1, - "response": [ - { - "id": 2, - "response": { - "options": [ - "marker pen", - "apple tv" - ] - } - } - ] - } - ] - } - } -} - -query_paginated_responses = ''' - query{ - allRoomResponses(page:1, perPage:2){ - responses { - roomName, - totalResponses, - response { - id, - response { - ... on Rate{ - rate - } - ... on SelectedOptions{ - options - } - ... on TextArea{ - suggestion - } - ... on MissingItems{ - missingItems{ - name - } - } - } - } - } - hasNext - hasPrevious - pages -} -} -''' - -query_paginated_responses_response = { - "data": { - "allRoomResponses": { - "responses": [ - { - "roomName": "Entebbe", - "totalResponses": 2, - "response": [ - { - "id": 2, - "response": { - "options": [ - "marker pen", - "apple tv" - ] - } - }, - { - "id": 1, - "response": { - "rate": 1 - } - } - ] - } - ], - "hasNext": False, - "hasPrevious": False, - "pages": 1 - } - } -} - -query_paginated_responses_empty_page = ''' - query{ - allRoomResponses(page:5, perPage:2){ - responses { - roomName, - totalResponses, - response { - id, - response{ - ... on Rate{ - rate - } - ... on TextArea{ - suggestion - } - ... on SelectedOptions{ - options - } - ... on MissingItems{ - missingItems{ - name - } - } - } - } - } - hasNext - hasPrevious - pages -} -} -''' - -mark_response_as_resolved_mutation = ''' - mutation{ - resolveRoomResponse(responseId:1){ - roomResponse{ - resolved - id - response{ - ... on Rate{ - rate - } - ... on TextArea{ - suggestion - } - ... on SelectedOptions{ - options - } - ... on MissingItems{ - missingItems{ - name - } - } - } - roomId - } - } -} -''' - -mark_user_response_as_resolved_mutation_response = { - "data": { - "resolveRoomResponse": { - "roomResponse": { - "resolved": True, - "id": 1, - "response": { - "rate": 1 - }, - "roomId": 1 - } - } - } -} - -mark_response_as_resolved_mutation_with_an_invalid_response_id = ''' - mutation{ - resolveRoomResponse(responseId:4){ - roomResponse{ - resolved - id - response{ - ... on Rate{ - rate - } - ... on TextArea{ - suggestion - } - ... on SelectedOptions{ - options - } - ... on MissingItems{ - missingItems{ - name - } - } - } - roomId - } - } -} -''' - -mark_a_user_response_as_unresolved_mutation = ''' - mutation{ - resolveRoomResponse(responseId:2){ - roomResponse{ - resolved - id - roomId - } - } -} -''' - -mark_a_user_response_as_unresolved_mutation_response = { - "data": { - "resolveRoomResponse": { - "roomResponse": { - "resolved": False, - "id": 2, - "roomId": 1, - } - } - } -} - -mark_multiple_as_resolved_mutation = ''' - mutation{ - resolveMultipleResponses(responses:[1], resolved:true){ - handledResponses{ - responses{ - id - resolved - response{ - ... on Rate{ - rate - } - ... on TextArea{ - suggestion - } - ... on SelectedOptions{ - options - } - ... on MissingItems{ - missingItems{ - name - } - } - } - } - totalResponses - } - } -} -''' - -mark_multiple_as_resolved_response = { - "data": { - "resolveMultipleResponses": { - "handledResponses": { - "responses": [ - { - "id": 1, - "resolved": True, - "response": { - "rate": 1 - } - } - ], - "totalResponses": 1 - } - } - } -} - -mark_multiple_as_unresolved_mutation = ''' - mutation{ - resolveMultipleResponses(responses:[1], resolved:false){ - handledResponses{ - responses{ - id - resolved - response{ - ... on Rate{ - rate - } - ... on TextArea{ - suggestion - } - ... on SelectedOptions{ - options - } - ... on MissingItems{ - missingItems{ - name - } - } - } - } - totalResponses - } - } -} -''' - -mark_multiple_as_unresolved_response = { - "data": { - "resolveMultipleResponses": { - "handledResponses": { - "responses": [ - { - "id": 1, - "resolved": False, - "response": { - "rate": 1 - } - } - ], - "totalResponses": 1 - } - } - } -} - -mark_multiple_as_resolved_with_invalid_id = ''' - mutation{ - resolveMultipleResponses(responses:[36], resolved:true){ - handledResponses{ - responses{ - id - resolved - response{ - ... on TextArea{ - suggestion - } - } - } - totalResponses - } - } -} -''' diff --git a/fixtures/response/room_search_response_fixture.py b/fixtures/response/room_search_response_fixture.py new file mode 100644 index 000000000..30dc7ff6b --- /dev/null +++ b/fixtures/response/room_search_response_fixture.py @@ -0,0 +1,143 @@ +from ..output.OutputBuilder import build + +room_response_data = { + "allRoomResponses": { + "responses": [ + { + "roomName": "Entebbe", + "totalResponses": 1, + "response": [ + { + "id": 2, + "response": { + "options": [ + "marker pen", + "apple tv" + ] + } + } + ] + } + ] + } +} + +search_resolved_responses_by_room_name_data = build( + data=room_response_data +) + + +search_resolved_responses_by_room_name = ''' +query{ + allRoomResponses(room:"Entebbe", resolved:true){ + responses{ + totalResponses + roomName + response{ + id + response { + ... on Rate{ + rate + } + ... on SelectedOptions{ + options + } + ... on TextArea{ + suggestion + } + ... on MissingItems{ + missingItems{ + name + id + } + } + } + } + } + } +} +''' + +search_response_by_room_no_response = ''' +query{ + allRoomResponses(room:"Kampala"){ + responses{ + totalResponses + roomId + roomName + response{ + id + } + } + } +} +''' + +search_response_by_invalid_room = ''' +query{ + allRoomResponses(room:"Mubende"){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' +search_response_by_room_invalid_room_query = ''' +query{ + allRoomResponses(upperLimitCount: 2, lowerLimitCount: 0, room:"Entebbes"){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' + +search_response_by_room_only = ''' +query{ + allRoomResponses(room:"Entebbe"){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' + +search_response_by_room_query = ''' + query{ + allRoomResponses(lowerLimitCount: 1, upperLimitCount: 3, room:"Entebbe"){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' + +search_response_by_room_beyond_limits_query = ''' +query{ + allRoomResponses(upperLimitCount: 7, lowerLimitCount: 5, room:"Entebbe"){ + responses{ + totalResponses + roomName + response{ + id + } + } + } +} +''' diff --git a/fixtures/response/room_summary_response_fixture.py b/fixtures/response/room_summary_response_fixture.py new file mode 100644 index 000000000..47b0bb344 --- /dev/null +++ b/fixtures/response/room_summary_response_fixture.py @@ -0,0 +1,61 @@ +summary_room_response_query = '''{ + allRoomResponses { + responses { + roomName, + totalResponses, + response { + id, + response { + ... on Rate{ + rate + } + ... on SelectedOptions{ + options + } + ... on TextArea{ + suggestion + } + ... on MissingItems{ + missingItems{ + name + id + } + } + } + } + } + } +} +''' + +response_sample = [ + { + "roomName": "Entebbe", + "totalResponses": 2, + "response": [ + { + "id": 2, + "response": { + "options": [ + "marker pen", + "apple tv" + ] + } + }, + { + "id": 1, + "response": { + "rate": 1 + } + } + ] + } +] + +summary_room_response_data = { + "data": { + "allRoomResponses": { + "responses": response_sample + } + } +} diff --git a/fixtures/response/user_response_check.py b/fixtures/response/user_response_check.py index 5e138ce6e..1958b926f 100644 --- a/fixtures/response/user_response_check.py +++ b/fixtures/response/user_response_check.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None check_non_existing_question = ''' @@ -29,25 +32,15 @@ } ''' -check_non_existing_question_response = { - "errors": [ - { - "message": "Response to question", - "locations": [ - { - "line": 2, - "column": 3 - } - ], - "path": [ - "createResponse" - ] - } - ], - "data": { - "createResponse": null - } -} +cne_error = error_item +cne_error.message = "Response to question" +cne_error.locations = [{"line": 2, "column": 3}] +cne_error.path = ["createResponse"] +cne_data = {"createResponse": null} +check_non_existing_question_response = build( + error=cne_error.build_error(cne_error), + data=cne_data +) check_with_non_existent_room = ''' mutation{ @@ -235,16 +228,12 @@ ''' -filter_question_by_invalid_room_response = { - "errors": [{ - "message": "This room doesn't exist or doesn't have feedback.", - "locations": [{ - "line": 3, - "column": 3 - }], - "path": ["getRoomResponse"] - }], - "data": { - "getRoomResponse": null - } -} +fqb_error = error_item +fqb_error.message = "This room doesn't exist or doesn't have feedback." +fqb_error.locations = [{"line": 3, "column": 3}] +fqb_error.path = ["getRoomResponse"] +fqb_data = {"getRoomResponse": null} +filter_question_by_invalid_room_response = build( + error=fqb_error.build_error(fqb_error), + data=fqb_data +) diff --git a/fixtures/response/user_response_fixtures.py b/fixtures/response/user_response_fixtures.py index e3bb99828..f90bd3db6 100644 --- a/fixtures/response/user_response_fixtures.py +++ b/fixtures/response/user_response_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None create_rate_query = ''' @@ -58,25 +61,15 @@ } ''' -rate_non_existing_question_response = { - "errors": [ - { - "message": "Question does not exist", - "locations": [ - { - "line": 2, - "column": 3 - } - ], - "path": [ - "createResponse" - ] - } - ], - "data": { - "createResponse": null - } -} +rne_error = error_item +rne_error.message = "Question does not exist" +rne_error.locations = [{"line": 2, "column": 3}] +rne_error.path = ["createResponse"] +rne_data = {"createResponse": null} +rate_non_existing_question_response = build( + error=rne_error.build_error(rne_error), + data=rne_data +) invalid_rating_number = ''' mutation{ @@ -107,25 +100,15 @@ } ''' -invalid_rating_number_response = { - "errors": [ - { - "message": "Please rate between 1 and 5", - "locations": [ - { - "line": 2, - "column": 3 - } - ], - "path": [ - "createResponse" - ] - } - ], - "data": { - "createResponse": null - } -} +irn_error = error_item +irn_error.message = "Please rate between 1 and 5" +irn_error.locations = [{"line": 2, "column": 3}] +irn_error.path = ["createResponse"] +irn_data = {"createResponse": null} +invalid_rating_number_response = build( + error=irn_error.build_error(irn_error), + data=irn_data +) rate_with_non_existent_room = ''' mutation{ @@ -156,22 +139,12 @@ } ''' -rate_with_non_existent_room_response = { - "errors": [ - { - "message": "Non-existent room id", - "locations": [ - { - "line": 2, - "column": 3 - } - ], - "path": [ - "createResponse" - ] - } - ], - "data": { - "createResponse": null - } -} +rwn_error = error_item +rwn_error.message = "Non-existent room id" +rwn_error.locations = [{"line": 2, "column": 3}] +rwn_error.path = ["createResponse"] +rwn_data = {"createResponse": null} +rate_with_non_existent_room_response = build( + error=rwn_error.build_error(rwn_error), + data=rwn_data +) diff --git a/fixtures/role/role_fixtures.py b/fixtures/role/role_fixtures.py index 913c3b604..24306d3ba 100644 --- a/fixtures/role/role_fixtures.py +++ b/fixtures/role/role_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None role_mutation_query = ''' @@ -20,25 +23,16 @@ } } -role_duplication_mutation_response = { - "errors": [ - { - "message": "DevOps Role already exists", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "createRole" - ] - } - ], - "data": { - "createRole": null - } -} +rdm_error = error_item +rdm_error.message = "DevOps Role already exists" +rdm_error.locations = [{"line": 3, "column": 3}] +rdm_error.path = ["createRole"] +rdm_data = {"createRole": null} +role_duplication_mutation_response = build( + error=rdm_error.build_error(rdm_error), + data=rdm_data +) + role_query = ''' query { diff --git a/fixtures/room/create_room_fixtures.py b/fixtures/room/create_room_fixtures.py index 7e6c13fc2..d80a1f495 100644 --- a/fixtures/room/create_room_fixtures.py +++ b/fixtures/room/create_room_fixtures.py @@ -1,94 +1,3 @@ -null = None - -room_mutation_query = ''' - mutation { - createRoom( - name: "Syne", - calendarId: "andela.com_3836323338323230343935@resource.calendar.google.com", # noqa: E501 - roomType: "Meeting", - capacity: 1, - locationId: 1, - roomTags: [1], - structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - imageUrl: "http://url.com", - roomLabels: ["Epic tower", "1st Floor"]) { - room { - name - roomType - capacity - locationId, - calendarId, - structureId, - imageUrl - roomTags { - name - color - } - roomLabels - } - } - } -''' - -room_mutation_query_response = {'data': {'createRoom': { - 'room': { - 'name': 'Syne', - 'roomType': 'Meeting', - 'capacity': 1, - 'locationId': 1, - 'calendarId': 'andela.com_3836323338323230343935@resource.calendar.google.com', # noqa: E501 - 'structureId': "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - 'imageUrl': 'http://url.com', - 'roomTags': [{'name': 'Block-B', 'color': 'green'}], - 'roomLabels': ['Epic tower', '1st Floor'] - } -} -} -} - -room_mutation_different_location_query = ''' - mutation { - createRoom( - name: "Syne", - calendarId: "andela.com_3836323338323230343935@resource.calendar.google.com", # noqa: E501 - roomType: "Meeting", - capacity: 1, - locationId: 2, - roomTags: [1], - structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - imageUrl: "http://url.com", - roomLabels: ["Epic tower", "1st Floor"]) { - room { - name - roomType - capacity - locationId, - calendarId, - structureId, - imageUrl - roomTags { - name - color - } - roomLabels - } - } - } -''' - -room_mutation_response = { - "data": { - "createRoom": { - "room": { - "name": "Mbarara", - "roomType": "Meeting", - "capacity": 4, - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - } - } -} - room_invalid_location_id_mutation = ''' mutation { createRoom( @@ -151,250 +60,3 @@ } } ''' - -room_invalid_calendar_id_mutation_query = ''' - mutation { - createRoom( - name: "Kigali", roomType: "Meeting", capacity: 6, locationId: 1, - structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - calendarId:"andela.com_38363233383232303439@resource.calendar.google.com", - imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", - roomLabels: ["Epic tower", "1st Floor"]) { # noqa: E501 - room { - name - } - } - } -''' - -room_invalid_calendar_id_mutation_response = { - "errors": [ - { - "message": "Room calendar Id is invalid", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createRoom" - ] - } - ], - "data": { - "createRoom": null - } -} - -rooms_query = ''' -query { - allRooms{ - rooms{ - name - capacity - roomType - imageUrl - roomTags { - name - color - } - } - } -} -''' - - -invalid_room_label_query = ''' -mutation { - createRoom( - name: "yaoundejsdcds", - roomType: "Meeting", - capacity: 4, - locationId: 3, - calendarId: "andela.com_3735303539313930363030@resource.calendar.google.com", - structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 - roomLabels: ["{'id': '1', 'value': 'Office 1'}"]) { - room { - id - name - roomType - capacity - locationId - imageUrl - } - } -} -''' - -non_existent_structure_room_label_query = ''' - mutation { -createRoom(name: "Djibouti", roomType: "Meeting", capacity: 4, locationId: 1, -structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", -calendarId:"andela.com_3334333830313238333634@resource.calendar.google.com", -imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 -roomLabels: ["Block Z", "10th Floor"]) { - room { - id - name - roomType - capacity - locationId - imageUrl - roomLabels - roomTags { - name - color - } - - } - } -} -''' - -db_rooms_query = ''' - { - rooms{ - name - capacity - roomType - imageUrl - } - } - ''' - -db_rooms_query_response = { - "data": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - }, - { - "name": "Tana", - "capacity": 14, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - ] - } -} - -query_rooms_response = { - "data": { - "allRooms": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "roomTags": [ - { - "name": "Block-B", - "color": "green" - } - ], - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - }, - { - "name": "Tana", - "capacity": 14, - "roomType": "meeting", - "roomTags": [ - { - "name": "Block-B", - "color": "green" - } - ], - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - ] - } - } -} - -room_mutation_query_duplicate_name = ''' - mutation { - createRoom( - name: "Entebbe", roomType: "Meeting", capacity: 4, locationId: 1, - calendarId:"andela.com_3836323338323230343935@resource.calendar.google.com", - structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", - roomLabels: ["Epic tower", "1st Floor"]) { # noqa: E501 - room { - id - name - roomType - capacity - locationId - structureId - imageUrl - roomTags { - name - description - } - } - } - } -''' - -room_mutation_query_duplicate_name_response = { - "errors": [ - { - "message": "Entebbe Room already exists", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createRoom" - ] - } - ], - "data": { - "createRoom": null - } -} - -room_duplicate_calender_id_mutation_query = ''' - mutation { - createRoom( - name: "Mbarara", roomType: "Meeting", capacity: 4, locationId: 1, - calendarId:"andela.com_3630363835303531343031@resource.calendar.google.com", - structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", - imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", - roomLabels: ["Epic tower", "1st Floor"]) { # noqa: E501 - room { - name - roomType - capacity - imageUrl - } - } - } -''' - -room_duplicate_calendar_id_mutation_response = { - "errors": [ - { - "message": "andela.com_3630363835303531343031@resource.calendar.google.com CalenderId already exists", # noqa: E501 - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createRoom" - ] - } - ], - "data": { - "createRoom": null - } -} diff --git a/fixtures/room/create_room_query_fixtures.py b/fixtures/room/create_room_query_fixtures.py new file mode 100644 index 000000000..6593e2e44 --- /dev/null +++ b/fixtures/room/create_room_query_fixtures.py @@ -0,0 +1,167 @@ +room_mutation_sample_string = ''' + mutation { + createRoom( + name: "Syne", + calendarId: "andela.com_3836323338323230343935@resource.calendar.google.com", # noqa: E501 + roomType: "Meeting", + capacity: 1, + locationId: %d, + roomTags: [1], + structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", + imageUrl: "http://url.com", + roomLabels: ["Epic tower", "1st Floor"]) { + room { + name + roomType + capacity + locationId, + calendarId, + structureId, + imageUrl + roomTags { + name + color + } + roomLabels + } + } + } +''' + +room_mutation_query = room_mutation_sample_string % (1) + +room_mutation_different_location_query = room_mutation_sample_string % (2) + +room_invalid_calendar_id_mutation_query = ''' + mutation { + createRoom( + name: "Kigali", roomType: "Meeting", capacity: 6, locationId: 1, + structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", + calendarId:"andela.com_38363233383232303439@resource.calendar.google.com", + imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", + roomLabels: ["Epic tower", "1st Floor"]) { # noqa: E501 + room { + name + } + } + } +''' + +rooms_query = ''' +query { + allRooms{ + rooms{ + name + capacity + roomType + imageUrl + roomTags { + name + color + } + } + } +} +''' + +invalid_room_label_query = ''' +mutation { + createRoom( + name: "yaoundejsdcds", + roomType: "Meeting", + capacity: 4, + locationId: 3, + calendarId: "andela.com_3735303539313930363030@resource.calendar.google.com", + structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", + imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 + roomLabels: ["{'id': '1', 'value': 'Office 1'}"]) { + room { + id + name + roomType + capacity + locationId + imageUrl + } + } +} +''' + +non_existent_structure_room_label_query = ''' + mutation { +createRoom(name: "Djibouti", roomType: "Meeting", capacity: 4, locationId: 1, +structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", +calendarId:"andela.com_3334333830313238333634@resource.calendar.google.com", +imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 +roomLabels: ["Block Z", "10th Floor"]) { + room { + id + name + roomType + capacity + locationId + imageUrl + roomLabels + roomTags { + name + color + } + + } + } +} +''' + +db_rooms_query = ''' + { + rooms{ + name + capacity + roomType + imageUrl + } + } + ''' + +room_mutation_query_duplicate_name = ''' + mutation { + createRoom( + name: "Entebbe", roomType: "Meeting", capacity: 4, locationId: 1, + calendarId:"andela.com_3836323338323230343935@resource.calendar.google.com", + structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", + imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", + roomLabels: ["Epic tower", "1st Floor"]) { # noqa: E501 + room { + id + name + roomType + capacity + locationId + structureId + imageUrl + roomTags { + name + description + } + } + } + } +''' + +room_duplicate_calender_id_mutation_query = ''' + mutation { + createRoom( + name: "Mbarara", roomType: "Meeting", capacity: 4, locationId: 1, + calendarId:"andela.com_3630363835303531343031@resource.calendar.google.com", + structureId: "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", + imageUrl: "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", + roomLabels: ["Epic tower", "1st Floor"]) { # noqa: E501 + room { + name + roomType + capacity + imageUrl + } + } + } +''' diff --git a/fixtures/room/create_room_responses_fixtures.py b/fixtures/room/create_room_responses_fixtures.py new file mode 100644 index 000000000..e655126d1 --- /dev/null +++ b/fixtures/room/create_room_responses_fixtures.py @@ -0,0 +1,115 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +null = None + +room_mutation_query_response = {'data': {'createRoom': { + 'room': { + 'name': 'Syne', + 'roomType': 'Meeting', + 'capacity': 1, + 'locationId': 1, + 'calendarId': 'andela.com_3836323338323230343935@resource.calendar.google.com', # noqa: E501 + 'structureId': "b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968", + 'imageUrl': 'http://url.com', + 'roomTags': [{'name': 'Block-B', 'color': 'green'}], + 'roomLabels': ['Epic tower', '1st Floor'] + } +} +} +} + +room_mutation_response = { + "data": { + "createRoom": { + "room": { + "name": "Mbarara", + "roomType": "Meeting", + "capacity": 4, + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + } + } + } +} + +ric_error = error_item +ric_error.message = "Room calendar Id is invalid" +ric_error.locations = [{'line': 3, 'column': 9}] +ric_error.path = ['createRoom'] +ric_data = {'createRoom': null} +room_invalid_calendar_id_mutation_response = build( + ric_error.build_error(ric_error), + ric_data +) +db_rooms_query_data = { + "rooms": [ + { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting", + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + }, + { + "name": "Tana", + "capacity": 14, + "roomType": "meeting", + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + } + ] + } +db_rooms_query_response = build( + data=db_rooms_query_data +) + +query_rooms_response = { + "data": { + "allRooms": { + "rooms": [ + { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting", + "roomTags": [ + { + "name": "Block-B", + "color": "green" + } + ], + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + }, + { + "name": "Tana", + "capacity": 14, + "roomType": "meeting", + "roomTags": [ + { + "name": "Block-B", + "color": "green" + } + ], + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + } + ] + } + } +} + +rmq_error = error_item +rmq_error.message = "Entebbe Room already exists" +rmq_error.locations = [{'line': 3, 'column': 9}] +rmq_error.path = ['createRoom'] +rmq_data = {'createRoom': null} +room_mutation_query_duplicate_name_response = build( + rmq_error.build_error(rmq_error), + rmq_data +) + +rdc_error = error_item +rdc_error.message = "andela.com_3630363835303531343031@resource.calendar.google.com CalenderId already exists" # noqa: E501 +rdc_error.locations = [{'line': 3, 'column': 9}] +rdc_error.path = ['createRoom'] +rdc_data = {'createRoom': null} +room_duplicate_calendar_id_mutation_response = build( + rdc_error.build_error(rdc_error), + rdc_data +) diff --git a/fixtures/room/daily_room_events_fixture.py b/fixtures/room/daily_room_events_fixture.py index 0d3c0e8ae..f058d86b1 100644 --- a/fixtures/room/daily_room_events_fixture.py +++ b/fixtures/room/daily_room_events_fixture.py @@ -32,27 +32,6 @@ } ''' -daily_room_events_response = { - "data": { - "analyticsForDailyRoomEvents": { - "DailyRoomEvents": [ - { - "day": "Wed Jul 11 2018", - "events": [ - { - 'endTime': '09:45:00', - 'eventSummary': 'Onboarding', - 'noOfParticipants': 4, - 'roomName': 'Entebbe', - 'startTime': '09:00:00' - } - ] - } - ] - } - } -} - paginated_daily_room_events_query = ''' query{ analyticsForDailyRoomEvents(startDate:"Jul 11 2018",page:1, perPage:1, @@ -92,38 +71,3 @@ hasPrevious } }''' # fetch for invalid page number(non-existing) - - -daily_paginated_room_events_response = { - "data": { - "analyticsForDailyRoomEvents": { - "DailyRoomEvents": [ - { - "day": "Wed Jul 11 2018", - "events": [ - { - "eventSummary": "Onboarding", - "startTime": "09:00:00", - "endTime": "09:45:00", - "roomName": "Entebbe", - "noOfParticipants": 4 - } - ] - } - ], - "pages": 1, - "hasNext": False, - "hasPrevious": False - } - } -} - -daily_events_wrong_date_format_response = {'errors': [ - { - 'message': "time data '10 jan 2019' does not match format '%b %d %Y'", - 'locations': [{'line': 3, 'column': 5}], - 'path': ['analyticsForDailyRoomEvents']}], - 'data': { - 'analyticsForDailyRoomEvents': None -} -} diff --git a/fixtures/room/daily_room_events_responses_fixture.py b/fixtures/room/daily_room_events_responses_fixture.py new file mode 100644 index 000000000..e8c6a0df5 --- /dev/null +++ b/fixtures/room/daily_room_events_responses_fixture.py @@ -0,0 +1,57 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +daily_room_events_response = { + "data": { + "analyticsForDailyRoomEvents": { + "DailyRoomEvents": [ + { + "day": "Wed Jul 11 2018", + "events": [ + { + 'endTime': '09:45:00', + 'eventSummary': 'Onboarding', + 'noOfParticipants': 4, + 'roomName': 'Entebbe', + 'startTime': '09:00:00' + } + ] + } + ] + } + } +} + +daily_paginated_room_events_response = { + "data": { + "analyticsForDailyRoomEvents": { + "DailyRoomEvents": [ + { + "day": "Wed Jul 11 2018", + "events": [ + { + "eventSummary": "Onboarding", + "startTime": "09:00:00", + "endTime": "09:45:00", + "roomName": "Entebbe", + "noOfParticipants": 4 + } + ] + } + ], + "pages": 1, + "hasNext": False, + "hasPrevious": False + } + } +} + +dew_error = error_item +dew_error.message = "time data '10 jan 2019' does not match format '%b %d %Y'" +dew_error.locations = [{'line': 3, 'column': 5}] +dew_error.path = ['analyticsForDailyRoomEvents'] +dew_data = {'analyticsForDailyRoomEvents': None} +daily_events_wrong_date_format_response = build( + dew_error.build_error(dew_error), + dew_data +) diff --git a/fixtures/room/delete_room_fixtures.py b/fixtures/room/delete_room_fixtures.py index d5b3edfdf..89f73496b 100644 --- a/fixtures/room/delete_room_fixtures.py +++ b/fixtures/room/delete_room_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None delete_room_query = ''' @@ -13,16 +16,16 @@ ''' expected_response_room_query = { - "data": { - "deleteRoom": { - "room": { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting" - } - } - } - } + "data": { + "deleteRoom": { + "room": { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting" + } + } + } +} delete_room_query_non_existant_room_id = ''' mutation{ @@ -36,19 +39,11 @@ } ''' -expected_response_non_existant_room_id = { - "errors": [ - { - "message": "RoomId not found", # noqa: E501 - "locations": [ - { - "line": 3, - "column": 21 - } - ] - } - ], - "data": { - "deleteRoom": null - } - } +ern_error = error_item +ern_error.message = "RoomId not found" +ern_error.locations = [{"line": 3, "column": 21}] +ern_data = {"deleteRoom": null} +expected_response_non_existant_room_id = build( + error=ern_error.build_error(ern_error), + data=ern_data +) diff --git a/fixtures/room/filter_room_fixtures.py b/fixtures/room/filter_room_fixtures.py index 370c4be51..09f918f61 100644 --- a/fixtures/room/filter_room_fixtures.py +++ b/fixtures/room/filter_room_fixtures.py @@ -9,20 +9,6 @@ } } ''' -filter_rooms_by_capacity_response = { - "data": { - "allRooms": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - ] - } - } -} filter_rooms_by_location = '''query { allRooms(location:"Kampala"){ rooms{ @@ -34,26 +20,6 @@ } } ''' -filter_rooms_by_location_response = { - "data": { - "allRooms": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - }, - { - "name": "Tana", - "capacity": 14, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - ] - } - } -} filter_rooms_by_wings_and_floors = ''' query { allRooms(roomLabels:"1st Floor, Wing A") { @@ -66,22 +32,6 @@ } ''' -filter_rooms_by_wings_and_floors_response = { - 'data': { - 'allRooms': { - 'rooms': [ - { - 'id': '1', - 'name': 'Entebbe', - 'roomLabels': [ - '1st Floor', - 'Wing A' - ] - } - ] - } - } -} filter_rooms_by_non_existent_room_label = ''' query { allRooms(roomLabels:"Random") { @@ -94,13 +44,6 @@ } ''' -filter_rooms_by_non_existent_room_label_response = { - 'data': { - 'allRooms': { - 'rooms': [] - } - } -} filter_rooms_by_location_capacity = '''query { allRooms(location:"Kampala",capacity:6){ rooms{ @@ -112,35 +55,6 @@ } } ''' -filter_rooms_by_location_capacity_response = { - "data": { - "allRooms": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - ] - } - } -} -filter_rooms_by_resources_capacity_response = { - "data": { - "allRooms": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 - } - ] - } - } -} - filter_rooms_by_tag = '''query { filterRoomsByTag(tagId: 1){ id @@ -166,26 +80,6 @@ } }''' -filter_rooms_by_invalid_tag_error_response = { - "errors": [ - { - "message": "No rooms found with this tag", - "locations": [ - { - "line": 2, - "column": 5 - } - ], - "path": [ - "filterRoomsByTag" - ] - } - ], - "data": { - "filterRoomsByTag": None - } -} - filter_rooms_by_room_labels = '''query { allRooms(roomLabels:"Wing A"){ rooms{ @@ -199,21 +93,6 @@ } ''' -filter_rooms_by_room_labels_response = { - "data": { - "allRooms": { - "rooms": [ - { - "name": "Entebbe", - "capacity": 6, - "roomType": "meeting", - "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 - "roomLabels": ["1st Floor", "Wing A"] - } - ] - } - } -} filter_rooms_by_location_room_labels = '''query { allRooms(roomLabels:"Wing A", location:"Kampala"){ rooms{ diff --git a/fixtures/room/filter_room_responses_fixtures.py b/fixtures/room/filter_room_responses_fixtures.py new file mode 100644 index 000000000..cc240b172 --- /dev/null +++ b/fixtures/room/filter_room_responses_fixtures.py @@ -0,0 +1,108 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item +from ..location.rooms_in_location_fixtures import rooms_sample + +filter_rooms_by_capacity_response = { + "data": { + "allRooms": { + "rooms": [ + { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting", + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + } + ] + } + } +} + +filter_rooms_by_location_data = { + "allRooms": { + "rooms": rooms_sample + } +} +filter_rooms_by_location_response = build( + data=filter_rooms_by_location_data +) + +filter_rooms_by_wings_and_floors_response = { + 'data': { + 'allRooms': { + 'rooms': [ + { + 'id': '1', + 'name': 'Entebbe', + 'roomLabels': [ + '1st Floor', + 'Wing A' + ] + } + ] + } + } +} + +filter_rooms_by_non_existent_room_label_response = { + 'data': { + 'allRooms': { + 'rooms': [] + } + } +} + +filter_rooms_by_location_capacity_response = { + "data": { + "allRooms": { + "rooms": [ + { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting", + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + } + ] + } + } +} + +filter_rooms_by_resources_capacity_response = { + "data": { + "allRooms": { + "rooms": [ + { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting", + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg" # noqa: E501 + } + ] + } + } +} + +frb_error = error_item +frb_error.message = "No rooms found with this tag" +frb_error.locations = [{'line': 2, 'column': 5}] +frb_error.path = ['filterRoomsByTag'] +frb_data = {'filterRoomsByTag': None} +filter_rooms_by_invalid_tag_error_response = build( + frb_error.build_error(frb_error), + frb_data +) + +filter_rooms_by_room_labels_response = { + "data": { + "allRooms": { + "rooms": [ + { + "name": "Entebbe", + "capacity": 6, + "roomType": "meeting", + "imageUrl": "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg", # noqa: E501 + "roomLabels": ["1st Floor", "Wing A"] + } + ] + } + } +} diff --git a/fixtures/room/query_room_fixtures.py b/fixtures/room/query_room_fixtures.py index d9467b9a4..6d71e1e44 100644 --- a/fixtures/room/query_room_fixtures.py +++ b/fixtures/room/query_room_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None all_remote_rooms_query = ''' @@ -131,38 +134,23 @@ } ''' -room_occupants_of_non_existant_calendar_id_response = { - "errors": [ - { - "message": "Invalid CalendarId", - "locations": [ - { - "line": 1, - "column": 2 - } - ] - } - ], - "data": { - "roomSchedule": null - } -} -room_schedule_of_non_existant_calendar_id_response = { - "errors": [ - { - "message": "Invalid CalendarId", - "locations": [ - { - "line": 1, - "column": 2 - } - ] - } - ], - "data": { - "roomSchedule": null - } -} +roo_error = error_item +roo_error.message = "Invalid CalendarId" +roo_error.locations = [{"line": 1, "column": 2}] +roo_data = {"roomSchedule": null} +room_occupants_of_non_existant_calendar_id_response = build( + error=roo_error.build_error(roo_error), + data=roo_data +) + +rso_error = error_item +rso_error.message = "Invalid CalendarId" +rso_error.locations = [{"line": 1, "column": 2}] +rso_data = {"roomSchedule": null} +room_schedule_of_non_existant_calendar_id_response = build( + error=rso_error.build_error(rso_error), + data=rso_data +) room_search_by_name = ''' { diff --git a/fixtures/room/room_analytics_bookings_count_fixtures.py b/fixtures/room/room_analytics_bookings_count_fixtures.py index 0e511e027..b49d149ed 100644 --- a/fixtures/room/room_analytics_bookings_count_fixtures.py +++ b/fixtures/room/room_analytics_bookings_count_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None get_bookings_count_daily = ''' @@ -66,20 +69,20 @@ ''' get_single_room_daily_count_response = { - "data": { - "bookingsAnalyticsCount": [ - { - "roomName": "Entebbe", - "period": "Jul 11 2018", - "bookings": 1 - }, - { - "roomName": "Entebbe", - "period": "Jul 12 2018", - "bookings": 0 - } - ] - } + "data": { + "bookingsAnalyticsCount": [ + { + "roomName": "Entebbe", + "period": "Jul 11 2018", + "bookings": 1 + }, + { + "roomName": "Entebbe", + "period": "Jul 12 2018", + "bookings": 0 + } + ] + } } non_existing_room_id_query = ''' @@ -93,22 +96,12 @@ } ''' -non_existing_room_id_response = { - "errors": [ - { - "message": "Room Id does not exist", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "bookingsAnalyticsCount" - ] - } - ], - "data": { - "bookingsAnalyticsCount": null - } -} +ner_error = error_item +ner_error.message = "Room Id does not exist" +ner_error.locations = [{"line": 3, "column": 3}] +ner_error.path = ["bookingsAnalyticsCount"] +ner_data = {"bookingsAnalyticsCount": null} +non_existing_room_id_response = build( + error=ner_error.build_error(ner_error), + data=ner_data +) diff --git a/fixtures/room/room_analytics_duration_fixtures.py b/fixtures/room/room_analytics_duration_fixtures.py index a835f6ec8..c9e9bfab6 100644 --- a/fixtures/room/room_analytics_duration_fixtures.py +++ b/fixtures/room/room_analytics_duration_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None true = True false = False @@ -84,7 +87,7 @@ "numberOfMeetings": 1 } ] - }]}}} + }]}}} get_paginated_meetings_total_duration_query = ''' query { @@ -106,26 +109,26 @@ ''' get_paginated_meetings_total_duration_response = { - "data": { - "analyticsForMeetingsDurations": { - "hasPrevious": false, - "hasNext": false, - "pages": 1, - "MeetingsDurationaAnalytics": [ - { - "roomName": "Entebbe", - "count": 1, - "totalDuration": 45, - "events": [ + "data": { + "analyticsForMeetingsDurations": { + "hasPrevious": false, + "hasNext": false, + "pages": 1, + "MeetingsDurationaAnalytics": [ + { + "roomName": "Entebbe", + "count": 1, + "totalDuration": 45, + "events": [ { "durationInMinutes": 45, "numberOfMeetings": 1 } ] + } + ] } - ] } - } } get_paginated_meetings_total_duration_query_invalid_page = ''' @@ -147,16 +150,12 @@ } ''' -get_paginated_meetings_total_duration_invalid_page_result = { - "errors": [{ - "message": "Page does not exist", - "locations": [{ - "line": 3, - "column": 5 - }], - "path": ["analyticsForMeetingsDurations"] - }], - "data": { - "analyticsForMeetingsDurations": null - } -} +gpm_error = error_item +gpm_error.message = "Page does not exist" +gpm_error.locations = [{"line": 3, "column": 5}] +gpm_error.path = ["analyticsForMeetingsDurations"] +gpm_data = {"analyticsForMeetingsDurations": null} +get_paginated_meetings_total_duration_invalid_page_result = build( + error=gpm_error.build_error(gpm_error), + data=gpm_data +) diff --git a/fixtures/room_resource/get_rooms_with_resource_fixtures.py b/fixtures/room_resource/get_rooms_with_resource_fixtures.py index b7210df5a..ddb8139a2 100644 --- a/fixtures/room_resource/get_rooms_with_resource_fixtures.py +++ b/fixtures/room_resource/get_rooms_with_resource_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + rooms_containing_resource_query = ''' query { roomsContainingResource(resourceId: 1) { @@ -33,22 +36,12 @@ } ''' -rooms_containing_non_existent_resource_expected_response = { - "errors": [ - { - "message": "Resource does not exist", - "locations": [ - { - "line": 3, - "column": 6 - } - ], - "path": [ - "roomsContainingResource" - ] - } - ], - "data": { - "roomsContainingResource": None - } -} +rcn_error = error_item +rcn_error.message = "Resource does not exist" +rcn_error.locations = [{"line": 3, "column": 6}] +rcn_error.path = ["roomsContainingResource"] +rcn_data = {"roomsContainingResource": None} +rooms_containing_non_existent_resource_expected_response = build( + error=rcn_error.build_error(rcn_error), + data=rcn_data +) diff --git a/fixtures/room_resource/resource_fixture.py b/fixtures/room_resource/resource_fixture.py index 007f3392c..73df8227c 100644 --- a/fixtures/room_resource/resource_fixture.py +++ b/fixtures/room_resource/resource_fixture.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None resource_query = ''' @@ -39,42 +42,22 @@ } } -none_existing_resource_response = { - "errors": [ - { - "message": "No Matching Resource", - "locations": [ - { - "line": 3, - "column": 13 - } - ], - "path": [ - "resourceByName" - ] - } - ], - "data": { - "resourceByName": null - } -} +ner_error = error_item +ner_error.message = "No Matching Resource" +ner_error.locations = [{"line": 3, "column": 13}] +ner_error.path = ["resourceByName"] +ner_data = {"resourceByName": null} +none_existing_resource_response = build( + error=ner_error.build_error(ner_error), + data=ner_data +) -search_blank_name_response = { - "errors": [ - { - "message": "Please input Resource Name", - "locations": [ - { - "line": 3, - "column": 13 - } - ], - "path": [ - "resourceByName" - ] - } - ], - "data": { - "resourceByName": null - } -} +sbn_error = error_item +sbn_error.message = "Please input Resource Name" +sbn_error.locations = [{"line": 3, "column": 13}] +sbn_error.path = ["resourceByName"] +sbn_data = {"resourceByName": null} +search_blank_name_response = build( + error=sbn_error.build_error(sbn_error), + data=sbn_data +) diff --git a/fixtures/room_resource/update_resource_fixtures.py b/fixtures/room_resource/update_resource_fixtures.py index aca2b4b8d..5dde5e36c 100644 --- a/fixtures/room_resource/update_resource_fixtures.py +++ b/fixtures/room_resource/update_resource_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None update_room_resource_query = ''' @@ -31,22 +34,14 @@ } ''' -expected_non_existant_resource_id_query = { - "errors": [ - { - "message": "ResourceId not Found", - "locations": [ - { - "line": 3, - "column": 25 - } - ] - } - ], - "data": { - "updateRoomResource": null - } -} +ene_error = error_item +ene_error.message = "ResourceId not Found" +ene_error.locations = [{"line": 3, "column": 25}] +ene_data = {"updateRoomResource": null} +expected_non_existant_resource_id_query = build( + error=ene_error.build_error(ene_error), + data=ene_data +) update_with_empty_field = ''' mutation{ @@ -58,20 +53,11 @@ } ''' -expected_response_empty_field = { - "errors": [ - { - "message": "name is required field", - "locations": [ - { - "line": 3, - "column": 25 - } - ] - } - ], - "data": { - "updateRoomResource": null - } - -} +ere_error = error_item +ere_error.message = "name is required field" +ere_error.locations = [{"line": 3, "column": 25}] +ere_data = {"updateRoomResource": null} +expected_response_empty_field = build( + error=ere_error.build_error(ere_error), + data=ere_data +) diff --git a/fixtures/structure/structures_fixtures.py b/fixtures/structure/structures_fixtures.py index 792074aca..81d10775a 100644 --- a/fixtures/structure/structures_fixtures.py +++ b/fixtures/structure/structures_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None structures_query = ''' @@ -64,25 +67,15 @@ } ''' -expected_error_non_existant_structure_id = { - "errors": [ - { - "message": "Structure not found", - "locations": [ - { - "line": 3, - "column": 7 - } - ], - "path": [ - "structureByStructureId" - ] - } - ], - "data": { - "structureByStructureId": null - } -} +een_error = error_item +een_error.message = "Structure not found" +een_error.locations = [{"line": 3, "column": 7}] +een_error.path = ["structureByStructureId"] +een_data = {"structureByStructureId": null} +expected_error_non_existant_structure_id = build( + error=een_error.build_error(een_error), + data=een_data +) structure_query_invalid_structure_id = ''' { @@ -94,22 +87,12 @@ } ''' -expected_error_invalid_structure_id = { - "errors": [ - { - "message": "Please input a valid structureId", - "locations": [ - { - "line": 3, - "column": 7 - } - ], - "path": [ - "structureByStructureId" - ] - } - ], - "data": { - "structureByStructureId": null - } -} +eei_error = error_item +eei_error.message = "Please input a valid structureId" +eei_error.locations = [{"line": 3, "column": 7}] +eei_error.path = ["structureByStructureId"] +eei_data = {"structureByStructureId": null} +expected_error_invalid_structure_id = build( + error=eei_error.build_error(eei_error), + data=eei_data +) diff --git a/fixtures/tags/create_tags_fixtures.py b/fixtures/tags/create_tags_fixtures.py index fe12b5c26..f7656294a 100644 --- a/fixtures/tags/create_tags_fixtures.py +++ b/fixtures/tags/create_tags_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None create_tag_query = ''' @@ -37,26 +40,15 @@ } ''' -create_duplicate_tag_response = { - "errors": [ - { - "message": "Block-B Tag already exists", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createTag" - ] - } - ], - "data": { - "createTag": null - } -} - +cdt_error = error_item +cdt_error.message = "Block-B Tag already exists" +cdt_error.locations = [{"line": 3, "column": 9}] +cdt_error.path = ["createTag"] +cdt_data = {"createTag": null} +create_duplicate_tag_response = build( + error=cdt_error.build_error(cdt_error), + data=cdt_data +) create_tag_with_missing_argument = ''' mutation { @@ -70,26 +62,15 @@ } ''' -create_tag_missing_args_response = { - "errors": [ - { - "message": "name is required field", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createTag" - ] - } - ], - "data": { - "createTag": null - } -} - +ctm_error = error_item +ctm_error.message = "name is required field" +ctm_error.locations = [{"line": 3, "column": 9}] +ctm_error.path = ["createTag"] +ctm_data = {"createTag": null} +create_tag_missing_args_response = build( + error=ctm_error.build_error(ctm_error), + data=ctm_data +) update_tag_mutation = ''' mutation { @@ -125,22 +106,12 @@ } }''' -update_non_existent_tag_response = { - "errors": [ - { - "message": "Tag not found", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "updateTag" - ] - } - ], - "data": { - "updateTag": null - } -} +une_error = error_item +une_error.message = "Tag not found" +une_error.locations = [{"line": 3, "column": 9}] +une_error.path = ["updateTag"] +une_data = {"updateTag": null} +update_non_existent_tag_response = build( + error=une_error.build_error(une_error), + data=une_data +) diff --git a/fixtures/user/add_user_fixture.py b/fixtures/user/add_user_fixture.py index a3e1ca2dc..3c4b0afdd 100644 --- a/fixtures/user/add_user_fixture.py +++ b/fixtures/user/add_user_fixture.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None non_Andela_email_mutation = ''' mutation { @@ -13,22 +16,12 @@ } ''' -non_Andela_email_mutation_response = { - "errors": [ - { - "message": "This email is not allowed", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "createUser" - ] - } - ], - "data": { - "createUser": null - } -} +nae_error = error_item +nae_error.message = "This email is not allowed" +nae_error.locations = [{"line": 3, "column": 3}] +nae_error.path = ["createUser"] +nae_data = {"createUser": null} +non_Andela_email_mutation_response = build( + error=nae_error.build_error(nae_error), + data=nae_data +) diff --git a/fixtures/user/user_fixture.py b/fixtures/user/user_fixture.py index ba617d307..dd5b58e8c 100644 --- a/fixtures/user/user_fixture.py +++ b/fixtures/user/user_fixture.py @@ -1,5 +1,44 @@ null = None +send_invitation_template = ''' +mutation{ + inviteToConverge(email: "%s"){ + email + + } +} +''' + +query_user_by_name_template = ''' + query{ + userByName(userName:"%s"){ + name + email + } + } +''' + +change_user_location_template = ''' + mutation { + changeUserLocation(email: "%s", locationId: %d) { + user { + name + location + } + } + } + ''' +set_user_location_template = ''' +mutation { + setUserLocation(locationId: %d){ + user{ + email + location + } + } +} +''' + user_mutation_query = ''' mutation { createUser(email: "mrm@andela.com" @@ -16,33 +55,6 @@ } ''' -user_mutation_response = { - "data": { - "createUser": { - "user": { - "email": "mrm@andela.com", - "name": "this user", - "picture": "www.andela.com/user", - "location": "Lagos" - } - } - } -} - -user_duplication_mutation_response = { - "errors": [{ - "message": "mrm@andela.com User email already exists", - "locations": [{ - "line": 3, - "column": 3 - }], - "path": ["createUser"] - }], - "data": { - "createUser": null - } -} - user_query = ''' query { users{ @@ -53,24 +65,6 @@ } ''' -user_query_response = { - "data": { - "users": { - "users": [ - { - "email": "mrm@andela.com", - }, - { - "email": "peter.adeoye@andela.com", - }, - { - "email": "peter.walugembe@andela.com", - }, - ] - } - } -} - paginated_users_query = ''' query { users(page:1, perPage:1){ @@ -83,20 +77,6 @@ } } ''' - -paginated_users_response = { - "data": { - "users": { - "users": [{ - "email": "peter.adeoye@andela.com" - }], - "hasNext": True, - "hasPrevious": False, - "pages": 3 - } - } -} - query_user_by_email = ''' query { user(email: "peter.walugembe@andela.com"){ @@ -105,14 +85,6 @@ } ''' -query_user_email_response = { - "data": { - "user": { - "email": "peter.walugembe@andela.com", - } - } -} - change_user_role_mutation = ''' mutation{ changeUserRole(email:"peter.walugembe@andela.com", roleId: 1){ @@ -139,8 +111,6 @@ } ''' -change_user_role_mutation_response = "Role changed but email not sent" - change_user_role_with_already_assigned_role_mutation = ''' mutation{ changeUserRole(email:"peter.walugembe@andela.com", roleId: 1){ @@ -154,8 +124,6 @@ } ''' -change_user_role_with_already_assigned_role_mutation_response = "This role is already assigned to this user" # noqa: E501 - change_user_role_to_non_existence_role_mutation = ''' mutation{ createUserRole(userId: 1, roleId: 10){ @@ -169,46 +137,17 @@ } ''' -change_user_role_to_non_existing_role_mutation_response = "Role id does not exist" # noqa: E501 +send_invitation_to_existent_user_query = send_invitation_template % ( + "peter.walugembe@andela.com" +) -send_invitation_to_existent_user_query = ''' -mutation{ - inviteToConverge(email: "peter.walugembe@andela.com"){ - email +send_invitation_to_nonexistent_user_query = send_invitation_template % ( + "beverly.kololi@andela.com" +) - } -} -''' - -send_invitation_to_nonexistent_user_query = ''' -mutation{ - inviteToConverge(email: "beverly.kololi@andela.com"){ - email - } -} -''' - -send_invitation_to_invalid_email = ''' -mutation{ - inviteToConverge(email: "peter.walugembe@gmail.com"){ - email - } -} -''' - -send_invitation_to_existent_user_response = { - "errors": [{ - "message": "User already joined Converge", - "locations": [{ - "line": 3, - "column": 5 - }], - "path": ["inviteToConverge"] - }], - "data": { - "inviteToConverge": null - } -} +send_invitation_to_invalid_email = send_invitation_template % ( + "peter.walugembe@gmail.com" +) get_users_by_location = ''' query{ @@ -242,18 +181,6 @@ } } ''' -get_user_by_role_reponse = { - 'data': { - 'users': { - 'users': [ - { - 'name': 'Peter Adeoye', - 'location': 'Lagos' - } - ] - } - } -} change_role_of_non_existing_user_mutation = ''' mutation{ @@ -289,225 +216,32 @@ } ''' -query_user_by_name = ''' - query{ - userByName(userName:"Peter Adeoye"){ - name - email - } - } -''' +query_user_by_name = query_user_by_name_template % ("Peter Adeoye") -query_user_by_name_response = { - 'data': { - 'userByName': [{ - 'name': 'Peter Adeoye', - 'email': 'peter.adeoye@andela.com' - }] - } -} +query_non_existing_user_by_name = query_user_by_name_template % ( + "unknown user" +) -query_non_existing_user_by_name = ''' - query{ - userByName(userName:"unknown user"){ - name - email - } - } -''' +change_user_location_invalid_user_mutation = change_user_location_template % ( + "someinvaliduser@andela.com", + 1 +) -query_non_existing_user_by_name_response = { - "errors": [ - { - "message": "User not found", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "userByName" - ] - } - ], - "data": { - "userByName": null - } -} +change_user_location_invalid_location_id_mutation = change_user_location_template % ( # noqa: E501 + "peter.walugembe@andela.com", + 90 +) -change_user_location_invalid_user_mutation = ''' - mutation { - changeUserLocation(email: "someinvaliduser@andela.com", locationId: 1) { - user { - name - location - } - } - } - ''' +change_user_location_to_same_location_mutation = change_user_location_template % ( # noqa: E501 + "peter.walugembe@andela.com", + 1 +) -change_user_location_invalid_user_response = { - "errors": [ - { - "message": "User not found", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "changeUserLocation" - ] - } - ], - "data": { - "changeUserLocation": null - } -} - -change_user_location_invalid_location_id_mutation = ''' - mutation { - changeUserLocation(email: "peter.walugembe@andela.com", locationId: 90) { - user { - name - location - } - } - } - ''' - -change_user_location_invalid_location_id_response = { - "errors": [ - { - "message": "the location supplied does not exist", - "locations": [ - { - "line": 3, - "column": 7 - } - ], - "path": [ - "changeUserLocation" - ] - } - ], - "data": { - "changeUserLocation": null - } -} +change_user_location_valid_input_mutation = change_user_location_template % ( + "peter.walugembe@andela.com", + 2 +) -change_user_location_to_same_location_mutation = ''' - mutation { - changeUserLocation(email: "peter.walugembe@andela.com", locationId: 1) { - user { - name - location - } - } - } - ''' +set_user_location_mutation = set_user_location_template % (2) -change_user_location_to_same_location_response = { - "errors": [ - { - "message": "user already in this location", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "changeUserLocation" - ] - } - ], - "data": { - "changeUserLocation": null - } -} - -change_user_location_valid_input_mutation = ''' - mutation { - changeUserLocation(email: "peter.walugembe@andela.com", locationId: 2) { - user { - name - location - } - } - } - ''' - -change_user_location_valid_input_response = { - "data": { - "changeUserLocation": { - "user": { - "name": "Peter Walugembe", - "location": "Nairobi" - } - } - } -} - -set_user_location_mutation = ''' -mutation { - setUserLocation(locationId: 2){ - user{ - email - location - } - } -} -''' -set_user_location_exists_mutation = ''' -mutation { - setUserLocation(locationId: 1){ - user{ - email - location - } - } -} -''' - -set_user_location_mutation_response = { - "errors": [ - { - "message": "This user already has a location set.", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "setUserLocation" - ] - } - ], - "data": { - "setUserLocation": None - } -} - -set_location_for_user_with_location_response = { - "errors": [ - { - "message": "This user already has a location set.", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "setUserLocation" - ] - } - ], - "data": { - "setUserLocation": None - } -} +set_user_location_exists_mutation = set_user_location_template % (1) diff --git a/fixtures/user/user_fixture_response.py b/fixtures/user/user_fixture_response.py new file mode 100644 index 000000000..eb2a655fc --- /dev/null +++ b/fixtures/user/user_fixture_response.py @@ -0,0 +1,175 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + +null = None + +user_mutation_response = { + "data": { + "createUser": { + "user": { + "email": "mrm@andela.com", + "name": "this user", + "picture": "www.andela.com/user", + "location": "Lagos" + } + } + } +} + +udm_error = error_item +udm_error.message = "mrm@andela.com User email already exists" +udm_error.locations = [{"line": 3, "column": 3}] +udm_error.path = ["createUser"] +udm_data = {"createUser": null} +user_duplication_mutation_response = build( + error=udm_error.build_error(udm_error), + data=udm_data +) + +user_query_response = { + "data": { + "users": { + "users": [ + { + "email": "mrm@andela.com", + }, + { + "email": "peter.adeoye@andela.com", + }, + { + "email": "peter.walugembe@andela.com", + }, + ] + } + } +} + +paginated_users_response = { + "data": { + "users": { + "users": [{ + "email": "peter.adeoye@andela.com" + }], + "hasNext": True, + "hasPrevious": False, + "pages": 3 + } + } +} + +query_user_email_response = { + "data": { + "user": { + "email": "peter.walugembe@andela.com", + } + } +} + +change_user_role_mutation_response = "Role changed but email not sent" + +change_user_role_with_already_assigned_role_mutation_response = "This role is already assigned to this user" # noqa: E501 + +change_user_role_to_non_existing_role_mutation_response = "Role id does not exist" # noqa: E501 + +sit_error = error_item +sit_error.message = "User already joined Converge" +sit_error.locations = [{"line": 3, "column": 5}] +sit_error.path = ["inviteToConverge"] +sit_data = {"inviteToConverge": null} +send_invitation_to_existent_user_response = build( + error=sit_error.build_error(sit_error), + data=sit_data +) + +get_user_by_role_reponse = { + 'data': { + 'users': { + 'users': [ + { + 'name': 'Peter Adeoye', + 'location': 'Lagos' + } + ] + } + } +} + +query_user_by_name_response = { + 'data': { + 'userByName': [{ + 'name': 'Peter Adeoye', + 'email': 'peter.adeoye@andela.com' + }] + } +} + +qne_error = error_item +qne_error.message = "User not found" +qne_error.locations = [{"line": 3, "column": 9}] +qne_error.path = ["userByName"] +qne_data = {"userByName": null} +query_non_existing_user_by_name_response = build( + error=qne_error.build_error(qne_error), + data=qne_data +) + +cul_error = error_item +cul_error.message = "User not found" +cul_error.locations = [{"line": 3, "column": 9}] +cul_error.path = ["changeUserLocation"] +cul_data = {"changeUserLocation": null} +change_user_location_invalid_user_response = build( + error=cul_error.build_error(cul_error), + data=cul_data +) + +culi_error = error_item +culi_error.message = "the location supplied does not exist" +culi_error.locations = [{"line": 3, "column": 9}] +culi_error.path = ["changeUserLocation"] +culi_data = {"changeUserLocation": null} +change_user_location_invalid_location_id_response = build( + error=culi_error.build_error(culi_error), + data=culi_data +) + +cult_error = error_item +cult_error.message = "user already in this location" +cult_error.locations = [{"line": 3, "column": 9}] +cult_error.path = ["changeUserLocation"] +cult_data = {"changeUserLocation": null} +change_user_location_to_same_location_response = build( + error=cult_error.build_error(cult_error), + data=cult_data +) + +change_user_location_valid_input_response = { + "data": { + "changeUserLocation": { + "user": { + "name": "Peter Walugembe", + "location": "Nairobi" + } + } + } +} + +sul_error = error_item +sul_error.message = "This user already has a location set." +sul_error.locations = [{"line": 3, "column": 3}] +sul_error.path = ["setUserLocation"] +sul_data = {"setUserLocation": null} +set_user_location_mutation_response = build( + error=sul_error.build_error(sul_error), + data=sul_data +) + +slf_error = error_item +slf_error.message = "This user already has a location set." +slf_error.locations = [{"line": 3, "column": 3}] +slf_error.path = ["setUserLocation"] +slf_data = {"setUserLocation": null} +set_location_for_user_with_location_response = build( + error=slf_error.build_error(slf_error), + data=slf_data +) diff --git a/fixtures/user_role/user_role_fixtures.py b/fixtures/user_role/user_role_fixtures.py index 469724267..b2fc1f533 100644 --- a/fixtures/user_role/user_role_fixtures.py +++ b/fixtures/user_role/user_role_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None user_role_mutation_query = ''' mutation{ @@ -151,25 +154,15 @@ } ''' -change_unavailable_user_role_mutation_response = { - "errors": [ - { - "message": "User not found", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "changeUserRole" - ] - } - ], - "data": { - "changeUserRole": null - } -} +cuu_error = error_item +cuu_error.message = "User not found" +cuu_error.locations = [{"line": 3, "column": 3}] +cuu_error.path = ["changeUserRole"] +cuu_data = {"changeUserRole": null} +change_unavailable_user_role_mutation_response = build( + error=cuu_error.build_error(cuu_error), + data=cuu_data +) assign_invalid_user_role_mutation = ''' mutation{ @@ -184,22 +177,12 @@ } ''' -assign_invalid_user_role_response = { - "errors": [ - { - "message": "invalid role id", - "locations": [ - { - "line": 3, - "column": 3 - } - ], - "path": [ - "changeUserRole" - ] - } - ], - "data": { - "changeUserRole": null - } -} +aiu_error = error_item +aiu_error.message = "invalid role id" +aiu_error.locations = [{"line": 3, "column": 3}] +aiu_error.path = ["changeUserRole"] +aiu_data = {"changeUserRole": null} +assign_invalid_user_role_response = build( + error=aiu_error.build_error(aiu_error), + data=aiu_data +) diff --git a/fixtures/wing/wing_fixtures.py b/fixtures/wing/wing_fixtures.py index 489936f9b..f167f9e07 100644 --- a/fixtures/wing/wing_fixtures.py +++ b/fixtures/wing/wing_fixtures.py @@ -1,3 +1,6 @@ +from ..output.OutputBuilder import build +from ..output.Error import error_item + null = None create_wing_mutation = ''' @@ -33,25 +36,15 @@ } ''' -duplicate_wing_mutation_response = { - "errors": [ - { - "message": "Naija Wing already exists", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createWing" - ] - } - ], - "data": { - "createWing": null - } -} +dwm_error = error_item +dwm_error.message = "Naija Wing already exists" +dwm_error.locations = [{"line": 3, "column": 9}] +dwm_error.path = ["createWing"] +dwm_data = {"createWing": null} +duplicate_wing_mutation_response = build( + error=dwm_error.build_error(dwm_error), + data=dwm_data +) wing_creation_no_name = ''' mutation { @@ -64,25 +57,15 @@ } ''' -wing_creation_no_name_response = { - "errors": [ - { - "message": "name is required field", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "createWing" - ] - } - ], - "data": { - "createWing": null - } -} +wcn_error = error_item +wcn_error.message = "name is required field" +wcn_error.locations = [{"line": 3, "column": 9}] +wcn_error.path = ["createWing"] +wcn_data = {"createWing": null} +wing_creation_no_name_response = build( + error=wcn_error.build_error(wcn_error), + data=wcn_data +) create_wing_other_location = ''' mutation { @@ -150,25 +133,15 @@ } ''' -update_duplicate_wing_mutation_response = { - "errors": [ - { - "message": "Naija Wing already exists", - "locations": [ - { - "line": 3, - "column": 9 - } - ], - "path": [ - "updateWing" - ] - } - ], - "data": { - "updateWing": null - } -} +udw_error = error_item +udw_error.message = "Naija Wing already exists" +udw_error.locations = [{"line": 3, "column": 9}] +udw_error.path = ["updateWing"] +udw_data = {"updateWing": null} +update_duplicate_wing_mutation_response = build( + error=udw_error.build_error(udw_error), + data=udw_data +) wing_update_no_name = ''' mutation { diff --git a/tests/test_analytics/test_all_analytics_query.py b/tests/test_analytics/test_all_analytics_query.py index 5e5cda620..ec4dd3cad 100644 --- a/tests/test_analytics/test_all_analytics_query.py +++ b/tests/test_analytics/test_all_analytics_query.py @@ -5,9 +5,12 @@ ) from fixtures.analytics.query_all_analytics_fixtures import ( all_analytics_query, - all_analytics_query_response, all_analytics_query_invalid_locationid, - analytics_query_for_date_ranges, + analytics_query_for_date_ranges +) + +from fixtures.analytics.analytics_query_responses import ( + all_analytics_query_response, all_analytics_query_response_super_admin_with_invalid_locationid ) diff --git a/tests/test_authentication/test_authentication.py b/tests/test_authentication/test_authentication.py index e2d33c8c8..82a0c7092 100644 --- a/tests/test_authentication/test_authentication.py +++ b/tests/test_authentication/test_authentication.py @@ -2,8 +2,9 @@ import sys from tests.base import BaseTestCase -from fixtures.room.create_room_fixtures import ( - room_mutation_query) +from fixtures.room.create_room_query_fixtures import ( + room_mutation_query +) sys.path.append(os.getcwd()) diff --git a/tests/test_channels/test_channels.py b/tests/test_channels/test_channels.py index d25a85236..a08207911 100644 --- a/tests/test_channels/test_channels.py +++ b/tests/test_channels/test_channels.py @@ -1,7 +1,10 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.channels.channel_fixtures import ( - channels_query, - channels_response) + channels_query +) +from fixtures.channels.channel_responses_fixtures import ( + channels_response +) class TestChannels(BaseTestCase): diff --git a/tests/test_devices/test_all_devices.py b/tests/test_devices/test_all_devices.py index 8197dcd6b..98ed68f74 100644 --- a/tests/test_devices/test_all_devices.py +++ b/tests/test_devices/test_all_devices.py @@ -1,7 +1,9 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.devices.devices_fixtures import ( query_devices, - query_devices_with_filter, + query_devices_with_filter +) +from fixtures.devices.devices_fixtures_responses import ( expected_response_devices, expected_response_devices_with_filter ) diff --git a/tests/test_devices/test_create_device.py b/tests/test_devices/test_create_device.py index 1a5e9177e..fb372263c 100644 --- a/tests/test_devices/test_create_device.py +++ b/tests/test_devices/test_create_device.py @@ -1,10 +1,11 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.devices.devices_fixtures import ( devices_query, - devices_query_response, create_device_query_invalid_room ) - +from fixtures.devices.devices_fixtures_responses import ( + devices_query_response +) from fixtures.token.token_fixture import ADMIN_TOKEN import sys diff --git a/tests/test_devices/test_delete_device.py b/tests/test_devices/test_delete_device.py index e091f79f1..85f8cd222 100644 --- a/tests/test_devices/test_delete_device.py +++ b/tests/test_devices/test_delete_device.py @@ -1,6 +1,8 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.devices.devices_fixtures import ( - delete_device_mutation, + delete_device_mutation +) +from fixtures.devices.devices_fixtures_responses import ( delete_device_response ) diff --git a/tests/test_devices/test_specific_device.py b/tests/test_devices/test_specific_device.py index 2af6c6e84..b4cb6f8c8 100644 --- a/tests/test_devices/test_specific_device.py +++ b/tests/test_devices/test_specific_device.py @@ -1,14 +1,14 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.devices.devices_fixtures import ( + search_device_by_name, + search_non_existing_device, query_device, - expected_response_device, query_non_existent_device, expected_error_non_existent_device_id ) -from fixtures.devices.devices_fixtures import ( - search_device_by_name, - search_non_existing_device, +from fixtures.devices.devices_fixtures_responses import ( search_device_by_name_expected_response, + expected_response_device, search_non_existing_device_response ) diff --git a/tests/test_events/test_end_event.py b/tests/test_events/test_end_event.py index 3c5db77d0..436ba6ba9 100644 --- a/tests/test_events/test_end_event.py +++ b/tests/test_events/test_end_event.py @@ -2,14 +2,18 @@ from fixtures.events.end_event_fixtures import ( end_event_mutation, - end_event_mutation_response, end_unchecked_in_event_mutation, - end_unchecked_in_event_mutation_response, - end_event_twice_mutation_response, wrong_calendar_id_end_event_mutation, ) +from fixtures.events.end_event_responses_fixtures import ( + end_event_mutation_response, + end_event_twice_mutation_response, + end_unchecked_in_event_mutation_response +) from fixtures.events.event_checkin_fixtures import ( - event_checkin_mutation, + event_checkin_mutation +) +from fixtures.events.event_checkin_responses_fixtures import ( event_checkin_response ) diff --git a/tests/test_events/test_event_checkin.py b/tests/test_events/test_event_checkin.py index 653130679..bfb19e945 100644 --- a/tests/test_events/test_event_checkin.py +++ b/tests/test_events/test_event_checkin.py @@ -5,12 +5,14 @@ from fixtures.events.event_checkin_fixtures import ( event_checkin_mutation, event_2_checkin_mutation, - event_checkin_response, wrong_calendar_id_checkin_mutation, cancel_event_mutation, - cancel_event_respone, cancel_event_invalid_start_time, - checkin_mutation_for_event_existing_in_db, + checkin_mutation_for_event_existing_in_db +) +from fixtures.events.event_checkin_responses_fixtures import ( + event_checkin_response, + cancel_event_respone, response_for_event_existing_in_db_checkin ) from helpers.calendar.calendar import get_events_mock_data diff --git a/tests/test_events/test_query_all_events_by_date.py b/tests/test_events/test_query_all_events_by_date.py index 807f1c638..e683f65c0 100644 --- a/tests/test_events/test_query_all_events_by_date.py +++ b/tests/test_events/test_query_all_events_by_date.py @@ -3,7 +3,6 @@ query_events, query_events_with_start_date_before_end_date, query_events_with_pagination, - event_query_with_pagination_response, query_events_page_without_per_page, query_events_per_page_without_page, query_events_invalid_page, @@ -11,7 +10,10 @@ query_events_without_start_date, query_events_without_end_date, query_events_without_start_and_end_date, - query_events_without_page_and_per_page, + query_events_without_page_and_per_page +) +from fixtures.events.events_query_by_date_responses_fixtures import ( + event_query_with_pagination_response, event_query_without_page_and_per_page_response ) diff --git a/tests/test_events/test_query_all_events_by_room.py b/tests/test_events/test_query_all_events_by_room.py index 5aa7a5905..05526e9e4 100644 --- a/tests/test_events/test_query_all_events_by_room.py +++ b/tests/test_events/test_query_all_events_by_room.py @@ -1,12 +1,13 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.events.events_by_room_fixtures import ( query_all_events_by_room_with_dates, - query_all_events_by_room_with_dates_response, query_all_events_by_room_with_invalid_calendar_id, query_all_events_by_room_without_callendar_id, - query_all_events_by_room_without_dates, + query_all_events_by_room_without_dates +) +from fixtures.events.events_by_room_responses_fixtures import ( + query_all_events_by_room_with_dates_response, query_all_events_by_room_without_dates_response - ) diff --git a/tests/test_events/test_sync_events_data.py b/tests/test_events/test_sync_events_data.py index a07074d15..87938b733 100644 --- a/tests/test_events/test_sync_events_data.py +++ b/tests/test_events/test_sync_events_data.py @@ -3,10 +3,12 @@ from helpers.calendar.calendar import get_events_mock_data from fixtures.events.sync_events_data_fixture import ( sync_data_mutation, - sync_data_response, - notification_response, notification_mutation ) +from fixtures.events.sync_events_data_responses_fixture import ( + sync_data_response, + notification_response +) @patch("helpers.calendar.events.get_google_calendar_events", diff --git a/tests/test_healthcheck/test_db.py b/tests/test_healthcheck/test_db.py index f234c2c5b..2f22c6222 100644 --- a/tests/test_healthcheck/test_db.py +++ b/tests/test_healthcheck/test_db.py @@ -2,9 +2,11 @@ from graphene.test import Client from healthcheck_schema import healthcheck_schema -from fixtures.room.create_room_fixtures import ( - db_rooms_query, - db_rooms_query_response, +from fixtures.room.create_room_query_fixtures import ( + db_rooms_query +) +from fixtures.room.create_room_responses_fixtures import ( + db_rooms_query_response ) diff --git a/tests/test_questions/test_create_question.py b/tests/test_questions/test_create_question.py index 80391fb75..fbfc09efe 100644 --- a/tests/test_questions/test_create_question.py +++ b/tests/test_questions/test_create_question.py @@ -3,12 +3,14 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.questions.create_questions_fixtures import ( create_question_query, - create_question_response, question_mutation_query_without_name, create_question_query_with_early_startDate, create_question_query_with_early_endDate, question_mutation_query_with_invalid_question_type ) +from fixtures.questions.create_questions_responses_fixtures import ( + create_question_response +) sys.path.append(os.getcwd()) diff --git a/tests/test_questions/test_delete_question.py b/tests/test_questions/test_delete_question.py index 0613ef21d..c1b849c89 100644 --- a/tests/test_questions/test_delete_question.py +++ b/tests/test_questions/test_delete_question.py @@ -3,9 +3,11 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.questions.create_questions_fixtures import ( delete_question_mutation, - delete_question_response, delete_question_invalidId ) +from fixtures.questions.create_questions_responses_fixtures import ( + delete_question_response +) sys.path.append(os.getcwd()) diff --git a/tests/test_questions/test_update_question.py b/tests/test_questions/test_update_question.py index 144fcc57f..fabb68ff6 100644 --- a/tests/test_questions/test_update_question.py +++ b/tests/test_questions/test_update_question.py @@ -2,11 +2,13 @@ import os from tests.base import BaseTestCase, CommonTestCases from fixtures.questions.create_questions_fixtures import ( - update_question_mutation, - update_question_response, - update_question_invalidId, - query_update_total_views_of_questions, - update_question_with_invalid_question_type + update_question_mutation, + update_question_invalidId, + query_update_total_views_of_questions, + update_question_with_invalid_question_type +) +from fixtures.questions.create_questions_responses_fixtures import ( + update_question_response ) diff --git a/tests/test_questions/test_view_question.py b/tests/test_questions/test_view_question.py index 511866c8c..fe08fc4f2 100644 --- a/tests/test_questions/test_view_question.py +++ b/tests/test_questions/test_view_question.py @@ -3,17 +3,19 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.questions.get_question_fixtures import ( all_questions_query, - all_questions_query_response, paginated_all_questions_query, - paginated_all_questions_query_response, get_question_by_id_query, - get_question_by_id_query_response, get_question_invalid_id_query, get_all_questions_query, - get_all_questions_query_response, paginated_questions_empty_page, all_questions_higher_start_date_query, - all_questions_query_no_date_range, + all_questions_query_no_date_range +) +from fixtures.questions.get_question_responses_fixtures import ( + all_questions_query_response, + paginated_all_questions_query_response, + get_question_by_id_query_response, + get_all_questions_query_response, all_questions_query_no_date_range_response ) diff --git a/tests/test_response/test_resolved_responses.py b/tests/test_response/test_resolved_responses.py index 88d57b119..5affb1f91 100644 --- a/tests/test_response/test_resolved_responses.py +++ b/tests/test_response/test_resolved_responses.py @@ -1,16 +1,22 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.response.room_response_fixture import ( get_resolved_room_responses_query, - get_resolved_room_responses_query_data, + get_resolved_room_responses_query_data +) +from fixtures.response.room_all_resolved_response_fixture import ( all_resolved_room_response_query, - all_resolved_room_response_data, - search_resolved_responses_by_room_name, - search_resolved_responses_by_room_name_data, + all_resolved_room_response_data +) +from fixtures.response.room_mark_response_fixture import ( mark_multiple_as_resolved_mutation, mark_multiple_as_unresolved_mutation, mark_multiple_as_resolved_with_invalid_id, mark_multiple_as_resolved_response, - mark_multiple_as_unresolved_response, + mark_multiple_as_unresolved_response +) +from fixtures.response.room_search_response_fixture import ( + search_resolved_responses_by_room_name, + search_resolved_responses_by_room_name_data ) diff --git a/tests/test_response/test_room_response.py b/tests/test_response/test_room_response.py index 53364549c..b114a3277 100644 --- a/tests/test_response/test_room_response.py +++ b/tests/test_response/test_room_response.py @@ -5,29 +5,39 @@ get_room_response_query, get_room_response_query_data, get_room_response_non_existence_room_id, + get_room_response_query_by_date, + get_room_response_query_by_date_and_limits, + get_room_response_query_by_date_data, + get_room_response_query_with_invalid_date, + get_room_response_query_with_higher_start_date +) +from fixtures.response.room_search_response_fixture import ( search_response_by_room_invalid_room_query, search_response_by_room_query, search_response_by_room_only, search_response_by_room_beyond_limits_query, - search_response_by_invalid_room, + search_response_by_invalid_room +) +from fixtures.response.room_summary_response_fixture import ( summary_room_response_query, - summary_room_response_data, + summary_room_response_data +) +from fixtures.response.room_filter_response_fixture import ( filter_by_response_query, filter_by_response_invalid_query, - filter_by_response_data, + filter_by_response_data +) +from fixtures.response.room_query_response_fixture import ( query_paginated_responses, query_paginated_responses_response, - query_paginated_responses_empty_page, + query_paginated_responses_empty_page +) +from fixtures.response.room_mark_response_fixture import ( mark_response_as_resolved_mutation, mark_user_response_as_resolved_mutation_response, mark_response_as_resolved_mutation_with_an_invalid_response_id, mark_a_user_response_as_unresolved_mutation, - mark_a_user_response_as_unresolved_mutation_response, - get_room_response_query_by_date, - get_room_response_query_by_date_and_limits, - get_room_response_query_by_date_data, - get_room_response_query_with_invalid_date, - get_room_response_query_with_higher_start_date + mark_a_user_response_as_unresolved_mutation_response ) sys.path.append(os.getcwd()) diff --git a/tests/test_rooms/test_create_room.py b/tests/test_rooms/test_create_room.py index 8fc74575a..95731bcc6 100644 --- a/tests/test_rooms/test_create_room.py +++ b/tests/test_rooms/test_create_room.py @@ -7,19 +7,24 @@ query_string, query_string_response ) from fixtures.room.create_room_fixtures import ( + room_name_empty_mutation, + room_invalid_location_id_mutation, + room_invalid_tag_mutation +) +from fixtures.room.create_room_query_fixtures import ( room_mutation_query, room_mutation_different_location_query, - room_name_empty_mutation, room_mutation_query_duplicate_name, - room_mutation_query_duplicate_name_response, room_invalid_calendar_id_mutation_query, room_duplicate_calender_id_mutation_query, - room_duplicate_calendar_id_mutation_response, - room_invalid_location_id_mutation, - room_invalid_tag_mutation, invalid_room_label_query, - non_existent_structure_room_label_query, - room_mutation_query_response) + non_existent_structure_room_label_query +) +from fixtures.room.create_room_responses_fixtures import ( + room_mutation_query_duplicate_name_response, + room_duplicate_calendar_id_mutation_response, + room_mutation_query_response +) from fixtures.token.token_fixture import ADMIN_TOKEN sys.path.append(os.getcwd()) diff --git a/tests/test_rooms/test_query_rooms.py b/tests/test_rooms/test_query_rooms.py index 17d3201fe..80d0f6cfb 100644 --- a/tests/test_rooms/test_query_rooms.py +++ b/tests/test_rooms/test_query_rooms.py @@ -3,9 +3,8 @@ from unittest.mock import patch from tests.base import BaseTestCase, CommonTestCases from helpers.calendar.calendar import get_calendar_list_mock_data -from fixtures.room.create_room_fixtures import ( - rooms_query, - query_rooms_response) +from fixtures.room.create_room_query_fixtures import rooms_query +from fixtures.room.create_room_responses_fixtures import query_rooms_response from fixtures.room.query_room_fixtures import ( paginated_rooms_query, paginated_rooms_response, diff --git a/tests/test_rooms/test_room_filter.py b/tests/test_rooms/test_room_filter.py index 980c2fdc5..60d278ee0 100644 --- a/tests/test_rooms/test_room_filter.py +++ b/tests/test_rooms/test_room_filter.py @@ -4,25 +4,27 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.room.filter_room_fixtures import ( filter_rooms_by_capacity, - filter_rooms_by_capacity_response, filter_rooms_by_location, - filter_rooms_by_location_response, filter_rooms_by_location_capacity, - filter_rooms_by_location_capacity_response, filter_rooms_by_wings_and_floors, - filter_rooms_by_wings_and_floors_response, filter_rooms_by_non_existent_room_label, - filter_rooms_by_non_existent_room_label_response, filter_rooms_by_room_labels, - filter_rooms_by_room_labels_response, filter_rooms_by_location_room_labels, filter_rooms_by_resource, filter_rooms_by_location_resource ) +from fixtures.room.filter_room_responses_fixtures import ( + filter_rooms_by_room_labels_response, + filter_rooms_by_non_existent_room_label_response, + filter_rooms_by_wings_and_floors_response, + filter_rooms_by_location_capacity_response, + filter_rooms_by_location_response, + filter_rooms_by_capacity_response +) from fixtures.room.assign_resource_fixture import ( assign_resource_mutation, assign_resource_mutation_response - ) +) sys.path.append(os.getcwd()) diff --git a/tests/test_user/test_change_user_location.py b/tests/test_user/test_change_user_location.py index dd0c860b0..2129e05e0 100644 --- a/tests/test_user/test_change_user_location.py +++ b/tests/test_user/test_change_user_location.py @@ -1,13 +1,15 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.user.user_fixture import ( change_user_location_valid_input_mutation, - change_user_location_valid_input_response, change_user_location_invalid_user_mutation, - change_user_location_invalid_user_response, change_user_location_invalid_location_id_mutation, + change_user_location_to_same_location_mutation +) +from fixtures.user.user_fixture_response import ( + change_user_location_to_same_location_response, change_user_location_invalid_location_id_response, - change_user_location_to_same_location_mutation, - change_user_location_to_same_location_response + change_user_location_invalid_user_response, + change_user_location_valid_input_response ) diff --git a/tests/test_user/test_change_user_role.py b/tests/test_user/test_change_user_role.py index 02b083444..34f8b7d21 100644 --- a/tests/test_user/test_change_user_role.py +++ b/tests/test_user/test_change_user_role.py @@ -1,14 +1,17 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.user.user_fixture import ( - change_user_role_mutation, change_user_role_mutation_response, + change_user_role_mutation, change_user_role_to_non_existence_role_mutation, - change_user_role_to_non_existing_role_mutation_response, change_role_of_non_existing_user_mutation, assign_role_to_non_existing_user_mutation, change_user_role_with_already_assigned_role_mutation, - change_user_role_with_already_assigned_role_mutation_response, change_user_role_to_super_admin_mutation ) +from fixtures.user.user_fixture_response import ( + change_user_role_mutation_response, + change_user_role_to_non_existing_role_mutation_response, + change_user_role_with_already_assigned_role_mutation_response +) from tests.base import change_user_role_to_super_admin import sys diff --git a/tests/test_user/test_create_user.py b/tests/test_user/test_create_user.py index f3270a777..d9f783cb2 100644 --- a/tests/test_user/test_create_user.py +++ b/tests/test_user/test_create_user.py @@ -1,6 +1,9 @@ from tests.base import BaseTestCase from fixtures.user.user_fixture import ( - user_mutation_query, user_mutation_response, + user_mutation_query +) +from fixtures.user.user_fixture_response import ( + user_mutation_response, user_duplication_mutation_response ) from fixtures.user.add_user_fixture import ( diff --git a/tests/test_user/test_invite_email.py b/tests/test_user/test_invite_email.py index e966f010f..94173952f 100644 --- a/tests/test_user/test_invite_email.py +++ b/tests/test_user/test_invite_email.py @@ -1,9 +1,12 @@ from tests.base import BaseTestCase, CommonTestCases +from fixtures.user.user_fixture_response import ( + send_invitation_to_existent_user_response +) from fixtures.user.user_fixture import ( send_invitation_to_existent_user_query, - send_invitation_to_existent_user_response, send_invitation_to_nonexistent_user_query, - send_invitation_to_invalid_email) + send_invitation_to_invalid_email +) class InviteUser(BaseTestCase): diff --git a/tests/test_user/test_query_user.py b/tests/test_user/test_query_user.py index 3361dcacc..f80b059a2 100644 --- a/tests/test_user/test_query_user.py +++ b/tests/test_user/test_query_user.py @@ -1,13 +1,18 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.user.user_fixture import ( - user_query, user_query_response, - query_user_by_email, query_user_email_response, - paginated_users_query, paginated_users_response, - get_users_by_location, get_users_by_location_and_role, - get_user_by_role_reponse, get_users_by_role, - filter_user_by_location, - query_user_by_name, query_user_by_name_response, - query_non_existing_user_by_name, query_non_existing_user_by_name_response + user_query, query_user_by_email, + paginated_users_query, get_users_by_location, + get_users_by_location_and_role, + get_users_by_role, filter_user_by_location, + query_user_by_name, query_non_existing_user_by_name +) +from fixtures.user.user_fixture_response import ( + user_query_response, + query_user_email_response, + paginated_users_response, + get_user_by_role_reponse, + query_user_by_name_response, + query_non_existing_user_by_name_response ) from helpers.database import db_session from api.user.models import User diff --git a/tests/test_user/test_set_user_location.py b/tests/test_user/test_set_user_location.py index 2b9906c9b..6a277bfb1 100644 --- a/tests/test_user/test_set_user_location.py +++ b/tests/test_user/test_set_user_location.py @@ -1,10 +1,11 @@ from tests.base import BaseTestCase, CommonTestCases from fixtures.user.user_fixture import ( set_user_location_mutation, - set_user_location_mutation_response, - set_user_location_exists_mutation, - set_location_for_user_with_location_response - + set_user_location_exists_mutation +) +from fixtures.user.user_fixture_response import ( + set_location_for_user_with_location_response, + set_user_location_mutation_response )