<commit_before>require "spec_helper"
describe Mogli::Client do

  let :client do
    Mogli::Client.new
  end


  describe "creation" do
    it "allows creating with an access_token" do
      client = Mogli::Client.new("myaccesstoken")
      client.access_token.should == "myaccesstoken"
    end

    context "when exchanging a session key" do
      it "allows creating" do
        Time.stub!(:now).and_return(1270000000)
        authenticator = Mogli::Authenticator.new('123456', 'secret', nil)
        authenticator.should_receive(:get_access_token_for_session_key).
                      with('mysessionkey').
                      and_return({'access_token' => '<PASSWORD>cesstoken',
                                  'expires' => 5000})
        Mogli::Authenticator.should_receive(:new).and_return(authenticator)
        client = Mogli::Client.create_from_session_key(
                   'mysessionkey', '123456', 'secret')
        client.access_token.should == 'myaccesstoken'
        client.expiration.should == Time.at(1270005000)
      end

      it "allows creating and authenticating as an application" do
        authenticator = Mogli::Authenticator.new('123456', 'secret', nil)
        authenticator.should_receive(:get_access_token_for_application).
                      and_return("123456|<KEY>")
        Mogli::Authenticator.should_receive(:new).and_return(authenticator)
        client = Mogli::Client.create_and_authenticate_as_application(
                   'mysessionkey', '123456')
        client.access_token.should == '<KEY>'
      end<commit_msg>Test for Accept and Content-Type request headers.<commit_after>require "spec_helper"
describe Mogli::Client do

  let :client do
    Mogli::Client.new
  end


  describe "default options" do
    it "set 'accept' and 'content-type' headers" do
      headers = Mogli::Client.default_options[:headers]

      headers.should_not be_nil
      headers.should include("Accept")
      headers.should include("Content-Type")
    end
  end

  describe "creation" do
    it "allows creating with an access_token" do
      client = Mogli::Client.new("myaccesstoken")
      client.access_token.should == "myaccesstoken"
    end

    context "when exchanging a session key" do
      it "allows creating" do
        Time.stub!(:now).and_return(1270000000)
        authenticator = Mogli::Authenticator.new('123456', 'secret', nil)
        authenticator.should_receive(:get_access_token_for_session_key).
                      with('mysessionkey').
                      and_return({'access_token' => 'myaccesstoken',
                                  'expires' => 5000})
        Mogli::Authenticator.should_receive(:new).and_return(authenticator)
        client = Mogli::Client.create_from_session_key(
                   'mysessionkey', '123456', 'secret')
        client.access_token.should == 'myaccesstoken'
        client.expiration.should == Time.at(1270005000)
      end

      it "allows creating and authenticating as an application" do
        authenticator = Mogli::Authenticator.new('123456', 'secret', nil)
        authenticator.should_receive(:get_access_token_for_application).
                      and_return("123456|<KEY>")
        Mogli::Authenticator.should_receive(:new).and_return(authenticator)
        client = Mogli::Client.create_and_authenticate_as_application(
                   'mysessionkey', '123456')
        client.access_token.should == '<KEY>BH5tJtl-dcBdsfgo'
      end
{'fraction_non_alphanumeric': 0.10664739884393064, 'fraction_numerical': 0.0315028901734104, 'mean_word_length': 2.8285398230088497, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1159916', 'n_tokens_mistral': 1118, 'n_tokens_neox': 990, 'n_words': 188}