File: exception_test.rb

package info (click to toggle)
ruby-openstack 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 3,217; makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,746 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require File.dirname(__FILE__) + '/../test_helper'

class ExceptionTest < Test::Unit::TestCase
  def test_400_cloud_servers_fault
    response = mock()
    response.stubs(:code => "400", :body => "{\"ComputeFault\":{\"message\":\"422 Unprocessable Entity: We could not process your request at this time. We have been notified and are looking into the issue.  [E03]\",\"details\":\"com.rackspace.cloud.service.servers.OpenStack::ComputeFault: Fault occured\",\"code\":400}}" )
    exception=nil
    begin
      OpenStack::Exception.raise_exception(response)
    rescue Exception => e
      exception=e
    end
    assert_equal(OpenStack::Exception::ComputeFault, e.class)
    assert_equal("400", e.response_code)
    assert_not_nil(e.response_body)
  end

  def test_413_over_limit
    response = mock()
    response.stubs(:code => "413", :body => "{\"overLimit\":{\"message\":\"Too many requests...\",\"code\":413,\"retryAfter\":\"2010-08-25T10:47:57.890-05:00\"}}")
    exception=nil
    begin
      OpenStack::Exception.raise_exception(response)
    rescue Exception => e
      exception=e
    end
    assert_equal(OpenStack::Exception::OverLimit, e.class)
    assert_equal("413", e.response_code)
    assert_not_nil(e.response_body)
  end

  def test_other
    response = mock()
    body="{\"blahblah\":{\"message\":\"Failed...\",\"code\":500}}"
    response.stubs(:code => "500", :body => body)
    exception=nil
    begin
      OpenStack::Exception.raise_exception(response)
    rescue Exception => e
      exception=e
    end
    assert_equal(OpenStack::Exception::Other, exception.class)
    assert_equal("500", exception.response_code)
    assert_not_nil(exception.response_body)
    assert_equal(body, exception.response_body)
  end
end