Class: ATM::Services::TestCase

Inherits:
Base
  • Object
show all
Includes:
Helper::TestCase
Defined in:
lib/atm_ruby/services/test_case.rb

Overview

ATM::Services::TestCase provides methods for working with test cases

Instance Attribute Summary collapse

Attributes inherited from Base

#[], #auth_header, #header, #response

Instance Method Summary collapse

Methods included from Helper::TestCase

#retrive_based_on_username

Methods inherited from Base

#set_response

Constructor Details

#initialize(**options) ⇒ TestCase

Returns a new instance of TestCase.



13
14
15
16
17
# File 'lib/atm_ruby/services/test_case.rb', line 13

def initialize(**options)
  @project_id = options.delete(:project_id)
  @environment = options.delete(:environment)
  super(options)
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



11
12
13
# File 'lib/atm_ruby/services/test_case.rb', line 11

def environment
  @environment
end

#project_idObject

Returns the value of attribute project_id.



11
12
13
# File 'lib/atm_ruby/services/test_case.rb', line 11

def project_id
  @project_id
end

Instance Method Details

#add_attachment(_test_case_id) ⇒ Object

Adds attachment to a test case

Examples:

Add attachment to an existed test case

Parameters:

  • tese_case_id (String)


91
92
93
94
95
96
# File 'lib/atm_ruby/services/test_case.rb', line 91

def add_attachment(_test_case_id) # TODO: need to fix this.
  warn 'Not implemented at the moment'
  # self.class.get("/rest/kanoahtests/1.0/testcase/#{test_case_id}/attachment", headers: auth_header).tap do |res|
  #   raise ATM::TestCaseError, response unless response.code == 201
  # end
end

#create(body) ⇒ Object

Creates new test case

Examples:

Create new test case

ATM::Client.new.TestCase.create({"projectKey": "JQA", "name": "Ensure the axial-flow pump is enabled"})

Parameters:

  • body (Hash)


26
27
28
29
30
31
# File 'lib/atm_ruby/services/test_case.rb', line 26

def create(body)
  self.class.post('/rest/kanoahtests/1.0/testcase', body: body.to_json, headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestCaseError, response unless code == 201
  end
end

#create_new_test_result(test_data) ⇒ Object

Create new result for test case

Examples:

test_data = { project: "GG", test_case: 'GG-T1'}
ATM::Client.new.TestCase.create_new_test_result(test_data)

Parameters:

  • test_data (Hash)


106
107
108
109
110
111
# File 'lib/atm_ruby/services/test_case.rb', line 106

def create_new_test_result(test_data)
  self.class.post('/rest/kanoahtests/1.0/testresult', body: test_data.to_json, headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestCaseError, response unless code == 200
  end
end

#delete(test_case_id) ⇒ Object

Deletes test case

Examples:

Delete existing test case

Parameters:

  • test_case_id (String)


52
53
54
55
56
57
# File 'lib/atm_ruby/services/test_case.rb', line 52

def delete(test_case_id)
  self.class.delete("/rest/kanoahtests/1.0/testcase/#{test_case_id}", headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestCaseError, response unless code == 204
  end
end

#find(test_case_id) ⇒ Object

Finds specific test case

Examples:

Find existing test case

Parameters:

  • test_case_id (String)


65
66
67
68
69
70
# File 'lib/atm_ruby/services/test_case.rb', line 65

def find(test_case_id)
  self.class.get("/rest/kanoahtests/1.0/testcase/#{test_case_id}", headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestCaseError, response unless code == 200
  end
end

#process_result(test_data) ⇒ Object

Creates hash for new test result

Parameters:

  • test_data (Hash)


116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/atm_ruby/services/test_case.rb', line 116

def process_result(test_data)
  {
    'projectKey'    => test_data.fetch(:project_id, project_id),
    'testCaseKey'   => test_data[:test_case_id],
    'status'        => test_data.fetch(:status, nil),
    'environment'   => test_data.fetch(:environment, environment),
    'userKey'       => test_data.fetch(:username, nil),
    'comment'       => test_data.fetch(:comment, nil),
    'executionTime' => test_data.fetch(:execution_time, nil),
    'executionDate' => test_data.fetch(:execution_date, nil),
    'scriptResults' => test_data.fetch(:script_results, nil)
  }.delete_if { |_k, v| v.nil? }
end

#search(query_string) ⇒ Object

Searches for test cases based on the provided quiry

Examples:

Search for an existed test case

Parameters:

  • query_string (String)


78
79
80
81
82
83
# File 'lib/atm_ruby/services/test_case.rb', line 78

def search(query_string)
  self.class.get("/rest/kanoahtests/1.0/testcase/search?query=#{query_string}", headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestCaseError, response unless code == 200
  end
end

#update(test_case_id, body) ⇒ Object

Updates test case

Examples:

Update existing test case

Parameters:

  • test_case_id (String)


39
40
41
42
43
44
# File 'lib/atm_ruby/services/test_case.rb', line 39

def update(test_case_id, body)
  self.class.put("/rest/kanoahtests/1.0/testcase/#{test_case_id}", body: body.to_json, headers: auth_header).tap do |res|
    set_response(res)
    raise ATM::TestCaseError, response unless code == 200
  end
end