Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
rspec for workflow_job/job_node
Browse files Browse the repository at this point in the history
  • Loading branch information
mimodian committed Jun 20, 2018
1 parent fef3e37 commit 854a0a7
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
AnsibleTowerClient::Project,
AnsibleTowerClient::ProjectUpdate,
AnsibleTowerClient::WorkflowJob,
AnsibleTowerClient::WorkflowJobNode,
AnsibleTowerClient::WorkflowJobTemplate,
AnsibleTowerClient::WorkflowJobTemplateNode,
].freeze
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
trait(:project) { [description, organization] }
trait(:job_event) { [url] }
trait(:system_job_template) { [description, extra_vars] }
trait(:workflow_job) { [description, extra_vars] }
trait(:workflow_job_node) { [description, extra_vars] }
trait(:workflow_job_template) { [description, extra_vars] }
trait(:workflow_job_template_node) { [description, extra_vars] }

Expand Down
4 changes: 4 additions & 0 deletions spec/support/mock_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def get(path, get_options = nil)
wrap_response(Project.response)
when "me"
wrap_response(Me.response)
when "workflow_jobs"
wrap_response(WorkflowJob.response)
when "workflow_job_nodes"
wrap_response(WorkflowJobNode.response)
when "workflow_job_template_nodes"
wrap_response(WorkflowJobTemplateNode.response)
when "workflow_job_templates"
Expand Down
86 changes: 86 additions & 0 deletions spec/support/mock_api/workflow_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
module AnsibleTowerClient
class MockApi
module WorkflowJob
def self.collection
[
{
"id": 792,
"type": "workflow_job",
"url": "/api/v1/workflow_jobs/792/",
"related": {
"created_by": "/api/v1/users/1/",
"unified_job_template": "/api/v1/workflow_job_templates/345/",
"workflow_job_template": "/api/v1/workflow_job_templates/345/",
"notifications": "/api/v1/workflow_jobs/792/notifications/",
"workflow_nodes": "/api/v1/workflow_jobs/792/workflow_nodes/",
"labels": "/api/v1/workflow_jobs/792/labels/",
"activity_stream": "/api/v1/workflow_jobs/792/activity_stream/",
"relaunch": "/api/v1/workflow_jobs/792/relaunch/",
"cancel": "/api/v1/workflow_jobs/792/cancel/"
},
"summary_fields": {
"instance_group": {
"id": 1,
"name": "tower"
},
"workflow_job_template": {
"id": 345,
"name": "Demo-workflow (a expln)",
"description": ""
},
"unified_job_template": {
"id": 345,
"name": "Demo-workflow (a expln)",
"description": "",
"unified_job_type": "workflow_job"
},
"created_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"user_capabilities": {
"start": true,
"delete": true
},
"labels": {
"count": 0,
"results": []
}
},
"created": "2018-06-20T20:01:10.696Z",
"modified": "2018-06-20T20:01:32.763Z",
"name": "Demo-workflow (a expln)",
"description": "",
"unified_job_template": 345,
"launch_type": "relaunch",
"status": "successful",
"failed": false,
"started": "2018-06-20T20:01:10.873367Z",
"finished": "2018-06-20T20:01:32.758097Z",
"elapsed": 21.885,
"job_args": "",
"job_cwd": "",
"job_env": {},
"job_explanation": "",
"result_stdout": "stdout capture is missing",
"result_traceback": "",
"workflow_job_template": 345,
"extra_vars": "{\"colors\": [\"red\", \"blue\"], \"name\": \"test abc\"}",
"allow_simultaneous": false
}
]
end

def self.response
{
"count" => collection.length,
"next" => nil,
"previous" => nil,
"results" => collection
}.to_json
end
end
end
end
69 changes: 69 additions & 0 deletions spec/support/mock_api/workflow_job_node.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module AnsibleTowerClient
class MockApi
module WorkflowJobNode
def self.collection
[
{
"id": 1,
"type": "workflow_job_node",
"url": "/api/v1/workflow_job_nodes/1/",
"related": {
"unified_job_template": "/api/v1/job_templates/216/",
"success_nodes": "/api/v1/workflow_job_nodes/1/success_nodes/",
"failure_nodes": "/api/v1/workflow_job_nodes/1/failure_nodes/",
"always_nodes": "/api/v1/workflow_job_nodes/1/always_nodes/",
"job": "/api/v1/jobs/429/",
"workflow_job": "/api/v1/workflow_jobs/428/"
},
"summary_fields": {
"workflow_job": {
"id": 428,
"name": "james-wf2",
"description": ""
},
"job": {
"id": 429,
"name": "Demo Job Template",
"description": "",
"status": "successful",
"failed": false,
"elapsed": 6.344
},
"unified_job_template": {
"id": 216,
"name": "Demo Job Template",
"description": "",
"unified_job_type": "job"
}
},
"created": "2018-05-17T13:13:48.022Z",
"modified": "2018-05-17T13:13:51.562Z",
"unified_job_template": 216,
"success_nodes": [],
"failure_nodes": [],
"always_nodes": [
2
],
"inventory": nil,
"credential": nil,
"job_type": nil,
"job_tags": nil,
"skip_tags": nil,
"limit": nil,
"job": 429,
"workflow_job": 428
}
]
end

def self.response
{
"count" => collection.length,
"next" => nil,
"previous" => nil,
"results" => collection
}.to_json
end
end
end
end
18 changes: 18 additions & 0 deletions spec/workflow_job_node_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe AnsibleTowerClient::WorkflowJobNode do
let(:url) { "example.com/api/v1/workflow_job_nodes" }
let(:api) { AnsibleTowerClient::Api.new(AnsibleTowerClient::MockApi.new) }
let(:raw_instance) { build(:response_instance, :workflow_job_node, :klass => described_class) }

include_examples "Api Methods"
include_examples "Crud Methods"

it "#initialize instantiates an #{described_class} from a hash" do
obj = api.workflow_job_nodes.all.first

expect(obj).to be_a described_class
expect(obj.id).to be_a Integer
expect(obj.job_id).to be_a Integer
expect(obj.workflow_job_id).to be_a Integer
expect(obj.related).to be_a described_class::Related
end
end
18 changes: 18 additions & 0 deletions spec/workflow_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe AnsibleTowerClient::WorkflowJob do
let(:url) { "example.com/api/v1/workflow_jobs" }
let(:api) { AnsibleTowerClient::Api.new(AnsibleTowerClient::MockApi.new) }
let(:raw_instance) { build(:response_instance, :workflow_job, :klass => described_class) }

include_examples "Api Methods"
include_examples "Crud Methods"

it "#initialize instantiates an #{described_class} from a hash" do
obj = api.workflow_jobs.all.first

expect(obj).to be_a described_class
expect(obj.id).to be_a Integer
expect(obj.name).to be_a String
expect(obj.workflow_job_nodes).to be_a Enumerator
expect(obj.related).to be_a described_class::Related
end
end

0 comments on commit 854a0a7

Please sign in to comment.