mitchellh-rubyuw 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ class MyUWTest < Test::Unit::TestCase
2
+ context "initializing a MyUW object" do
3
+ setup do
4
+ @myuw = MyUW.new
5
+ end
6
+
7
+ context "with browser object" do
8
+ should "initialize the browser object" do
9
+ assert @myuw.browser
10
+ assert @myuw.browser.kind_of?(WWW::Mechanize)
11
+ end
12
+
13
+ should "not store any history" do
14
+ assert_equal @myuw.browser.max_history, 0
15
+ end
16
+
17
+ should "not keep_alive to avoid strange SSL errors" do
18
+ assert !@myuw.browser.keep_alive
19
+ end
20
+ end
21
+
22
+ should "initialize the session object" do
23
+ assert @myuw.session
24
+ assert @myuw.session.kind_of?(MyUW::Session)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class SessionTest < Test::Unit::TestCase
4
+ def stub_get_login_page(myuw, page="login")
5
+ fixture_page = myuw.browser.get(path_to_html(page))
6
+ myuw.session.expects(:get_login_page).returns(fixture_page)
7
+
8
+ fixture_page
9
+ end
10
+
11
+ context "logging a user in" do
12
+ setup do
13
+ @myuw = MyUW.new
14
+ @session = @myuw.session
15
+ @browser = @myuw.browser
16
+ @browser.follow_meta_refresh = false
17
+ @session.email = @session.password = "foo"
18
+ end
19
+
20
+ should "raise an exception if no email/password are set" do
21
+ @session.email = @session.password = nil
22
+
23
+ assert_raise RuntimeError do
24
+ @session.login
25
+ end
26
+ end
27
+
28
+ should "raise an exception if the login form is not found" do
29
+ stub_get_login_page(@myuw, "no_form_login")
30
+
31
+ assert_raise RuntimeError do
32
+ @session.login
33
+ end
34
+ end
35
+
36
+ should "fill in details of the form and submit" do
37
+ login_fixture = stub_get_login_page(@myuw, "login")
38
+ login_form = login_fixture.form_with(:name => 'query')
39
+
40
+ login_form.expects(:user=).with(@session.email)
41
+ login_form.expects(:pass=).with(@session.password)
42
+ login_form.expects(:submit).once.returns(login_fixture) # Return to force it to think login failed
43
+
44
+ assert !@session.login
45
+ end
46
+ end
47
+
48
+ context "checking if logged in" do
49
+ setup do
50
+ @myuw = MyUW.new
51
+ @session = @myuw.session
52
+ @browser = @myuw.browser
53
+ @browser.follow_meta_refresh = false
54
+ end
55
+
56
+ should "raise an exception if the log in button is not found" do
57
+ fixture_page = @browser.get(path_to_html("no_login_button"))
58
+ @browser.expects(:get).with("http://myuw.washington.edu").once.returns(fixture_page)
59
+
60
+ assert_raise RuntimeError do
61
+ @session.logged_in?
62
+ end
63
+ end
64
+
65
+ should "report a user is logged in if it finds the greeting span" do
66
+ welcome_fixture_page = @browser.get(path_to_html("welcome"))
67
+ relay_fixture_page = @browser.get(path_to_html("logged_in_relay"))
68
+
69
+ @browser.stubs(:get).returns(welcome_fixture_page, relay_fixture_page)
70
+
71
+ assert_nothing_raised do
72
+ assert @session.logged_in?
73
+ end
74
+ end
75
+
76
+ should "report a user is not logged in if it doesnt find the greeting" do
77
+ welcome_fixture_page = @browser.get(path_to_html("welcome"))
78
+ relay_fixture_page = @browser.get(path_to_html("not_logged_in_relay"))
79
+
80
+ @browser.stubs(:get).returns(welcome_fixture_page, relay_fixture_page)
81
+
82
+ assert_nothing_raised do
83
+ assert !@session.logged_in?
84
+ end
85
+ end
86
+ end
87
+
88
+ context "logging a user out" do
89
+ should "just clear browser cookies" do
90
+ @myuw = MyUW.new
91
+ @myuw.browser.cookie_jar.expects(:clear!).once
92
+
93
+ @myuw.session.logout
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class MockedSlnTest < Test::Unit::TestCase
4
+ context "fetching SLN information" do
5
+ setup do
6
+ @myuw = MyUW.new
7
+ @myuw.stubs(:logged_in?).returns(true)
8
+ @browser = @myuw.browser
9
+ @browser.follow_meta_refresh = false
10
+ @sln = @myuw.sln("123456", "AUT+2009")
11
+ end
12
+
13
+ should "return a MyUW::SLNInfo object when calling MyUW.sln" do
14
+ sln_obj = @myuw.sln("123456", "AUT+2009")
15
+ assert sln_obj.kind_of?(MyUW::SLNInfo)
16
+ assert_equal sln_obj.sln, "123456"
17
+ assert_equal sln_obj.term, "AUT+2009"
18
+ end
19
+
20
+ should "raise a RuntimeError if there is no SLN set" do
21
+ @sln.sln = nil
22
+ assert @sln.term # Sanity
23
+
24
+ assert_raise RuntimeError do
25
+ @sln.course
26
+ end
27
+ end
28
+
29
+ should "raise a RuntimeError if there is no term set" do
30
+ @sln.term = nil
31
+ assert @sln.sln
32
+
33
+ assert_raise RuntimeError do
34
+ @sln.course
35
+ end
36
+ end
37
+
38
+ should "raise a RuntimeError if an SLN is requested again too soon" do
39
+ fixture_page = @browser.get(path_to_html("bad_request"))
40
+ fixture_page.uri = "http://www.washington.edu/students/timeschd/badrequest.html"
41
+ @browser.expects(:get).with("https://sdb.admin.washington.edu/timeschd/uwnetid/sln.asp?QTRYR=#{@sln.term}&SLN=#{@sln.sln}").returns(fixture_page)
42
+
43
+ assert_raise RuntimeError do
44
+ @sln.get_sln_page
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ class Test::Unit::TestCase
2
+ def path_to_html(html)
3
+ "file://" + File.join(File.dirname(__FILE__), 'fixture_pages', "#{html}.html")
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ #
2
+ # Contains the credentials for running live tests
3
+ # of the library. This file should never be stored
4
+ # in the repository. (The non-sample version)
5
+ #
6
+
7
+ MYUW_ID = "foo"
8
+ MYUW_PASSWORD = "bar"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mitchellh-rubyuw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hashimoto
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-26 00:00:00 -07:00
12
+ date: 2009-06-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,6 +39,23 @@ files:
39
39
  - lib/myuw/session.rb
