Skip to content

Commit

Permalink
Resolves HELIO-2264: Integration test on heliotrope-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Apr 22, 2019
1 parent 1816df1 commit f14f090
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 127 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -50,6 +50,9 @@ dump.rdb
/config/skylight.yml
/config/aptrust.yml

# Configuration file for automated systems tests.
/testing/testing.yml

# Google Analytics access keys
*.p12

Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Expand Up @@ -89,6 +89,7 @@ RSpec/DescribeClass:
- 'spec/features/**/*'
- 'spec/routing/**/*'
- 'spec/views/**/*'
- 'testing/spec/**/*'

RSpec/ExampleWording:
CustomTransform:
Expand Down
6 changes: 6 additions & 0 deletions db/publishers.yml
Expand Up @@ -68,3 +68,9 @@
press_url: 'http://www.psupress.org'
typekit: 'cbh1mev'
google_analytics: 'UA-77847516-7'

- subdomain: testing
production: false
name: 'Testing Press'
description: "Testing Press dedicated to automated systems tests."
press_url: 'https://www.lib.umich.edu'
18 changes: 10 additions & 8 deletions testing/README.md
@@ -1,11 +1,13 @@
# System Testing
## Shell Envirionment Variables
<table>
<tr><th>Variable</th><th>Description</th></tr>
<tr><td>HELIOTROPE_TESTING_API</td><td>Testing target API endpoint. e.g. http://localhost:3000/api </td></tr>
<tr><td>HELIOTROPE_TESTING_TOKEN</td><td>JSON Web Token of platform administrator user</td></tr>
</table>

# Testing
## Configuration
./testing/testing.yml
```yaml
testing:
source_url: 'https://www.fulcrum.org/'
source_token: ''
target_url: 'https://heliotrope-testing.hydra.lib.umich.edu/'
target_token: ''
```
## Rake Task
To run testing specs

Expand Down
16 changes: 0 additions & 16 deletions testing/bin/console

This file was deleted.

33 changes: 0 additions & 33 deletions testing/bin/handle

This file was deleted.

70 changes: 0 additions & 70 deletions testing/bin/heliotrope

This file was deleted.

19 changes: 19 additions & 0 deletions testing/spec/support/capybara_spec_helper.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'capybara/rspec'

Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end

Capybara.configure do |config|
config.default_max_wait_time = 10
config.default_driver = :selenium
end

RSpec.configure do |config|
config.include Capybara::DSL
end

module CapybaraSpecHelper
end
21 changes: 21 additions & 0 deletions testing/spec/testing/presses_index_spec.rb
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'testing_helper'

RSpec.describe "Presses Index", type: :capybara do
before do
Capybara.run_server = false
Capybara.default_max_wait_time = 15
Capybara.server_host = 'web'
Capybara.app_host = Testing::Target.url
end

it "index" do
visit "presses"
click_link "Testing Press"
expect(page).to have_content("Testing Press dedicated to automated systems tests.")
click_link "Log In"
expect(page).to have_content("Enter your Login ID and Password")
# Huston we have a problem ... Shibboleth.
end
end
11 changes: 11 additions & 0 deletions testing/spec/testing/testing_press_cleaner_spec.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'testing_helper'

RSpec.describe 'Testing Press Cleaner' do
before { Testing::Target.testing_press_cleaner }

it 'Press Cleaner is working' do
expect(Testing::Target.testing_press_monographs).to be_empty
end
end
10 changes: 10 additions & 0 deletions testing/spec/testing_helper.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'spec_helper'

require_relative '../testing'
require_relative './support/capybara_spec_helper'

RSpec.configure do |config|
config.include CapybaraSpecHelper, type: :capybara
end
41 changes: 41 additions & 0 deletions testing/testing.rb
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require_relative 'testing/source'
require_relative 'testing/target'

require 'yaml'

module Testing
def self.config
@config ||= Config.load_from_yaml
end
# private_class_method :config

class Config
def self.load_from_yaml
filename = 'testing.yml'
yaml = YAML.safe_load(File.read(filename)) if File.exist?(filename)
return new({}) unless yaml
new yaml.fetch('testing')
end

REQUIRED_KEYS = %w[source_url source_token target_url target_token].freeze

def initialize(config)
@config = config
end

def valid?
config_keys = @config.keys
REQUIRED_KEYS.all? { |required| config_keys.include?(required) }
end

REQUIRED_KEYS.each do |key|
class_eval <<-DEFINE, __FILE__, __LINE__ + 1
def #{key}
@config.fetch('#{key}')
end
DEFINE
end
end
end
5 changes: 5 additions & 0 deletions testing/testing.yml.sample
@@ -0,0 +1,5 @@
testing:
source_url: 'https://www.fulcrum.org/'
source_token: ''
target_url: 'https://heliotrope-testing.hydra.lib.umich.edu/'
target_token: ''
19 changes: 19 additions & 0 deletions testing/testing/source.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require_relative '../../app/services/turnsole/service'

module Testing
module Source
class << self
def url
Testing.config.source_url
end

private

def turnsole
@turnsole ||= Turnsole::Service.new(Testing.config.source_token, Testing.config.source_url + 'api/')
end
end
end
end
31 changes: 31 additions & 0 deletions testing/testing/target.rb
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require_relative '../../app/services/turnsole/service'

module Testing
module Target
class << self
def url
Testing.config.target_url
end

def testing_press_cleaner
monographs = testing_press_monographs
monographs.each do |monograph|
turnsole.delete_monograph(monograph['id'])
end
end

def testing_press_monographs
testing_press_id = turnsole.find_press('testing')
turnsole.press_monographs(testing_press_id)
end

private

def turnsole
@turnsole ||= Turnsole::Service.new(Testing.config.target_token, Testing.config.target_url + 'api/')
end
end
end
end

0 comments on commit f14f090

Please sign in to comment.