Skip to content

Commit

Permalink
Merge f3d768a into f6df732
Browse files Browse the repository at this point in the history
  • Loading branch information
keviny22 committed Oct 22, 2015
2 parents f6df732 + f3d768a commit fb72d84
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 55 deletions.
50 changes: 0 additions & 50 deletions .codeclimate.yml

This file was deleted.

1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## v0.1.3

* Added close account method

## v0.1.0

* First release
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in aws_account_utils.gemspec
gemspec

group :test do
gem 'rspec'
gem 'simplecov', require: false
gem 'coveralls', require: false
end
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[![Build Status](https://travis-ci.org/intuit/aws_account_utils.svg?branch=feature_delete_account)](https://travis-ci.org/intuit/aws_account_utils)
[![Coverage Status](https://coveralls.io/repos/intuit/aws_account_utils/badge.svg?branch=feature_delete_account&service=github)](https://coveralls.io/github/intuit/aws_account_utils)
[![Gem Version](https://badge.fury.io/rb/aws_account_utils.svg)](https://badge.fury.io/rb/aws_account_utils)
[![Code Climate](https://codeclimate.com/github/intuit/aws_account_utils.png)](https://codeclimate.com/github/intuit/aws_account_utils)

# AwsAccountUtils

A collection of helpers for creating and modifying AWS account details that can not be done using any existing AWS API
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
task :default => :spec
RSpec::Core::RakeTask.new
4 changes: 3 additions & 1 deletion aws_account_utils.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency 'bundler', '~> 1.9'
spec.required_ruby_version = '~> 2.1'

spec.add_development_dependency 'bundler', '>= 1.6.5'
spec.add_development_dependency 'webmock', '~> 1.21', '>= 1.21.0'
spec.add_development_dependency 'guard-rspec', '~> 4.3', '>= 4.3.1'
spec.add_development_dependency 'simplecov', '~> 0.8', '>= 0.8.2'
Expand Down
13 changes: 13 additions & 0 deletions lib/aws_account_utils.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'aws_account_utils/account'
require 'aws_account_utils/base'
require 'aws_account_utils/version'
require 'aws_account_utils/account_logger'
Expand Down Expand Up @@ -53,6 +54,14 @@ def change_root_password(account_email:, account_password:, new_password:)
browser.close rescue nil
end

def close_account(account_email:, account_password:)
resp = account.close(account_email, account_password)
logger.info 'Closed Account.' if resp
resp
ensure
browser.close rescue nil
end

def confirm_consolidated_billing(account_email:, account_password:, confirmation_link:)
resp = consolidated_billing.confirm account_email, account_password, confirmation_link
logger.info 'Consolidated billing has been confirmed' if resp
Expand Down Expand Up @@ -162,6 +171,10 @@ def challenge_questions
@challenge_questions ||= ChallengeQuestions.new logger, browser
end

def account
@account ||= Account.new logger, browser
end

def consolidated_billing
@consolidated_billing ||= ConsolidatedBilling.new logger, browser
end
Expand Down
44 changes: 44 additions & 0 deletions lib/aws_account_utils/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'aws_account_utils/base'
require 'aws_account_utils/login'

module AwsAccountUtils
class Account < Base
attr_reader :logger, :browser

def initialize(logger, browser)
@logger = logger
@browser = browser
end

def close(account_email, account_password)
logger.debug "Closing AWS account."

Login.new(logger, browser).execute url,
account_email,
account_password

browser.checkbox(:ng_model =>'isClosingAccount').when_present.set
screenshot(browser, "3")

browser.button(:text => /Close Account/).when_present.click
screenshot(browser, "2")

browser.wait_until{ browser.text.include? 'Are you sure you want to close your account?'}
browser.span(:text => /Close Account/).when_present.click
screenshot(browser, "3")

browser.p(:text => /Are you sure you want to close your account?/).wait_while_present

browser.wait_until{ browser.text.include? 'Account has been closed'}

rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
screenshot(browser, "error")
raise StandardError, "#{self.class.name} - #{e}"
end

private
def url
'https://console.aws.amazon.com/billing/home?#/account'
end
end
end
2 changes: 1 addition & 1 deletion lib/aws_account_utils/watir_browser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'aws_account_utils/base'
require 'watir-webdriver'
Watir::HTMLElement.attributes << :ng_model
Watir::HTMLElement.attributes << :ng_click

module AwsAccountUtils
class WatirBrowser
Expand Down Expand Up @@ -45,6 +46,5 @@ def proxy_settings
def proxy
@proxy ||= ENV['HTTP_PROXY']
end

end
end
56 changes: 56 additions & 0 deletions spec/aws_account_utils/account_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'spec_helper'

describe AwsAccountUtils::Account do
let(:logger) { Logger.new(STDOUT) }
let(:subject) { AwsAccountUtils::Account.new logger, browser }
let(:login) { AwsAccountUtils::Login.new logger, browser }
let(:browser) { double 'browser' }
let(:text_field) { double 'browser text field' }
let(:checkbox) { double 'browser checkbox' }
let(:text) { double 'browser text' }
let(:p) { double 'browser p element' }
let(:button) { double 'browser button' }
let(:span) { double 'browser span' }
let(:url) { 'https://console.aws.amazon.com/billing/home?#/account' }

it "should create a url alias" do
expect(logger).to receive(:debug).with('Closing AWS account.')

expect(browser).to receive(:text_field).with({:id=>"ap_email"}).and_return text_field
expect(text_field).to receive(:when_present).and_return text_field
expect(text_field).to receive(:set)

expect(browser).to receive(:text_field).with({:id=>"ap_password"}).and_return text_field
expect(text_field).to receive(:when_present).and_return text_field
expect(text_field).to receive(:set)

expect(browser).to receive(:button).with({:id=>"signInSubmit-input"}).and_return button
expect(button).to receive(:when_present).and_return button
expect(button).to receive(:click)

expect(browser).to receive(:goto).with(url)
expect(browser).to receive(:url).and_return('https://www.amazon.com/ap/signin?')
expect(logger).to receive(:debug).with('Logging into AWS.')

expect(browser).to receive(:checkbox).with({:ng_model => "isClosingAccount"}).and_return checkbox
expect(checkbox).to receive(:when_present).and_return checkbox
expect(checkbox).to receive(:set)

expect(browser).to receive(:button).with({:text => /Close Account/}).and_return button
expect(button).to receive(:when_present).and_return button
expect(button).to receive(:click)

expect(browser).to receive(:wait_until).and_return browser

expect(browser).to receive(:span).with({:text => /Close Account/}).and_return span
expect(span).to receive(:when_present).and_return span
expect(span).to receive(:click)

expect(browser).to receive(:p).with({:text => /Are you sure you want to close your account?/}).and_return p
expect(p).to receive(:wait_while_present).and_return p

expect(browser).to receive(:wait_until).and_return browser

expect(subject.close('my_user', 'my_password')).to be_truthy
end
end
2 changes: 0 additions & 2 deletions spec/aws_account_utils/challenge_questions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,4 @@
3=>"answer3"})

end

it "should generate random answers"
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require 'bundler/setup'
require 'simplecov'
require 'webmock/rspec'
require 'coveralls'
Coveralls.wear!

WebMock.disable_net_connect!(allow_localhost: true)

Expand Down

0 comments on commit fb72d84

Please sign in to comment.