Permalink
Browse files

Add some simple login routes to get a saucelabs username and API key …

…loaded into the session
  • Loading branch information...
1 parent ed3dddd commit 729bb116a0809093cc6e56379a021e2e72e1079c @rtyler committed Aug 5, 2012
Showing with 114 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +27 −0 features/step_definitions/watch_steps.rb
  3. +21 −0 features/support/credentials.rb
  4. +19 −0 features/watch.feature
  5. +25 −0 lib/saucetv.rb
  6. +15 −0 lib/views/login.haml
  7. +6 −0 lib/views/watch.haml
View
@@ -3,6 +3,7 @@ source :gemcutter
gem 'rake'
gem 'foreman'
gem 'sinatra'
+gem 'haml'
group :development do
gem 'cucumber'
@@ -0,0 +1,27 @@
+Given /^I am an unauthenticated user$/ do
+end
+
+Given /^I have a valid Sauce Labs username and API key$/ do
+ has_valid_credentials?
+end
+
+
+When /^I try to watch videos$/ do
+ visit '/watch'
+end
+
+When /^I enter my credentials$/ do
+ fill_in 'username', :with => username
+ fill_in 'api_key', :with => api_key
+ click_button 'Log in'
+end
+
+
+Then /^I should be given a list of jobs$/ do
+ page.should have_content "Welcome #{username}"
+end
+
+Then /^I should be prompted to log in with my username and API key$/ do
+ page.should have_content 'Please log in with your username and API key'
+end
+
@@ -0,0 +1,21 @@
+
+module UserCredentials
+ def has_valid_credentials?
+ filepath = File.join(Dir.pwd, 'ondemand.yml')
+ unless File.exists? filepath
+ raise Exception, 'Please place an ondemand.yml in the project root to run tests'
+ end
+
+ @credentials = YAML.load_file(filepath)
+ end
+
+ def username
+ @credentials['username'] || 'anonymous'
+ end
+
+ def api_key
+ @credentials['api_key'] || 'anonymous'
+ end
+end
+
+World(UserCredentials)
View
@@ -0,0 +1,19 @@
+Feature: Watch recorded job runs
+ As a browser
+ I want to watch videos from past job runs
+ So that I can have an idea of how tests are running even if I'm not 100%
+ focused on the videos and test results
+
+
+ Scenario: Unauthenticated user
+ Given I am an unauthenticated user
+ When I try to watch videos
+ Then I should be prompted to log in with my username and API key
+
+ Scenario: Authenticated user
+ Given I have a valid Sauce Labs username and API key
+ When I try to watch videos
+ And I enter my credentials
+ Then I should be given a list of jobs
+
+
View
@@ -3,8 +3,33 @@
module SauceTV
class Application < Sinatra::Base
+ enable :sessions
+
+ def authenticated?
+ session[:username] && session[:api_key]
+ end
+
get '/' do
'Welcome to SauceLabs.tv'
end
+
+ get '/login' do
+ haml :login
+ end
+
+ post '/login' do
+ session[:username] = params[:username]
+ session[:api_key] = params[:api_key]
+ redirect to('/watch')
+ end
+
+ get '/watch' do
+ unless authenticated?
+ redirect to('/login')
+ end
+
+ haml :watch, :locals => {:username => session[:username]}
+ end
+
end
end
View
@@ -0,0 +1,15 @@
+%html
+ %head
+ %title
+ SauceLabs.tv
+ %body
+ Please log in with your username and API key
+
+ %form{:method => 'POST', :action => '/login'}
+ %label
+ Sauce Labs Username:
+ %input{:name => 'username'}
+ %label
+ Sauce Labs API Key:
+ %input{:name => 'api_key', :type => 'password'}
+ %input{:type => 'submit', :value => 'Log in'}
View
@@ -0,0 +1,6 @@
+%html
+ %head
+ %title
+ SauceLabs.tv
+ %body
+ Welcome #{username}

0 comments on commit 729bb11

Please sign in to comment.