<commit_before>require 'test/unit'
require '3scale/client'

if ENV['TEST_3SCALE_PROVIDER_KEY'] &&
   ENV['TEST_3SCALE_APP_IDS']      &&
   ENV['TEST_3SCALE_APP_KEYS']
  class ThreeScale::RemoteTest < Test::Unit::TestCase
    def setup
      @provider_key = ENV['TEST_3SCALE_PROVIDER_KEY']

      stripper = lambda { |string| string.strip }

      @app_ids  = ENV['TEST_3SCALE_APP_IDS'].split(',').map(&stripper)
      @app_keys = ENV['TEST_3SCALE_APP_KEYS'].split(',').map(&stripper)

      @client = ThreeScale::Client.new(:provider_key => @provider_key)

      if defined?(FakeWeb)
        FakeWeb.clean_registry
        FakeWeb.allow_net_connect = true
      end
    end

    def test_successful_authrep
      @app_keys.each do |app_key|
        response = @client.authrep(:app_id => @app_ids[0], :app_key => app_key,
                                   :usage => {:hits => 2},
                                   :log => {:request => "a/a", :response => "b/b", :code => "c/c"})
        assert response.success?, "AuthRep should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it failed with: '#{response.error_message}'"
      end
    end

    def test_successful_secure_authrep
      @client = ThreeScale::Client.new(:provider_key => @provider_key, :secure => true)
      test_successful_authrep
    end


    def test_failed_authrep
      response = @client.authrep(:app_id => 'invalid-id')
      assert !response.success?
      assert_equal 'application_not_found',                          response.error_code
      assert_equal 'application with id="invalid-id" was not found', response.error_message
    end

    def test_successful_authorize
      @app_keys.each do |app_key|
        response = @client.authorize(:app_id => @app_ids[0], :app_key => app_key)
        assert response.success?, "Authorize should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it failed with: '#{response.error_message}'"
      end
    end
<commit_msg>test that remote tests are actually testing<commit_after>require 'test/unit'
require '3scale/client'

if ENV['TEST_3SCALE_PROVIDER_KEY'] &&
   ENV['TEST_3SCALE_APP_IDS']      &&
   ENV['TEST_3SCALE_APP_KEYS']
  class ThreeScale::RemoteTest < Test::Unit::TestCase
    def setup
      @provider_key = ENV['TEST_3SCALE_PROVIDER_KEY']

      stripper = lambda { |string| string.strip }

      @app_ids  = ENV['TEST_3SCALE_APP_IDS'].split(',').map(&stripper)
      @app_keys = ENV['TEST_3SCALE_APP_KEYS'].split(',').map(&stripper)

      @client = ThreeScale::Client.new(:provider_key => @provider_key)

      if defined?(FakeWeb)
        FakeWeb.clean_registry
        FakeWeb.allow_net_connect = true
      end
    end

    def test_app_ids_are_passed
      assert @app_ids.length > 0, 'expected TEST_3SCALE_APP_IDS to contain app ids'
    end

    def test_app_keys_are_passed
      assert @app_keys.length > 0, 'expected TEST_3SCALE_APP_KEYS to contain app keys'
    end

    def test_successful_authrep
      @app_keys.each do |app_key|
        response = @client.authrep(:app_id => @app_ids[0], :app_key => app_key,
                                   :usage => {:hits => 2},
                                   :log => {:request => "a/a", :response => "b/b", :code => "c/c"})
        assert response.success?, "AuthRep should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it failed with: '#{response.error_message}'"
      end
    end

    def test_successful_secure_authrep
      @client = ThreeScale::Client.new(:provider_key => @provider_key, :secure => true)
      test_successful_authrep
    end


    def test_failed_authrep
      response = @client.authrep(:app_id => 'invalid-id')
      assert !response.success?
      assert_equal 'application_not_found',                          response.error_code
      assert_equal 'application with id="invalid-id" was not found', response.error_message
    end

    def test_successful_authorize
      @app_keys.each do |app_key|
        response = @client.authorize(:app_id => @app_ids[0], :app_key => app_key)
        assert response.success?, "Authorize should succeed for app_id=#{@app_ids[0]} and app_key=#{app_key}, but it failed with: '#{response.error_message}'"
      end
    end

{'fraction_non_alphanumeric': 0.12357954545454546, 'fraction_numerical': 0.006628787878787879, 'mean_word_length': 3.050814956855225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6845347', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1361, 'n_words': 276}