<commit_before>require 'spec_helper'

# Provisions, binds, unbinds, deprovisions a service

def cleanup_mysql_user(username)
  ActiveRecord::Base.connection.execute("DROP USER #{username}")
rescue
end
def cleanup_mysql_database(dbname)
  ActiveRecord::Base.connection.execute("DROP DATABASE #{dbname}")
rescue
end

def create_mysql_client(username=Rails.configuration.database_configuration[Rails.env].fetch('username'),
                        password=Rails.configuration.database_configuration[Rails.env].fetch('password'),
                        database='mysql')
  Mysql2::Client.new(
      :host     => Rails.configuration.database_configuration[Rails.env].fetch('host'),
      :port     => Rails.configuration.database_configuration[Rails.env].fetch('port'),
      :database => database,
      :username => username,
      :password => password
  )
end


describe 'the service lifecycle' do
  let(:instance_id) { 'instance-1' }
  let(:dbname) { ServiceInstance.new(id: instance_id).database }

  let(:binding_id) { 'binding-1' }
  let(:password) { '<PASSWORD>' }
  let(:username) { ServiceBinding.new(id: binding_id).username }

  before do
    SecureRandom.stub(:base64).and_return(password, '<PASSWORD>')
    cleanup_mysql_user(username)
    cleanup_mysql_database(dbname)
  end

  after do
    cleanup_mysql_user(username)
    cleanup_mysql_database(dbname)
  end

  it 'provisions, binds, unbinds, deprovisions' do
    ##
    ## Provision the instance
    ##
    put "/v2/service_instances/#{instance_id}", {service_plan_id: 'PLAN-1'}

    expect(response.status).to eq(201)
    expect(response.body).to eq("{\"dashboard_url\":\"http://pmysql.vcap.me/manage/instances/#{instance_id}\"}")

    ##
    ## Bind
    ##
    put "/v2/service_instances/#{instance_id}/service_bindings/#{binding_id}"

    expect(response.status).to eq(201)<commit_msg>Fix test assertion to new default scheme<commit_after>require 'spec_helper'

# Provisions, binds, unbinds, deprovisions a service

def cleanup_mysql_user(username)
  ActiveRecord::Base.connection.execute("DROP USER #{username}")
rescue
end
def cleanup_mysql_database(dbname)
  ActiveRecord::Base.connection.execute("DROP DATABASE #{dbname}")
rescue
end

def create_mysql_client(username=Rails.configuration.database_configuration[Rails.env].fetch('username'),
                        password=Rails.configuration.database_configuration[Rails.env].fetch('password'),
                        database='mysql')
  Mysql2::Client.new(
      :host     => Rails.configuration.database_configuration[Rails.env].fetch('host'),
      :port     => Rails.configuration.database_configuration[Rails.env].fetch('port'),
      :database => database,
      :username => username,
      :password => password
  )
end


describe 'the service lifecycle' do
  let(:instance_id) { 'instance-1' }
  let(:dbname) { ServiceInstance.new(id: instance_id).database }

  let(:binding_id) { 'binding-1' }
  let(:password) { '<PASSWORD>' }
  let(:username) { ServiceBinding.new(id: binding_id).username }

  before do
    SecureRandom.stub(:base64).and_return(password, '<PASSWORD>')
    cleanup_mysql_user(username)
    cleanup_mysql_database(dbname)
  end

  after do
    cleanup_mysql_user(username)
    cleanup_mysql_database(dbname)
  end

  it 'provisions, binds, unbinds, deprovisions' do
    ##
    ## Provision the instance
    ##
    put "/v2/service_instances/#{instance_id}", {service_plan_id: 'PLAN-1'}

    expect(response.status).to eq(201)
    expect(response.body).to eq("{\"dashboard_url\":\"https://pmysql.vcap.me/manage/instances/#{instance_id}\"}")

    ##
    ## Bind
    ##
    put "/v2/service_instances/#{instance_id}/service_bindings/#{binding_id}"

    expect(response.status).to eq(201)
{'fraction_non_alphanumeric': 0.14010695187165775, 'fraction_numerical': 0.0074866310160427805, 'mean_word_length': 4.203059805285118, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 1, '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': '3844613', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1167, 'n_words': 183}