<commit_before># encoding: utf-8

require 'helper'

class TestCrawler < Test::Unit::TestCase
  context 'valid credentials' do
    setup { VCR.insert_cassette('console_valid_credentials') }
    teardown { VCR.eject_cassette('console_valid_credentials') }

    should 'login successfully' do
      assert_nothing_raised ESIC::LoginFailedException do
        ESIC::Crawler.new(USERNAME, PASSWORD)
      end
    end

    context 'requests' do
      should 'list' do
        crawler = ESIC::Crawler.new(USERNAME, PASSWORD)
        requests = crawler.requests
        assert requests.length == 4, "Should have 4 requests #{requests.length}"
      end
    end

    context 'request' do
      should 'list' do
        crawler = ESIC::Crawler.new(USERNAME, PASSWORD)
        request = crawler.request('08850001191201270')
        assert request.text =~ /violência contra a mulher/, request.text
        assert request.response_text =~ /Prezado Cidadão/, request.response_text
      end

      should 'work' do
        crawler = ESIC::Crawler.new(USERNAME, PASSWORD)<commit_msg>Melhora texto dos testes.<commit_after># encoding: utf-8

require 'helper'

class TestCrawler < Test::Unit::TestCase
  context 'valid credentials' do
    setup { VCR.insert_cassette('console_valid_credentials') }
    teardown { VCR.eject_cassette('console_valid_credentials') }

    should 'login successfully' do
      assert_nothing_raised ESIC::LoginFailedException do
        ESIC::Crawler.new(USERNAME, PASSWORD)
      end
    end

    context 'requests' do
      should 'list' do
        crawler = ESIC::Crawler.new(USERNAME, PASSWORD)
        requests = crawler.requests
        assert requests.length == 4, "Should have 4 requests #{requests.length}"
      end
    end

    context 'request' do
      should 'get the request\'s and response\'s text' do
        crawler = ESIC::Crawler.new(USERNAME, PASSWORD)
        request = crawler.request('08850001191201270')
        assert request.text =~ /violência contra a mulher/, request.text
        assert request.response_text =~ /Prezado Cidadão/, request.response_text
      end

      should 'work even if the public body haven\'t answered yet' do
        crawler = ESIC::Crawler.new(USERNAME, PASSWORD)
{'fraction_non_alphanumeric': 0.09466128308658592, 'fraction_numerical': 0.01794526693584567, 'mean_word_length': 3.137291280148423, 'pattern_counts': {'":': 0, '<': 5, '<?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': '879360', 'n_tokens_mistral': 715, 'n_tokens_neox': 680, 'n_words': 171}