dcuddeback-octopi 0.2.8

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.
Files changed (58) hide show
  1. data/.gitignore +4 -0
  2. data/.yardoc +0 -0
  3. data/CHANGELOG.md +9 -0
  4. data/LICENSE +20 -0
  5. data/README.markdown +144 -0
  6. data/Rakefile +94 -0
  7. data/VERSION.yml +4 -0
  8. data/contrib/backup.rb +100 -0
  9. data/dcuddeback-octopi.gemspec +108 -0
  10. data/examples/authenticated.rb +20 -0
  11. data/examples/issues.rb +18 -0
  12. data/examples/overall.rb +50 -0
  13. data/lib/ext/string_ext.rb +5 -0
  14. data/lib/octopi/api.rb +213 -0
  15. data/lib/octopi/base.rb +115 -0
  16. data/lib/octopi/blob.rb +25 -0
  17. data/lib/octopi/branch.rb +31 -0
  18. data/lib/octopi/branch_set.rb +11 -0
  19. data/lib/octopi/comment.rb +20 -0
  20. data/lib/octopi/commit.rb +69 -0
  21. data/lib/octopi/deploy_key.rb +27 -0
  22. data/lib/octopi/deploy_key_set.rb +18 -0
  23. data/lib/octopi/error.rb +35 -0
  24. data/lib/octopi/file_object.rb +16 -0
  25. data/lib/octopi/gist.rb +28 -0
  26. data/lib/octopi/issue.rb +111 -0
  27. data/lib/octopi/issue_comment.rb +7 -0
  28. data/lib/octopi/issue_set.rb +21 -0
  29. data/lib/octopi/key.rb +25 -0
  30. data/lib/octopi/key_set.rb +14 -0
  31. data/lib/octopi/plan.rb +5 -0
  32. data/lib/octopi/repository.rb +136 -0
  33. data/lib/octopi/repository_set.rb +9 -0
  34. data/lib/octopi/resource.rb +70 -0
  35. data/lib/octopi/self.rb +33 -0
  36. data/lib/octopi/tag.rb +23 -0
  37. data/lib/octopi/user.rb +131 -0
  38. data/lib/octopi.rb +135 -0
  39. data/test/api_test.rb +58 -0
  40. data/test/authenticated_test.rb +39 -0
  41. data/test/base_test.rb +20 -0
  42. data/test/blob_test.rb +23 -0
  43. data/test/branch_test.rb +20 -0
  44. data/test/commit_test.rb +82 -0
  45. data/test/file_object_test.rb +39 -0
  46. data/test/gist_test.rb +16 -0
  47. data/test/issue_comment.rb +19 -0
  48. data/test/issue_set_test.rb +33 -0
  49. data/test/issue_test.rb +120 -0
  50. data/test/key_set_test.rb +29 -0
  51. data/test/key_test.rb +35 -0
  52. data/test/repository_set_test.rb +23 -0
  53. data/test/repository_test.rb +151 -0
  54. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  55. data/test/tag_test.rb +20 -0
  56. data/test/test_helper.rb +246 -0
  57. data/test/user_test.rb +92 -0
  58. metadata +151 -0