40
40
  - lib/myuw/sln.rb
41
41
  - rubyuw.gemspec
42
+ - test/live/session_test.rb
43
+ - test/live/sln_test.rb
44
+ - test/live/test_helper.rb
45
+ - test/mocked/fixture_pages/bad_request.html
46
+ - test/mocked/fixture_pages/logged_in_relay.html
47
+ - test/mocked/fixture_pages/login.html
48
+ - test/mocked/fixture_pages/no_form_login.html
49
+ - test/mocked/fixture_pages/no_login_button.html
50
+ - test/mocked/fixture_pages/not_logged_in_relay.html
51
+ - test/mocked/fixture_pages/sln_does_not_exist.html
52
+ - test/mocked/fixture_pages/sln_status.html
53
+ - test/mocked/fixture_pages/welcome.html
54
+ - test/mocked/myuw_test.rb
55
+ - test/mocked/session_test.rb
56
+ - test/mocked/sln_test.rb
57
+ - test/mocked/test_helper.rb
58
+ - test/password.rb.sample
42
59
  has_rdoc: true
43
60
  homepage: http://github.com/mitchellh/rubyuw
44
61
  post_install_message:
@@ -65,5 +82,11 @@ rubygems_version: 1.2.0
65
82
  signing_key:
66
83
  specification_version: 2
67
84
  summary: Library which provides a ruby interface to the University of Washington student portal.
68
- test_files: []
69
-
85
+ test_files:
86
+ - test/live/session_test.rb
87
+ - test/live/sln_test.rb
88
+ - test/live/test_helper.rb
89
+ - test/mocked/myuw_test.rb
90
+ - test/mocked/session_test.rb
91
+ - test/mocked/sln_test.rb
92
+ - test/mocked/test_helper.rb