<commit_before>require 'test_helper'

# test district resource
class DistrictTest < Minitest::Test
  def setup
    Clever.configure do |config|
      config.api_key = 'DEMO_KEY'
    end
  end

  should "retrieve a district's schools" do
    test_object_list 'schools', 3, Clever::School
  end

  should "page a district's schools" do
    test_object_pages 'school', 2, 2
  end

  should "retrieve a district's teachers" do
    test_object_list 'teachers', 89, Clever::Teacher
  end

  should "page a district's teachers" do
    test_object_pages 'teacher', 10, 9
  end

  should "retrieve a district's sections" do
    test_object_list 'sections', 100, Clever::Section
  end

  should "page a district's sections" do
    test_object_pages 'section', 10, 38
  end

  should "retrieve a district's students" do
    test_object_list 'students', 100, Clever::Student
  end

  should "page a district's students" do
    test_object_pages 'student', 50, 21
  end

  should "retrieve a district's students with a small filter" do
    VCR.use_cassette('districts_students_filtered') do
      @district = Clever::District.all.first
      @district.students(limit: 2).size.must_equal 2
    end
  end

  should "retrieve a district's events" do
    test_object_list 'events', 13, Clever::Event
  end

  should "page a district's events" do
    test_object_pages 'event', 1, 14
  end

  private

  def test_object_list(plural_object_name, object_count, instance_name)
    VCR.use_cassette("districts_#{plural_object_name}", allow_playback_repeats: true) do
      district = Clever::District.all.first
      district.send(plural_object_name).size.must_equal object_count
      district.send(plural_object_name).first.must_be_instance_of instance_name
    end
  end

  def test_object_pages(object_name, limit, page_count)
    VCR.use_cassette("districts_#{object_name}_pages", allow_playback_repeats: true) do
      district = Clever::District.all.first
      object_count_from_list = district.send("#{object_name}s", limit: 100_000).size

      object_count_from_paging = 0
      pages = 0
      district.send("#{object_name}_pages", limit: limit).each do |object_page|
        pages += 1
        objects = object_page.all
        object_count_from_paging += objects.size
      end

      object_count_from_paging.must_equal object_count_from_list
      pages.must_equal page_count
    end
  end
end<commit_msg>update district_test to use pure minitest<commit_after>require 'test_helper'

# helpers for district tests
module DistrictHelpers
  def test_object_list(plural_object_name, object_count, instance_name)
    VCR.use_cassette("districts_#{plural_object_name}", allow_playback_repeats: true) do
      district = Clever::District.all.first
      district.send(plural_object_name).size.must_equal object_count
      district.send(plural_object_name).first.must_be_instance_of instance_name
    end
  end

  def test_object_pages(object_name, limit, page_count)
    VCR.use_cassette("districts_#{object_name}_pages", allow_playback_repeats: true) do
      district = Clever::District.all.first
      object_count_from_list = district.send("#{object_name}s", limit: 100_000).size

      object_count_from_paging = 0
      pages = 0
      district.send("#{object_name}_pages", limit: limit).each do |object_page|
        pages += 1
        objects = object_page.all
        object_count_from_paging += objects.size
      end

      object_count_from_paging.must_equal object_count_from_list
      pages.must_equal page_count
    end
  end
end

describe Clever::District do
  include DistrictHelpers

  before do
    Clever.configure do |config|
      config.api_key = 'DEMO_KEY'
    end
  end

  def test_retrieval
    it "retrieves a district's schools" do
      test_object_list 'schools', 3, Clever::School
    end

    it "retrieves a district's teachers" do
      test_object_list 'teachers', 89, Clever::Teacher
    end

    it "retrieves a district's sections" do
      test_object_list 'sections', 100, Clever::Section
    end

    it "retrieves a district's students" do
      test_object_list 'students', 100, Clever::Student
    end

    it "retrieves a district's events" do
      test_object_list 'events', 13, Clever::Event
    end
  end

  def test_filtered_retrieval
    it "retrieves a district's students with a small filter" do
      VCR.use_cassette('districts_students_filtered') do
        @district = Clever::District.all.first
        @district.students(limit: 2).size.must_equal 2
      end
    end
  end

  def test_pages
    it "pages a district's schools" do
      test_object_pages 'school', 2, 2
    end

    it "pages a district's teachers" do
      test_object_pages 'teacher', 10, 9
    end

    it "pages a district's sections" do
      test_object_pages 'section', 10, 38
    end

    it "pages a district's students" do
      test_object_pages 'student', 50, 21
    end

    it "pages a district's events" do
      test_object_pages 'event', 1, 14
    end
  end
end
{'fraction_non_alphanumeric': 0.08034462031656983, 'fraction_numerical': 0.015227409336806252, 'mean_word_length': 3.5756186984417964, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '3290840', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1582, 'n_words': 418}