data/lib/octopi.rb ADDED
@@ -0,0 +1,135 @@
1
+ require 'rubygems'
2
+
3
+ require 'httparty'
4
+ require 'mechanize'
5
+ require 'nokogiri'
6
+ require 'api_cache'
7
+
8
+ require 'yaml'
9
+ require 'pp'
10
+
11
+ # Core extension stuff
12
+ Dir[File.join(File.dirname(__FILE__), "ext/*.rb")].each { |f| require f }
13
+
14
+ # Octopi stuff
15
+ # By sorting them we ensure that api and base are loaded first on all sane operating systems
16
+ Dir[File.join(File.dirname(__FILE__), "octopi/*.rb")].sort.each { |f| require f }
17
+
18
+ # Include this into your app so you can access the child classes easier.
19
+ # This is the root of all things Octopi.
20
+ module Octopi
21
+
22
+ # The authenticated methods are all very similar.
23
+ # TODO: Find a way to merge them into something... better.
24
+
25
+ def authenticated(options={}, &block)
26
+ begin
27
+ config = config = File.open(options[:config]) { |yf| YAML::load(yf) } if options[:config]
28
+ config = read_gitconfig
29
+ options[:login] = config["github"]["user"]
30
+ options[:token] = config["github"]["token"]
31
+
32
+ authenticated_with(options) do
33
+ yield
34
+ end
35
+ ensure
36
+ # Reset authenticated so if we were to do an anonymous call it would Just Work(tm)
37
+ Api.authenticated = false
38
+ Api.api = AnonymousApi.instance
39
+ end
40
+ end
41
+
42
+ def authenticated_with(options, &block)
43
+ begin
44
+
45
+ if options[:token].nil? && !options[:password].nil?
46
+ options[:token] = grab_token(options[:login], options[:password])
47
+ end
48
+ begin
49
+ User.find(options[:login])
50
+ # If the user cannot see themselves then they are not logged in, tell them so
51
+ rescue Octopi::NotFound
52
+ raise Octopi::InvalidLogin
53
+ end
54
+
55
+ Api.api = AuthApi.instance
56
+ Api.api.trace_level = options[:trace] if options[:trace]
57
+ Api.api.login = options[:login]
58
+ Api.api.token = options[:token]
59
+
60
+ trace("=> Trace on: #{options[:trace]}")
61
+
62
+ yield
63
+ ensure
64
+ # Reset authenticated so if we were to do an anonymous call it would Just Work(tm)
65
+ Api.authenticated = false
66
+ Api.api = AnonymousApi.instance
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def grab_token(username, password)
73
+ a = Mechanize.new { |agent|
74
+ # Fake out the agent
75
+ agent.user_agent_alias = 'Mac Safari'
76
+ }
77
+
78
+ # Login with the provided
79
+ a.get('http://github.com/login') do |page|
80
+ user_page = page.form_with(:action => '/session') do |login|
81
+ login.login = username
82
+ login.password = password
83
+ end.submit
84
+
85
+
86
+ if Api.api.trace_level
87
+ File.open("got.html", "w+") do |f|
88
+ f.write user_page.body
89
+ end
90
+ `open got.html`
91
+ end
92
+
93
+ body = Nokogiri::HTML(user_page.body)
94
+ error = body.xpath("//div[@class='error_box']").text
95
+ raise error if error != ""
96
+
97
+ # Should be clear to go if there is no errors.
98
+ link = user_page.link_with(:text => "account")
99
+ @account_page = a.click(link)
100
+ if Api.api.trace_level
101
+ File.open("account.html", "w+") do |f|
102
+ f.write @account_page.body
103
+ end
104
+ `open account.html`
105
+ end
106
+
107
+ return Nokogiri::HTML(@account_page.body).xpath("//p").xpath("strong")[1].text
108
+ end
109
+ end
110
+
111
+
112
+ def read_gitconfig
113
+ config = {}
114
+ group = nil
115
+ File.foreach("#{ENV['HOME']}/.gitconfig") do |line|
116
+ line.strip!
117
+ if line[0] != ?# && line =~ /\S/
118
+ if line =~ /^\[(.*)\]$/
119
+ group = $1
120
+ config[group] ||= {}
121
+ else
122
+ key, value = line.split("=").map { |v| v.strip }
123
+ config[group][key] = value
124
+ end
125
+ end
126
+ end
127
+ config
128
+ end
129
+
130
+ def trace(text)
131
+ if Api.api.trace_level
132
+ puts text
133
+ end
134
+ end
135
+ end
data/test/api_test.rb ADDED
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class AuthenticatedTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ end
10
+
11
+ context "following" do
12
+
13
+ should "not be able to follow anyone if not authenticated" do
14
+ exception = assert_raise AuthenticationRequired do
15
+ Api.me.follow!("rails")
16
+ end
17
+ end
18
+
19
+ should "be able to follow a user" do
20
+ auth do
21
+ assert_not_nil Api.me.follow!("rails")
22
+ end
23
+ end
24
+ end
25
+
26
+ context "unfollowing" do
27
+
28
+ should "not be able to follow anyone if not authenticated" do
29
+ exception = assert_raise AuthenticationRequired do
30
+ Api.me.unfollow!("rails")
31
+ end
32
+ end
33
+
34
+ should "be able to follow a user" do
35
+ auth do
36
+ assert_not_nil Api.me.unfollow!("rails")
37
+ end
38
+ end
39
+ end
40
+
41
+ context "keys" do
42
+ should "not be able to see keys if not authenticated" do
43
+ exception = assert_raise AuthenticationRequired do
44
+ Api.me.keys
45
+ end
46
+
47
+ assert_equal "To view keys, you must be authenticated", exception.message
48
+ end
49
+
50
+ should "have some keys" do
51
+ auth do
52
+ keys = Api.me.keys
53
+ assert keys.is_a?(KeySet)
54
+ assert_equal 2, keys.size
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class AuthenticatedTest < Test::Unit::TestCase
4
+ include Octopi
5
+ def setup
6
+ fake_everything
7
+ end
8
+
9
+ context "Authenticating" do
10
+ should "be possible with username and password" do
11
+ authenticated_with(:login => "fcoury", :password => "yruocf") do
12
+ assert_equal "8f700e0d7747826f3e56ee13651414bd", Api.api.token
13
+ assert_not_nil User.find("fcoury")
14
+ end
15
+ end
16
+
17
+ should "be possible with username and token" do
18
+ auth do
19
+ assert_not_nil User.find("fcoury")
20
+ end
21
+ end
22
+
23
+ should "be possible using the .gitconfig" do
24
+ authenticated do
25
+ assert_not_nil User.find("fcoury")
26
+ end
27
+ end
28
+ #
29
+ # should "be denied access when specifying an invalid token and login combination" do
30
+ # FakeWeb.clean_registry
31
+ # FakeWeb.register_uri(:get, "http://github.com/api/v2/yaml/user/show/fcoury", :status => ["404", "Not Found"])
32
+ # assert_raise InvalidLogin do
33
+ # authenticated_with :login => "fcoury", :token => "ba7bf2d7f0ebc073d3874dda887b18ae" do
34
+ # # Just blank will do us fine.
35
+ # end
36
+ # end
37
+ # end
38
+ end
39
+ end
data/test/base_test.rb ADDED
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class BaseTest < Test::Unit::TestCase
4
+ class SparseUser < Octopi::Base
5
+ include Octopi::Resource
6
+
7
+ attr_accessor :some_attribute
8
+
9
+ find_path "/user/search/:query"
10
+ resource_path "/user/show/:id"
11
+ end
12
+
13
+ def setup
14
+ fake_everything
15
+ end
16
+
17
+ should "not raise an error if it doesn't know about the attributes that GitHub API provides" do
18
+ assert_nothing_raised { SparseUser.find("radar") }
19
+ end
20
+ end
data/test/blob_test.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class BlobTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ end
9
+
10
+ context Blob do
11
+ should "find a blob" do
12
+ blob = Blob.find(:user => "fcoury", :repo => "octopi", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
13
+ assert_not_nil blob
14
+ assert blob.is_a?(String)
15
+ end
16
+
17
+ # Can't grab real data for this yet, Github is throwing a 500 on this request.
18
+ # should "find a file for a blob" do
19
+ # assert_not_nil Blob.find(:user => "fcoury", :repo => "octopi", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae", :path => "lib/octopi.rb")
20
+ # end
21
+ end
22
+ end
23
+
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class BranchTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ end
9
+
10
+ context Branch do
11
+ should "Find all branches for a repository" do
12
+ assert_not_nil Branch.all(:user => "fcoury", :name => "octopi")
13
+ end
14
+
15
+ should "Be able to find a specific branch" do
16
+ assert_not_nil Branch.all(:user => "fcoury", :name => "octopi").find("lazy")
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,82 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class CommitTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository(:name => "octopi")
10
+ end
11
+
12
+ context Commit do
13
+ context "finding all commits" do
14
+ should "by strings" do
15
+ commits = Commit.find_all(:user => "fcoury", :repository => "octopi")
16
+ assert_not_nil commits
17
+ assert_equal 30, commits.size
18
+ assert_not_nil commits.first.repository
19
+ end
20
+
21
+ should "by objects" do
22
+ commits = Commit.find_all(:user => @user, :repository => @repo)
23
+ assert_not_nil commits
24
+ assert_equal 30, commits.size
25
+ end
26
+
27
+ should "be able to specify a branch" do
28
+ commits = Commit.find_all(:user => "fcoury", :repository => "octopi", :branch => "lazy")
29
+ assert_not_nil commits
30
+ assert_equal 30, commits.size
31
+ end
32
+
33
+ # Tests issue #28
34
+ should "be able to find commits in a private repository" do
35
+ auth do
36
+ commits = Commit.find_all(:user => "fcoury", :repository => "rboard")
37
+ end
38
+ assert_not_nil commits
39
+ assert_equal 22, commits.size
40
+ end
41
+
42
+ should "be able to find commits for a particular file" do
43
+ commits = Commit.find_all(:user => "fcoury", :repository => "octopi", :path => "lib/octopi.rb")
44
+ assert_not_nil commits
45
+ assert_equal 44, commits.size
46
+ end
47
+ end
48
+
49
+ context "finding a single commit" do
50
+ should "by strings" do
51
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
52
+ assert_not_nil commit
53
+ end
54
+
55
+ should "by objects" do
56
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
57
+ assert_not_nil commit
58
+ end
59
+
60
+ should "be able to specify a branch" do
61
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae", :branch => "lazy")
62
+ assert_not_nil commit
63
+ end
64
+
65
+ should "raise an error if not found" do
66
+ exception = assert_raise Octopi::NotFound do
67
+ Commit.find(:name => "octopi", :user => "fcoury", :sha => "nothere")
68
+ end
69
+
70
+ assert_equal "The Commit you were looking for could not be found, or is private.", exception.message
71
+ end
72
+ end
73
+
74
+ context "identifying a repository" do
75
+ should "be possible" do
76
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
77
+ assert_equal "fcoury/octopi/f6609209c3ac0badd004512d318bfaa508ea10ae", commit.repo_identifier
78
+ end
79
+ end
80
+ end
81
+ end
82
+
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class FileObjectTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repositories.find("octopi")
10
+ end
11
+
12
+ context "finding" do
13
+ context "with strings" do
14
+ should "work" do
15
+ FileObject.find(:user => "fcoury", :repository => "octopi", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
16
+ end
17
+ end
18
+
19
+ context "with objects" do
20
+ should "work" do
21
+ FileObject.find(:user => @user, :repository => @repo, :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
22
+ end
23
+ end
24
+
25
+ context "invalid sha" do
26
+ should "not work" do
27
+ # sha below is "ryan"
28
+ exception = assert_raise NotFound do
29
+ FileObject.find(:user => @user, :repository => @repo, :sha => "ea3cd978650417470535f3a4725b6b5042a6ab59")
30
+ end
31
+
32
+ assert_equal "The FileObject you were looking for could not be found, or is private.", exception.message
33
+
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
data/test/gist_test.rb ADDED
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class GistTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ end
9
+
10
+ context Gist do
11
+ should "Find a single gist" do
12
+ assert_not_nil Gist.find(159579)
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class IssueTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository("octopi")
10
+ end
11
+
12
+ context IssueComment do
13
+ should "be valid" do
14
+ comment = IssueComment.new({ :comment => "This is a comment", :status => "saved"})
15
+ assert_not_nil comment.comment
16
+ assert_not_nil comment.status
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class IssueSetTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository("octopi")
10
+ end
11
+
12
+
13
+ context IssueSet do
14
+ should "be able to find a specific issue" do
15
+ assert_not_nil @repo.issues.find(28)
16
+ end
17
+
18
+ should "not be able to find an issue that doesn't exist" do
19
+ exception = assert_raise Octopi::NotFound do
20
+ @repo.issues.find("not-a-number")
21
+ end
22
+
23
+ assert_equal "The Issue you were looking for could not be found, or is private.", exception.message
24
+ end
25
+
26
+ should "be able to look for an issue" do
27
+ results = @repo.issues.search(:keyword => "test")
28
+ assert_not_nil results
29
+ assert_equal 1, results.size
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,120 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class IssueTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository("octopi")
10
+ @issue = Issue.find(:user => @user, :repo => @repo, :number => 28)
11
+ @closed = Issue.find(:user => @user, :repo => @repo, :number => 27)
12
+ end
13
+
14
+
15
+ context Issue do
16
+ context "finding all the issues" do
17
+ should "using objects" do
18
+ issues = Issue.find_all(:user => @user, :repo => @repo)
19
+ assert_not_nil issues
20
+ assert_equal 21, issues.size
21
+ end
22
+
23
+ should "using strings" do
24
+ issues = Issue.find_all(:user => "fcoury", :repo => "octopi")
25
+ assert_not_nil issues
26
+ assert_equal 21, issues.size
27
+ end
28
+
29
+ should "specifying a state" do
30
+ issues = Issue.find_all(:user => @user, :repo => @repo, :state => "closed")
31
+ assert_not_nil issues
32
+ assert_equal 9, issues.size
33
+ end
34
+ end
35
+
36
+ context "finding a single issue" do
37
+ should "work" do
38
+ issue = Issue.find(:user => @user, :repo => @repo, :number => 28)
39
+ assert_not_nil issue
40
+ assert_not_nil issue.body
41
+ end
42
+
43
+ should "not work, if issue doesn't exist" do
44
+ exception = assert_raise NotFound do
45
+ Issue.find(:user => @user, :repo => @repo, :number => "not-a-number")
46
+ end
47
+
48
+ assert_equal "The Issue you were looking for could not be found, or is private.", exception.message
49
+ end
50
+
51
+ should "be able to look for an issue" do
52
+ results = Issue.search(:user => @user, :repo => @repo, :keyword => "test")
53
+ assert_not_nil results
54
+ assert_equal 1, results.size
55
+ end
56
+ end
57
+
58
+ context "actions" do
59
+ should "opening an issue" do
60
+ issue = Issue.open(:user => @user, :repo => @repo, :params => { :title => "something's broken", :body => "something broke" })
61
+ assert_not_nil issue
62
+ assert_equal "open", issue.state
63
+ end
64
+
65
+ should "re-opening an issue" do
66
+ assert_equal "closed", @closed.state
67
+ @closed.reopen!
68
+ assert_equal "open", @closed.state
69
+ end
70
+
71
+ should "closing an issue" do
72
+ assert_equal "open", @issue.state
73
+ @issue.close!
74
+ assert_equal "closed", @issue.state
75
+ end
76
+
77
+ should "editing an issue" do
78
+ @issue.title = 'Testing'
79
+ @issue.save
80
+ assert_equal "Testing", @issue.title
81
+ end
82
+
83
+ should "adding a label" do
84
+ assert @issue.labels.empty?
85
+ @issue.add_label("one-point-oh")
86
+ assert !@issue.labels.empty?
87
+ end
88
+
89
+ should "adding multiple labels" do
90
+ assert @issue.labels.empty?
91
+ @issue.add_label("one-point-oh", "maybe-two-point-oh")
92
+ assert !@issue.labels.empty?
93
+ assert 2, @issue.labels.size
94
+ end
95
+
96
+ should "removing a label" do
97
+ assert @issue.labels.empty?
98
+ @issue.add_label("one-point-oh")
99
+ assert !@issue.labels.empty?
100
+ @issue.remove_label("one-point-oh")
101
+ assert @issue.labels.empty?
102
+ end
103
+
104
+ should "removing multiple labels" do
105
+ assert @issue.labels.empty?
106
+ @issue.add_label("one-point-oh", "maybe-two-point-oh")
107
+ assert !@issue.labels.empty?
108
+ assert_equal 2, @issue.labels.size
109
+ @issue.remove_label("one-point-oh", "maybe-two-point-oh")
110
+ assert_equal 0, @issue.labels.size
111
+
112
+ end
113
+
114
+ should "be able to comment" do
115
+ comment = @issue.comment("Yes, it is broken.")
116
+ assert comment.is_a?(IssueComment)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class KeySetTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ end
10
+
11
+
12
+ context KeySet do
13
+ should "be able to find a key" do
14
+ auth do
15
+ assert_not_nil Api.me.keys.find("macbook")
16
+ end
17
+ end
18
+
19
+ should "not be able to find a key without a valid title" do
20
+ exception = assert_raise NotFound do
21
+ auth do
22
+ assert_not_nil Api.me.keys.find("windows-box")
23
+ end
24
+ end
25
+
26
+ assert_equal "The Key you were looking for could not be found, or is private.", exception.message
27
+ end
28
+ end
29
+ end
data/test/key_test.rb ADDED
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class KeyTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ auth do
10
+ @key = Api.me.keys.first
11
+ end
12
+ end
13
+
14
+ context Key do
15
+
16
+ should "be able to add a key" do
17
+ auth do
18
+ Key.add(:title => "other-computer", :key => "AAAAB3NzaC1yc2EAAAABIwAAAQEA0dyfPrSHHSVD0u3JQlJfLyUrEVeNDW+9imbMHwiuT/IStf8SOroRjWT+/S5cL9m6qmKQBIU4v3LUnMKLTHfiWlqICnTDVRHuSayrHGp193I9kTSGBdM7wFZ2E8hDv5OqXHvAKGmOJvl5RqK0d42mhoK/x3bLRMQXHxwSDmYIFLy9rXLMvbVbdFJbbcqXP6QjnP4fAeebvTnUs6bVzInL9nh8Tqb3qjB5qji2i0MiCz3IouuZonOlef/VEac3Zpm6NcI5rVthPsMY55G8BMu4rVEStbIUlAJPoSBzqOgEKEXQbmWLh3CZnOoqQlLwIIvrKlwnXx26M1b+oOFm8s712Q==")
19
+ end
20
+ end
21
+
22
+ should "be able to remove a key" do
23
+ auth do
24
+ assert_equal 2, Api.me.keys.size
25
+ @key.remove
26
+ # Just trust me on this one
27
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/user/keys" + auth_query, :response => stub_file(File.join("users", "key-removed")))
28
+ assert_equal 1, Api.me.keys.size
29
+ end
30
+ end
31
+
32
+
33
+
34
+ end
35
+ end