mitchellh-rubyuw 0.7.2 → 0.99.0
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.
- data/.gitignore +3 -1
- data/{README.markdown → README.md} +6 -11
- data/Rakefile +12 -2
- data/VERSION +1 -1
- data/lib/rubyuw.rb +8 -0
- data/lib/rubyuw/base.rb +122 -0
- data/lib/rubyuw/connection.rb +145 -0
- data/lib/rubyuw/curriculum_enrollment.rb +75 -0
- data/lib/rubyuw/errors.rb +16 -0
- data/lib/rubyuw/sln.rb +108 -0
- data/test/live/curriculum_enrollment_test.rb +47 -0
- data/test/live/sln_test.rb +16 -26
- data/test/live/test_helper.rb +15 -2
- data/test/mocked/base_test.rb +171 -0
- data/test/mocked/connection_test.rb +178 -0
- data/test/mocked/curriculum_enrollment_test.rb +132 -61
- data/test/mocked/sln_test.rb +106 -142
- data/test/mocked/test_helper.rb +57 -1
- metadata +20 -29
- data/lib/myuw.rb +0 -67
- data/lib/myuw/curriculum_enrollment.rb +0 -110
- data/lib/myuw/errors.rb +0 -18
- data/lib/myuw/registration.rb +0 -98
- data/lib/myuw/schedule.rb +0 -74
- data/lib/myuw/session.rb +0 -91
- data/lib/myuw/sln.rb +0 -131
- data/rubyuw.gemspec +0 -102
- data/test/live/registration_test.rb +0 -46
- data/test/live/schedule_test.rb +0 -28
- data/test/live/session_test.rb +0 -34
- data/test/mocked/myuw_test.rb +0 -39
- data/test/mocked/registration_test.rb +0 -105
- data/test/mocked/schedule_test.rb +0 -132
- data/test/mocked/session_test.rb +0 -96
data/test/live/schedule_test.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
# NOTE: Very little of this can actually be "live tested"
|
4
|
-
# by an automated script. The information is extremely
|
5
|
-
# volatile. We can only test the constants here. The
|
6
|
-
# rest must be "mock tested"
|
7
|
-
|
8
|
-
class LiveScheduleTest < Test::Unit::TestCase
|
9
|
-
context "fetching schedule" do
|
10
|
-
setup do
|
11
|
-
@myuw = MyUW.new
|
12
|
-
@session = @myuw.session
|
13
|
-
@session.email = MYUW_ID
|
14
|
-
@session.password = MYUW_PASSWORD
|
15
|
-
assert @session.login
|
16
|
-
|
17
|
-
@schedule = @myuw.schedule
|
18
|
-
end
|
19
|
-
|
20
|
-
should "throw an exception if not logged in" do
|
21
|
-
@session.logout
|
22
|
-
|
23
|
-
assert_raise MyUW::NotLoggedInError do
|
24
|
-
@schedule.schedule
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/test/live/session_test.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class LiveSessionTest < Test::Unit::TestCase
|
4
|
-
context "live sessions" do
|
5
|
-
setup do
|
6
|
-
@myuw = MyUW.new
|
7
|
-
@session = @myuw.session
|
8
|
-
@session.email = MYUW_ID
|
9
|
-
@session.password = MYUW_PASSWORD
|
10
|
-
end
|
11
|
-
|
12
|
-
should "report successful login with credentials" do
|
13
|
-
assert @session.login
|
14
|
-
end
|
15
|
-
|
16
|
-
should "fail login with bad credentials" do
|
17
|
-
@session.password = MYUW_PASSWORD + "bad"
|
18
|
-
assert !@session.login
|
19
|
-
assert !@session.logged_in?
|
20
|
-
end
|
21
|
-
|
22
|
-
should "report logged_in? once logged in via the session object" do
|
23
|
-
assert @session.login
|
24
|
-
assert @session.logged_in?
|
25
|
-
end
|
26
|
-
|
27
|
-
should "not report logged_in? once logout is called after logging in" do
|
28
|
-
assert @session.login
|
29
|
-
assert @session.logged_in?
|
30
|
-
@session.logout
|
31
|
-
assert !@session.logged_in?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/test/mocked/myuw_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class MyUWTest < Test::Unit::TestCase
|
4
|
-
context "initializing a MyUW object" do
|
5
|
-
setup do
|
6
|
-
@myuw = MyUW.new
|
7
|
-
end
|
8
|
-
|
9
|
-
context "with browser object" do
|
10
|
-
should "initialize the browser object" do
|
11
|
-
assert @myuw.browser
|
12
|
-
assert @myuw.browser.kind_of?(WWW::Mechanize)
|
13
|
-
end
|
14
|
-
|
15
|
-
should "not store any history" do
|
16
|
-
assert_equal @myuw.browser.max_history, 0
|
17
|
-
end
|
18
|
-
|
19
|
-
should "not keep_alive to avoid strange SSL errors" do
|
20
|
-
assert !@myuw.browser.keep_alive
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
should "initialize the session object" do
|
25
|
-
assert @myuw.session
|
26
|
-
assert @myuw.session.kind_of?(MyUW::Session)
|
27
|
-
end
|
28
|
-
|
29
|
-
should "initialize the schedule object" do
|
30
|
-
assert @myuw.schedule
|
31
|
-
assert @myuw.schedule.kind_of?(MyUW::Schedule)
|
32
|
-
end
|
33
|
-
|
34
|
-
should "initialize the registration object" do
|
35
|
-
assert @myuw.registration
|
36
|
-
assert @myuw.registration.kind_of?(MyUW::Registration)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,105 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class MockedRegistrationTest < Test::Unit::TestCase
|
4
|
-
def get_fixture_form
|
5
|
-
fixture_page = @browser.get(path_to_html("registration"))
|
6
|
-
fixture_form = fixture_page.form_with(:name => 'regform')
|
7
|
-
assert fixture_form
|
8
|
-
assert fixture_form.kind_of?(WWW::Mechanize::Form) # Sanity
|
9
|
-
|
10
|
-
fixture_form
|
11
|
-
end
|
12
|
-
|
13
|
-
context "registering for a course" do
|
14
|
-
setup do
|
15
|
-
@myuw = MyUW.new
|
16
|
-
@myuw.stubs(:logged_in?).returns(true)
|
17
|
-
@browser = @myuw.browser
|
18
|
-
@browser.follow_meta_refresh = false
|
19
|
-
@registration = @myuw.registration
|
20
|
-
|
21
|
-
@courses = ["123456", "123321"]
|
22
|
-
end
|
23
|
-
|
24
|
-
should "raise a NotLoggedInError if user is not logged in" do
|
25
|
-
@myuw.stubs(:logged_in?).returns(false)
|
26
|
-
|
27
|
-
assert_raise MyUW::NotLoggedInError do
|
28
|
-
@registration.register("123456")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
should "raise an InvalidPageError if it does not contain the registration form" do
|
33
|
-
fixture_page = @browser.get(path_to_html("registration_no_form"))
|
34
|
-
@browser.expects(:get).returns(fixture_page)
|
35
|
-
|
36
|
-
assert_raise MyUW::InvalidPageError do
|
37
|
-
@registration.register("123456")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
should "say the start index is 4 for the fixture form" do
|
42
|
-
fixture_form = get_fixture_form
|
43
|
-
|
44
|
-
assert_equal "4", @registration.get_add_section_index(fixture_form)
|
45
|
-
end
|
46
|
-
|
47
|
-
should "start filling in the sln values at the right index" do
|
48
|
-
fixture_form = get_fixture_form
|
49
|
-
start_index = @registration.get_add_section_index(fixture_form).to_i
|
50
|
-
|
51
|
-
assert_nothing_raised { @registration.fill_registration_form(fixture_form, @courses) }
|
52
|
-
@courses.each_index do |i|
|
53
|
-
assert_equal @courses[i], fixture_form["sln#{i + start_index}"]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "analyzing registration result" do
|
59
|
-
setup do
|
60
|
-
@myuw = MyUW.new
|
61
|
-
@myuw.stubs(:logged_in?).returns(true)
|
62
|
-
@browser = @myuw.browser
|
63
|
-
@browser.follow_meta_refresh = false
|
64
|
-
@registration = @myuw.registration
|
65
|
-
end
|
66
|
-
|
67
|
-
should "return true if schedule is updated right" do
|
68
|
-
fixture_page = @browser.get(path_to_html("registration_success"))
|
69
|
-
|
70
|
-
assert @registration.get_registration_result(fixture_page)
|
71
|
-
end
|
72
|
-
|
73
|
-
should "raise InvalidPageError if something unknown occurs" do
|
74
|
-
fixture_page = @browser.get(path_to_html("registration_unknown"))
|
75
|
-
|
76
|
-
assert_raise MyUW::InvalidPageError do
|
77
|
-
@registration.get_registration_result(fixture_page)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
should "return false if schedule is not updated" do
|
82
|
-
fixture_page = @browser.get(path_to_html("registration_error"))
|
83
|
-
|
84
|
-
assert !@registration.get_registration_result(fixture_page)
|
85
|
-
assert !@registration.errors["17429"].empty?
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "extracting registration errors" do
|
90
|
-
setup do
|
91
|
-
@myuw = MyUW.new
|
92
|
-
@myuw.stubs(:logged_in?).returns(true)
|
93
|
-
@browser = @myuw.browser
|
94
|
-
@browser.follow_meta_refresh = false
|
95
|
-
@registration = @myuw.registration
|
96
|
-
end
|
97
|
-
|
98
|
-
should "extract errors from an erroneous registration" do
|
99
|
-
fixture_page = @browser.get(path_to_html("registration_error"))
|
100
|
-
|
101
|
-
assert_nothing_raised { @registration.extract_registration_errors(fixture_page) }
|
102
|
-
assert_equal "To add this section, you must also register for the related 'primary' section. In most cases, the primary section is a lecture [LC] section.", @registration.errors["17429"]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class MockedScheduleTest < Test::Unit::TestCase
|
4
|
-
context "fetching a person's schedule" 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
|
-
@schedule = @myuw.schedule
|
11
|
-
|
12
|
-
@courses = [
|
13
|
-
{
|
14
|
-
:sln => "14368",
|
15
|
-
:course => "HIST 111 A",
|
16
|
-
:type => "LC",
|
17
|
-
:credits => "5.0",
|
18
|
-
:title => "THE ANCIENT WORLD",
|
19
|
-
:days => "MTWTh",
|
20
|
-
:time => "130-220",
|
21
|
-
:location => "SMI 120",
|
22
|
-
:instructor => "WALKER,JOEL T"
|
23
|
-
},
|
24
|
-
{
|
25
|
-
:sln => "14372"
|
26
|
-
},
|
27
|
-
{
|
28
|
-
:sln => "12271"
|
29
|
-
}
|
30
|
-
]
|
31
|
-
end
|
32
|
-
|
33
|
-
should "raise NotLoggedInError if not logged in and fetching schedule" do
|
34
|
-
@myuw.expects(:logged_in?).returns(false)
|
35
|
-
|
36
|
-
assert_raise MyUW::NotLoggedInError do
|
37
|
-
@myuw.schedule.schedule
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
should "raise InvalidPageError if there are no courses in the table" do
|
42
|
-
fixture_page = @browser.get(path_to_html("schedule_empty"))
|
43
|
-
@browser.expects(:get).returns(fixture_page)
|
44
|
-
|
45
|
-
assert_raise MyUW::InvalidPageError do
|
46
|
-
@schedule.schedule
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
should "get the courses" do
|
51
|
-
fixture_page = @browser.get(path_to_html("schedule"))
|
52
|
-
@browser.expects(:get).returns(fixture_page)
|
53
|
-
|
54
|
-
assert_nothing_raised { @schedule.schedule }
|
55
|
-
assert @schedule.courses
|
56
|
-
assert_equal @courses.length, @schedule.courses.length
|
57
|
-
|
58
|
-
@courses.each_index do |i|
|
59
|
-
course = @courses[i]
|
60
|
-
|
61
|
-
course.each do |k, v|
|
62
|
-
assert_equal v, @schedule.courses[i][k]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context "fetching a person's credits" do
|
69
|
-
setup do
|
70
|
-
@myuw = MyUW.new
|
71
|
-
@myuw.stubs(:logged_in?).returns(true)
|
72
|
-
@browser = @myuw.browser
|
73
|
-
@browser.follow_meta_refresh = false
|
74
|
-
@schedule = @myuw.schedule
|
75
|
-
end
|
76
|
-
|
77
|
-
should "raise InvalidPageError if the credit row is missing" do
|
78
|
-
fixture_page = @browser.get(path_to_html("schedule_no_credit_row"))
|
79
|
-
@browser.expects(:get).returns(fixture_page)
|
80
|
-
|
81
|
-
assert_raise MyUW::InvalidPageError do
|
82
|
-
@schedule.schedule
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
should "raise InvalidPageError if the credit row is in a different syntax" do
|
87
|
-
fixture_page = @browser.get(path_to_html("schedule_diff_credit_row"))
|
88
|
-
@browser.expects(:get).returns(fixture_page)
|
89
|
-
|
90
|
-
assert_raise MyUW::InvalidPageError do
|
91
|
-
@schedule.schedule
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
should "get the credits" do
|
96
|
-
fixture_page = @browser.get(path_to_html("schedule"))
|
97
|
-
@browser.expects(:get).returns(fixture_page)
|
98
|
-
|
99
|
-
assert_nothing_raised { @schedule.schedule }
|
100
|
-
assert @schedule.credits
|
101
|
-
assert_equal 8.0, @schedule.credits
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "fetching precached values for a schedule" do
|
106
|
-
setup do
|
107
|
-
@myuw = MyUW.new
|
108
|
-
@myuw.stubs(:logged_in?).returns(true)
|
109
|
-
@browser = @myuw.browser
|
110
|
-
@browser.follow_meta_refresh = false
|
111
|
-
@schedule = @myuw.schedule
|
112
|
-
|
113
|
-
# Fetch them once
|
114
|
-
fixture_page = @browser.get(path_to_html("schedule"))
|
115
|
-
@browser.expects(:get).returns(fixture_page)
|
116
|
-
|
117
|
-
assert_nothing_raised { @schedule.schedule }
|
118
|
-
end
|
119
|
-
|
120
|
-
should "not call any helper methods when getting schedule" do
|
121
|
-
@browser.expects(:get).never
|
122
|
-
|
123
|
-
@schedule.schedule
|
124
|
-
end
|
125
|
-
|
126
|
-
should "not call any helper methods when getting credits" do
|
127
|
-
@schedule.expects(:schedule).never
|
128
|
-
|
129
|
-
@schedule.credits
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
data/test/mocked/session_test.rb
DELETED
@@ -1,96 +0,0 @@
|
|
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 ArgumentError 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 MyUW::InvalidPageError 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 MyUW::InvalidPageError 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
|