Skip to content

Commit

Permalink
test: fix all tests to work with ruby 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Jan 9, 2022
1 parent 565250a commit 8dca0bb
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 152 deletions.
21 changes: 3 additions & 18 deletions test/api/campuses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ def test_student_cannot_post_campuses
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(user_student),
username: user_student.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: auth_token(user_student), username: user_student.username)

post_json "/api/campuses", data_to_post
assert_equal 403, last_response.status
Expand Down Expand Up @@ -85,12 +80,7 @@ def test_student_cannot_put_campuses
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(user_student),
username: user_student.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: auth_token(user_student), username: user_student.username)

put_json "/api/campuses/#{data_to_put[:campus].id}", data_to_put
assert_equal 403, last_response.status
Expand Down Expand Up @@ -122,12 +112,7 @@ def test_student_delete_campus
campus = FactoryBot.create(:campus, mode: 'timetable')

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(user_student),
username: user_student.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: auth_token(user_student), username: user_student.username)

# perform the delete
delete_json "/api/campuses/#{campus.id}"
Expand Down
92 changes: 18 additions & 74 deletions test/api/csv_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ def test_download_csv_all_task_definitions_unit_with_incorrect_auth_token
unit_id_to_test = 'string'

# auth_token and username added to header
auth_data_to_header = {
auth_token: "wrong_token"
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: "wrong token", username: 'aadmin')

# perform the get
get "/api/csv/task_definitions?unit_id=#{unit_id_to_test}"
Expand Down Expand Up @@ -157,11 +153,7 @@ def test_csv_upload_all_task_definitions_unit_incorrect_auth_token
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: "wrong_token"
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: "wrong_token")

# perform the POST
post "/api/csv/task_definitions", data_to_post
Expand Down Expand Up @@ -365,13 +357,8 @@ def test_download_csv_all_students_in_unit_with_incorrect_auth_token

unit_id_to_test = '1'

# auth_token to header
auth_data_to_header = {
auth_token: 'wrong_token'
}

# auth_token and username added to header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: 'wrong_token')

# perform the get
get "/api/csv/units/#{unit_id_to_test}"
Expand Down Expand Up @@ -411,12 +398,7 @@ def test_csv_upload_all_students_in_unit
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(unit.main_convenor_user),
username: unit.main_convenor_user.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: auth_token(unit.main_convenor_user), username: unit.main_convenor_user.username)

# perform the POST
post "/api/csv/units/#{unit.id}", data_to_post
Expand All @@ -439,12 +421,8 @@ def test_csv_upload_all_students_in_unit_incorrect_auth_token
file: upload_file_csv('test_files/csv_test_files/COS10001-Students.csv')
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: "wrong_token"
}

add_auth_header_for(auth_data_to_header)
# auth_token and username added to header
add_auth_header_for(username: 'aadmin', auth_token: "wrong_token")

# perform the POST
post "/api/csv/units/#{unit.id}", data_to_post
Expand Down Expand Up @@ -499,12 +477,7 @@ def test_csv_upload_all_students_in_unit_incorrect_file_pdf
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(unit.main_convenor_user),
username: unit.main_convenor_user.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(user: unit.main_convenor_user)

# perform the POST
post "/api/csv/units/#{unit.id}", data_to_post
Expand All @@ -522,12 +495,7 @@ def test_csv_upload_all_students_in_unit_no_file
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(unit.main_convenor_user),
username: unit.main_convenor_user.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: auth_token(unit.main_convenor_user), username: unit.main_convenor_user.username)

# perform the POST
post "/api/csv/units/#{unit.id}", data_to_post
Expand Down Expand Up @@ -567,12 +535,7 @@ def test_csv_upload_students_un_enroll_in_unit
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: auth_token(unit.main_convenor_user),
username: unit.main_convenor_user.username
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: auth_token(unit.main_convenor_user), username: unit.main_convenor_user.username)

user_id_check = unit.projects.last.user_id

Expand All @@ -598,11 +561,7 @@ def test_csv_upload_students_un_enroll_in_unit_incorrect_auth_token
}

# auth_token and username added to header
auth_data_to_header = {
auth_token: 'wrong_token'
}

add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: "wrong_token")

# perform the POST to withdraw user from the unit
post "/api/csv/units/#{unit.id}/withdraw", data_to_post
Expand All @@ -620,8 +579,9 @@ def test_csv_upload_students_un_enroll_in_unit_incorrect_auth_token
#POST /api/csv/units/{id}/withdraw
def test_csv_upload_students_un_enroll_in_unit_empty_auth_token

unit = FactoryBot.create(:unit, code: 'COS10001', with_students: false, stream_count: 0)
unit.import_users_from_csv test_file_path 'csv_test_files/COS10001-Students.csv'
unit = FactoryBot.create(:unit, code: 'COS10001', with_students: false, stream_count: 0)
response = unit.import_users_from_csv test_file_path 'csv_test_files/COS10001-Students.csv'
assert_equal 1, unit.projects.count, response


unit_id_to_test = '1'
Expand Down Expand Up @@ -689,7 +649,7 @@ def test_csv_upload_students_un_enroll_in_unit_empty_unit_id
}

# auth_token and username added to header
add_auth_header_for(user: User.first)
add_auth_header_for(user: unit.main_convenor_user)

user_id_check = unit.projects.last.user_id

Expand Down Expand Up @@ -886,12 +846,8 @@ def test_download_csv_all_student_tasks_in_unit_with_incorrect_auth_token

unit_id_to_test = '1'

auth_data_to_header = {
auth_token: 'wrong_token'
}

# Add authentication token to header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: 'wrong_token')

# perform the get
get "/api/csv/units/#{unit_id_to_test}/task_completion"
Expand Down Expand Up @@ -993,12 +949,8 @@ def test_download_csv_stats_tutor_assessed_with_incorrect_auth_token

