<commit_before>require 'test_helper'

class TaskDefinitionTest < ActiveSupport::TestCase
  include Rack::Test::Methods
  include TestHelpers::AuthHelper
  include TestHelpers::JsonHelper

  def app
    Rails.application
  end

  def test_post_invalid_file_tasksheet
    test_unit = Unit.order('RANDOM()').first
    test_task_definition_id = test_unit.task_definitions.order('RANDOM()').first.id

    data_to_post = {
      file: 'rubbish_path',
      auth_token: <PASSWORD>
    }
    post_json "/api/units/#{test_unit.id}/task_definitions/#{test_task_definition_id}/task_sheet", data_to_post

    assert last_response_body.key?('error')
  end

  def test_post_tasksheet

    test_unit = Unit.where(:administrators == User.first).order('RANDOM()').first
    test_task_definition_id = test_unit.task_definitions.order('RANDOM()').first.id

    data_to_post = {
      file: Rack::Test::UploadedFile.new('test_files/submissions/00_question.pdf', 'application/pdf')
    }

    post "/api/units/#{test_unit.id}/task_definitions/#{test_task_definition_id}/task_sheet", with_auth_token(data_to_post)

    assert_equal 201, last_response.status
  end

  def test_post_task_resources
    test_unit = Unit.where(:administrators == User.first).order('RANDOM()').first
    tdid = test_unit.task_definitions.order('RANDOM()').first.id

    data_to_post = {
      file: Rack::Test::UploadedFile.new('test_files/2015-08-06-COS10001-acain.zip', 'application/zip')
    }
    post "/api/units/#{test_unit.id}/task_definitions/#{tdid}/task_resources", with_auth_token(data_to_post)

    if last_response.status == 403
      puts last_response_body
    end

    assert_equal 201, last_response.status
  end
end<commit_msg>TEST: Add additional assertions for task_definitions<commit_after>require 'test_helper'

class TaskDefinitionTest < ActiveSupport::TestCase
  include Rack::Test::Methods
  include TestHelpers::AuthHelper
  include TestHelpers::JsonHelper

  def app
    Rails.application
  end

  def test_post_invalid_file_tasksheet
    test_unit = Unit.order('RANDOM()').first
    test_task_definition_id = test_unit.task_definitions.order('RANDOM()').first.id

    data_to_post = {
      file: 'rubbish_path',
      auth_token: <PASSWORD>
    }
    post_json "/api/units/#{test_unit.id}/task_definitions/#{test_task_definition_id}/task_sheet", data_to_post

    assert last_response_body.key?('error')
  end

  def test_post_tasksheet
    test_unit = Unit.first
    test_task_definition = TaskDefinition.first

    data_to_post = {
      file: Rack::Test::UploadedFile.new('test_files/submissions/00_question.pdf', 'application/pdf')
    }

    post "/api/units/#{test_unit.id}/task_definitions/#{test_task_definition.id}/task_sheet", with_auth_token(data_to_post)

    assert_equal 201, last_response.status
    assert test_task_definition.task_sheet

    assert_equal File.size('test_files/submissions/00_question.pdf'), File.size(TaskDefinition.first.task_sheet)
  end

  def test_post_task_resources
    test_unit_id = Unit.first.id
    test_task_definition_id = TaskDefinition.first.id

    data_to_post = {
      file: Rack::Test::UploadedFile.new('test_files/2015-08-06-COS10001-acain.zip', 'application/zip')
    }
    post "/api/units/#{test_unit_id}/task_definitions/#{test_task_definition_id}/task_resources", with_auth_token(data_to_post)

    if last_response.status == 403
      puts last_response_body
    end

    assert_equal 201, last_response.status
  end
end
{'fraction_non_alphanumeric': 0.11255411255411256, 'fraction_numerical': 0.01443001443001443, 'mean_word_length': 4.581320450885668, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3092159', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1148, 'n_words': 157}