unit_id_to_test = '1'

auth_data_to_header = {
auth_token: 'wrong_token'
}

# Add authentication token to header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: 'wrong_token')

# perform the get
get "/api/csv/units/#{unit_id_to_test}/tutor_assessments"
Expand Down Expand Up @@ -1049,12 +1001,8 @@ def test_download_csv_all_users
#GET /api/csv/users
def test_download_csv_all_users_with_incorrect_auth_token

auth_data_to_header = {
auth_token: 'wrong_token'
}

# Add authentication token to header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: 'wrong_token')

# perform the get
get "/api/csv/users"
Expand Down Expand Up @@ -1109,12 +1057,8 @@ def test_csv_upload_users_incorrect_auth_token
file: upload_file_csv('test_files/csv_test_files/doubtfire_users.csv')
}

auth_data_to_header = {
auth_token: 'wrong_token'
}

# Add authentication token to header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: 'wrong_token')

# perform the POST to withdraw user from the unit
post "/api/csv/users", data_to_post
Expand Down
22 changes: 11 additions & 11 deletions test/api/groups_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_pdf_comment_on_group_task
post "/api/projects/#{project.id}/task_def_id/#{td.id}/comments", comment_data

assert_equal 201, last_response.status
assert File.exists?(TaskComment.last.attachment_path)
assert File.exist?(TaskComment.last.attachment_path)

td.destroy
group.destroy
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_create_group

# Add username and auth_token to Header
add_auth_header_for(user: unit.main_convenor_user)

# Try again as convenor
post "/api/units/#{unit.id}/group_sets/#{gs_response['id']}/groups/#{group_response['id']}/members", {project_id: project.id}

Expand All @@ -318,7 +318,7 @@ def test_group_student_count

def test_group_switch_tutorial
unit = FactoryBot.create :unit, group_sets: 1, groups: [{gs: 0, students: 0}]

gs = unit.group_sets.first
gs.update keep_groups_in_same_class: true, allow_students_to_manage_groups: true
group1 = gs.groups.first
Expand All @@ -330,15 +330,15 @@ def test_group_switch_tutorial
group1.add_member p2

tutorial = FactoryBot.create :tutorial, unit: unit, campus: nil

refute p1.enrolled_in? tutorial
refute p2.enrolled_in? tutorial

# Add username and auth_token to Header
add_auth_header_for(user: unit.main_convenor_user)

put "/api/units/#{unit.id}/group_sets/#{gs.id}/groups/#{group1.id}", { group: {tutorial_id: tutorial.id} }

assert 201, last_response.status

p1.reload
Expand All @@ -353,7 +353,7 @@ def test_group_switch_tutorial

def test_group_switch_tutorial_no_student_management
unit = FactoryBot.create :unit, group_sets: 1, groups: [{gs: 0, students: 0}]

gs = unit.group_sets.first
gs.update keep_groups_in_same_class: true, allow_students_to_manage_groups: false
group1 = gs.groups.first
Expand All @@ -365,10 +365,10 @@ def test_group_switch_tutorial_no_student_management
group1.add_member p2

tutorial = FactoryBot.create :tutorial, unit: unit, campus: nil

refute p1.enrolled_in? tutorial
refute p2.enrolled_in? tutorial

add_auth_header_for(user: unit.main_convenor_user)
put "/api/units/#{unit.id}/group_sets/#{gs.id}/groups/#{group1.id}", { group: {tutorial_id: tutorial.id} }

Expand All @@ -386,7 +386,7 @@ def test_group_switch_tutorial_no_student_management

def test_group_switch_tutorial_unenrolled_students
unit = FactoryBot.create :unit, group_sets: 1, groups: [{gs: 0, students: 0}]

gs = unit.group_sets.first
gs.update keep_groups_in_same_class: true, allow_students_to_manage_groups: false, capacity: 2
group1 = gs.groups.first
Expand All @@ -400,7 +400,7 @@ def test_group_switch_tutorial_unenrolled_students
assert group1.at_capacity?

tutorial = FactoryBot.create :tutorial, unit: unit, campus: nil

refute p1.enrolled_in? tutorial
refute p2.enrolled_in? tutorial

Expand Down
18 changes: 3 additions & 15 deletions test/api/tutorials_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,8 @@ def test_post_tutorial_with_incorrect_auth_token
tutorial: tutorial
}

auth_data_to_header = {
auth_token: 'Incorrect_Auth_Token'
}

# Add username and auth_token to Header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(auth_token: 'Incorrect_Auth_Token', username: 'aadmin')

# Number of tutorials before POST
number_of_tutorials = Tutorial.all.length
Expand Down Expand Up @@ -963,12 +959,8 @@ def test_put_tutorials_with_incorrect_auth_token
tutorial: tutorial
}

auth_data_to_header = {
auth_token: 'Incorrect auth token'
}

# Add username and auth_token to Header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: 'Incorrect auth token')

# perform the PUT with incorrect auth token
put_json "/api/tutorials/#{tutorial_old.id}", data_to_put
Expand Down Expand Up @@ -1239,12 +1231,8 @@ def test_delete_tutorials_with_incorrect_auth_token
# Create a dummy tutorial
tutorial = FactoryBot.create(:tutorial)

auth_data_to_header = {
auth_token: 'incorrect_auth_token'
}

# Add username and auth_token to Header
add_auth_header_for(auth_data_to_header)
add_auth_header_for(username: 'aadmin', auth_token: 'incorrect_auth_token')

# Number of tutorials before DELETE
number_of_tutorials = Tutorial.all.length
Expand Down
Loading

0 comments on commit 8dca0bb

Please sign in to comment.