From 9a2674b7751c2a11af13cd62d84b03adfd445323 Mon Sep 17 00:00:00 2001 From: timalces Date: Fri, 8 Mar 2024 17:53:34 +0000 Subject: [PATCH 01/15] updated user sign up job --- app/jobs/user_signup_job.rb | 5 +++-- spec/jobs/user_signup_job_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/jobs/user_signup_job.rb b/app/jobs/user_signup_job.rb index e8796ba7..6af0bf36 100644 --- a/app/jobs/user_signup_job.rb +++ b/app/jobs/user_signup_job.rb @@ -23,7 +23,7 @@ def perform(user, cloud_service_config, **options) class Result include HttpRequests::ResultSyncer - property :cloud_user_id, from: :user_id, context: :cloud + property :cloud_user_id, from: :user_cloud_id, context: :cloud validates :cloud_user_id, presence: true, on: :cloud end @@ -47,7 +47,7 @@ def call private def url - "#{@cloud_service_config.user_handler_base_url}/create_user" + "#{@cloud_service_config.user_handler_base_url}/user" end def body @@ -59,6 +59,7 @@ def body project_id: @cloud_service_config.admin_project_id, }, username: @user.login, + name: @user.name, password: @user.foreign_password, email: @user.email } diff --git a/spec/jobs/user_signup_job_spec.rb b/spec/jobs/user_signup_job_spec.rb index 3c622c51..a16f5446 100644 --- a/spec/jobs/user_signup_job_spec.rb +++ b/spec/jobs/user_signup_job_spec.rb @@ -11,7 +11,7 @@ } describe "url" do - let(:user_service_path) { "/create_user" } + let(:user_service_path) { "/user" } subject { super().send(:url) } @@ -46,7 +46,7 @@ end describe "updating the user's details from the response" do - let(:user_service_path) { "/create_user" } + let(:user_service_path) { "/user" } context "when response does not contain expected fields" do let(:response_body) { {} } @@ -73,7 +73,7 @@ context "when response contains expected fields" do let(:cloud_user_id) { SecureRandom.uuid } - let(:response_body) { { "user_id" => cloud_user_id } } + let(:response_body) { { "user_cloud_id" => cloud_user_id } } before(:each) do stubs.post(user_service_path) { |env| [ 201, {}, response_body ] } From 2efd9fc6b692fe2e5ea9fe02ef46726265606540 Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 11 Mar 2024 12:17:46 +0000 Subject: [PATCH 02/15] updated team creation --- app/jobs/create_team_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/create_team_job.rb b/app/jobs/create_team_job.rb index f5236f6f..02a87259 100644 --- a/app/jobs/create_team_job.rb +++ b/app/jobs/create_team_job.rb @@ -26,7 +26,7 @@ class Result property :project_id, context: :cloud validates :project_id, presence: true, on: :cloud - property :billing_acct_id, from: :billing_account_id, context: :billing + property :billing_acct_id, context: :billing validates :billing_acct_id, presence: true, on: :billing end @@ -51,7 +51,7 @@ def call private def url - "#{@cloud_service_config.user_handler_base_url}/create_team" + "#{@cloud_service_config.user_handler_base_url}/team" end def body From 589007ba995331fc67eaaa27b37dd669c369921d Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 11 Mar 2024 14:06:13 +0000 Subject: [PATCH 03/15] updated create team role job --- app/jobs/create_team_role_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/create_team_role_job.rb b/app/jobs/create_team_role_job.rb index afbab854..73e3992a 100644 --- a/app/jobs/create_team_role_job.rb +++ b/app/jobs/create_team_role_job.rb @@ -64,7 +64,7 @@ def url end def path - "/create_team_role" + "/team_role" end def body From 58204e1c4da6d6405935556440c83a0f0d732237 Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 11 Mar 2024 17:16:43 +0000 Subject: [PATCH 04/15] updated delete team job --- app/jobs/delete_team_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/delete_team_job.rb b/app/jobs/delete_team_job.rb index 9a7bfc64..b91dccaa 100644 --- a/app/jobs/delete_team_job.rb +++ b/app/jobs/delete_team_job.rb @@ -56,7 +56,7 @@ def call def url url = URI(@cloud_service_config.user_handler_base_url) - url.path = "/delete_team" + url.path = "/team" url.to_s end From 5c7b1068b13e3383fd503e2058aa416b0aa3c7c5 Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 11 Mar 2024 17:46:45 +0000 Subject: [PATCH 05/15] updated update team role job --- app/jobs/update_team_role_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/update_team_role_job.rb b/app/jobs/update_team_role_job.rb index b8f06bfa..43cb4657 100644 --- a/app/jobs/update_team_role_job.rb +++ b/app/jobs/update_team_role_job.rb @@ -44,7 +44,7 @@ def test_stubs end def call - response = super + response = connection.patch("", body) unless response.success? return Result.new(false, "#{error_description}: #{response.reason_phrase || "Unknown error"}") @@ -67,7 +67,7 @@ def call private def url - "#{@cloud_service_config.user_handler_base_url}/update_team_role" + "#{@cloud_service_config.user_handler_base_url}/team_role" end def body From ab49046411219ea74fbf81392f885b591249f045 Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 11 Mar 2024 18:07:20 +0000 Subject: [PATCH 06/15] updated delete team role job --- app/jobs/delete_team_role_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/delete_team_role_job.rb b/app/jobs/delete_team_role_job.rb index 184ae030..b6180754 100644 --- a/app/jobs/delete_team_role_job.rb +++ b/app/jobs/delete_team_role_job.rb @@ -71,7 +71,7 @@ def url end def path - "/delete_team_role" + "/team_role" end def body From 083e9a3a61786ea0cda96d2f1629015405470e0b Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 11 Mar 2024 19:05:21 +0000 Subject: [PATCH 07/15] updated create credit deposit job --- app/jobs/create_credit_deposit_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/create_credit_deposit_job.rb b/app/jobs/create_credit_deposit_job.rb index 82207573..490733c3 100644 --- a/app/jobs/create_credit_deposit_job.rb +++ b/app/jobs/create_credit_deposit_job.rb @@ -54,14 +54,14 @@ def url end def path - "/add_credits" + "/credits" end def body { credits: { - billing_account_id: @credit_deposit.billing_acct_id, - credits_to_add: @credit_deposit.amount + billing_acct_id: @credit_deposit.billing_acct_id, + amount: @credit_deposit.amount } } end From 53227ca4ce95cb7e05e6e969c5362836e83036e8 Mon Sep 17 00:00:00 2001 From: timalces Date: Tue, 12 Mar 2024 12:10:11 +0000 Subject: [PATCH 08/15] updated user deletion job --- app/jobs/user_deletion_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/user_deletion_job.rb b/app/jobs/user_deletion_job.rb index 43f68aab..dd608da8 100644 --- a/app/jobs/user_deletion_job.rb +++ b/app/jobs/user_deletion_job.rb @@ -55,7 +55,7 @@ def call def url url = URI(@cloud_service_config.user_handler_base_url) - url.path = "/delete_user" + url.path = "/user" url.to_s end From c650ba81536af47de0e0a3f02e17d89e99f3e892 Mon Sep 17 00:00:00 2001 From: timalces Date: Tue, 12 Mar 2024 12:42:52 +0000 Subject: [PATCH 09/15] updated user update job --- app/jobs/user_update_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/user_update_job.rb b/app/jobs/user_update_job.rb index 66f22e21..bf1d464d 100644 --- a/app/jobs/user_update_job.rb +++ b/app/jobs/user_update_job.rb @@ -32,7 +32,7 @@ def test_stubs end def call - response = super + response = connection.patch("", body) if response.success? @user.foreign_password = @user.pending_foreign_password @user.pending_foreign_password = nil @@ -44,7 +44,7 @@ def call def url url = URI(@cloud_service_config.user_handler_base_url) - url.path = "/change_user_details" + url.path = "/user" url.to_s end From 61fd888aec918cc08080a3597794867f2b4ba522 Mon Sep 17 00:00:00 2001 From: timalces Date: Tue, 12 Mar 2024 16:55:29 +0000 Subject: [PATCH 10/15] updated key pair management --- app/controllers/key_pairs_controller.rb | 2 +- app/jobs/get_user_key_pairs_job.rb | 3 +-- app/views/key_pairs/_form.html.erb | 4 ++-- config/navigation.rb | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/key_pairs_controller.rb b/app/controllers/key_pairs_controller.rb index 122b1c59..031cfeb9 100644 --- a/app/controllers/key_pairs_controller.rb +++ b/app/controllers/key_pairs_controller.rb @@ -101,6 +101,6 @@ def key_pair_params # key pairs are user (not project) specific, but membership of a project is required # to view, create and delete them def set_project_id - @project_id = current_user.teams.where.not(project_id: nil).first&.project_id + @project_id = current_user.teams.where.not(project_id: nil).where(deleted_at: nil).first&.project_id end end diff --git a/app/jobs/get_user_key_pairs_job.rb b/app/jobs/get_user_key_pairs_job.rb index c4dd1c05..0afcf209 100644 --- a/app/jobs/get_user_key_pairs_job.rb +++ b/app/jobs/get_user_key_pairs_job.rb @@ -49,8 +49,7 @@ def call end results = response.body - key_pairs = results["key_pairs"].map do |key_pair| - details = key_pair["keypair"] + key_pairs = results["key_pairs"].map do |details| KeyPair.new(user: @user, name: details["name"], fingerprint: details["fingerprint"], key_type: details["type"] || "ssh") end return Result.new(true, key_pairs, "") diff --git a/app/views/key_pairs/_form.html.erb b/app/views/key_pairs/_form.html.erb index 4a9e2398..790731c1 100644 --- a/app/views/key_pairs/_form.html.erb +++ b/app/views/key_pairs/_form.html.erb @@ -14,12 +14,12 @@
<%= f.label :name, "Key name", class: 'required_field' %> - <%= f.text_field :name, autocomplete: :off, pattern: "^[a-zA-Z][a-zA-Z0-9\\-_]*$" %> + <%= f.text_field :name, autocomplete: :off, pattern: "^[a-zA-Z][a-zA-Z0-9\\-_]*$", required: true %>
<%= f.label :key_type, "Key type", class: 'required_field' %> - <%= f.select :key_type, [["SSH Key", "ssh"]] %> + <%= f.select :key_type, [["SSH Key", "ssh"]], required: true %>
diff --git a/config/navigation.rb b/config/navigation.rb index 7e40ebc8..7c0098d9 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -8,7 +8,7 @@ primary.item :youraccount, "#{current_user.name}", '#', align: :right, icon: :youraccount, - highlights_on: %r(/accounts|/key_pairs/) do |acc| + highlights_on: %r(/accounts|/key_pairs/|/key_pairs) do |acc| acc.item :acc_details, 'Account details', url_helpers.edit_user_registration_path, :icon => :details, :link => {:class => 'details'} unless current_user.root? acc.item :acc_details, 'Manage key-pairs', url_helpers.key_pairs_path, From 64bba6ef9f0a14d374f8d8dad357688fc6d7a728 Mon Sep 17 00:00:00 2001 From: timalces Date: Tue, 12 Mar 2024 17:58:34 +0000 Subject: [PATCH 11/15] updated invoice related jobs --- app/jobs/get_draft_invoice_job.rb | 2 +- app/jobs/get_invoice_job.rb | 4 ++-- app/jobs/get_invoices_job.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/jobs/get_draft_invoice_job.rb b/app/jobs/get_draft_invoice_job.rb index 57216cfb..a09473a7 100644 --- a/app/jobs/get_draft_invoice_job.rb +++ b/app/jobs/get_draft_invoice_job.rb @@ -71,7 +71,7 @@ def url def body { invoice: { - billing_account_id: @team.billing_acct_id, + billing_acct_id: @team.billing_acct_id, target_date: Date.today.to_formatted_s(:iso8601), }, } diff --git a/app/jobs/get_invoice_job.rb b/app/jobs/get_invoice_job.rb index 9682a159..715935f6 100644 --- a/app/jobs/get_invoice_job.rb +++ b/app/jobs/get_invoice_job.rb @@ -28,7 +28,7 @@ def invoice private def parse_body(body) - @invoice = parse_invoice(body["account_invoice"]) + @invoice = parse_invoice(body["invoice"]) end end @@ -71,7 +71,7 @@ def url def body { invoice: { - billing_account_id: @team.billing_acct_id, + billing_acct_id: @team.billing_acct_id, invoice_id: @invoice_id, }, } diff --git a/app/jobs/get_invoices_job.rb b/app/jobs/get_invoices_job.rb index 1f9c0eb9..f30c5f57 100644 --- a/app/jobs/get_invoices_job.rb +++ b/app/jobs/get_invoices_job.rb @@ -74,7 +74,7 @@ def url def body { invoices: { - billing_account_id: @team.billing_acct_id, + billing_acct_id: @team.billing_acct_id, offset: @offset, limit: @limit, }, From 62c77462cd6aece43da8835b56d2654e6a7ad0d9 Mon Sep 17 00:00:00 2001 From: timalces Date: Thu, 14 Mar 2024 15:01:21 +0000 Subject: [PATCH 12/15] devices may have dots in name --- app/models/device.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/device.rb b/app/models/device.rb index f3907043..7abd0e91 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -47,8 +47,8 @@ class Device < ApplicationRecord presence: true, length: { maximum: 150 }, format: { - with: /\A[a-zA-Z0-9\-]*\Z/, - message: "can contain only alphanumeric characters and hyphens." + with: /\A[a-zA-Z0-9\-\.]*\Z/, + message: "can contain only alphanumeric characters, dots and hyphens." } validates :status, presence: true, From 47bd57d4bbd0d5f2279b75c98327a9b84a5249a4 Mon Sep 17 00:00:00 2001 From: timalces Date: Wed, 20 Mar 2024 16:55:45 +0000 Subject: [PATCH 13/15] updated tests --- app/jobs/create_team_job.rb | 2 +- app/jobs/create_team_role_job.rb | 15 +++++------ spec/jobs/create_credit_deposit_job_spec.rb | 8 +++--- spec/jobs/create_team_role_job_spec.rb | 29 +++++++++++---------- spec/jobs/create_team_then_role_job_spec.rb | 4 +-- spec/jobs/delete_team_job_spec.rb | 2 +- spec/jobs/delete_team_role_job_spec.rb | 8 ++---- spec/jobs/get_draft_invoice_job_spec.rb | 2 +- spec/jobs/update_team_role_job_spec.rb | 8 +++--- spec/jobs/user_deletion_job_spec.rb | 2 +- spec/jobs/user_update_job_spec.rb | 6 ++--- spec/support/shared_examples/jobs.rb | 8 +++--- 12 files changed, 45 insertions(+), 49 deletions(-) diff --git a/app/jobs/create_team_job.rb b/app/jobs/create_team_job.rb index 02a87259..283fbe64 100644 --- a/app/jobs/create_team_job.rb +++ b/app/jobs/create_team_job.rb @@ -65,7 +65,7 @@ def body name: @team.name }.tap do |h| h[:project_id] = @team.project_id unless @team.project_id.blank? - h[:billing_account_id] = @team.billing_acct_id unless @team.billing_acct_id.blank? + h[:billing_acct_id] = @team.billing_acct_id unless @team.billing_acct_id.blank? end end end diff --git a/app/jobs/create_team_role_job.rb b/app/jobs/create_team_role_job.rb index 73e3992a..8b8b985d 100644 --- a/app/jobs/create_team_role_job.rb +++ b/app/jobs/create_team_role_job.rb @@ -33,12 +33,15 @@ class Runner < HttpRequests::Faraday::JobRunner def initialize(team_role:, **kwargs) @team_role = team_role - super(**kwargs) + super(**kwargs.reverse_merge(test_stubs: test_stubs)) end - def call - response = connection.post(path, body) + def test_stubs + nil + end + def call + response = super unless response.success? return Result.new(false, "#{error_description}: #{response.reason_phrase || "Unknown error"}") end @@ -60,11 +63,7 @@ def call private def url - @cloud_service_config.user_handler_base_url - end - - def path - "/team_role" + "#{@cloud_service_config.user_handler_base_url}/team_role" end def body diff --git a/spec/jobs/create_credit_deposit_job_spec.rb b/spec/jobs/create_credit_deposit_job_spec.rb index dfa66ede..605321eb 100644 --- a/spec/jobs/create_credit_deposit_job_spec.rb +++ b/spec/jobs/create_credit_deposit_job_spec.rb @@ -4,7 +4,7 @@ let(:stubs) { Faraday::Adapter::Test::Stubs.new } let(:cloud_service_config) { create(:cloud_service_config) } let(:team) { create(:team, :with_openstack_details) } - let(:path) { "#{cloud_service_config.user_handler_base_url}/add_credits" } + let(:path) { "#{cloud_service_config.user_handler_base_url}/credits" } let(:credit_deposit) { build(:credit_deposit, team: team) } subject { CreateCreditDepositJob::Runner.new(credit_deposit: credit_deposit, cloud_service_config: cloud_service_config) } @@ -21,7 +21,7 @@ class << subject end it "uses a hard-coded path" do - expect(subject.path).to eq "/add_credits" + expect(subject.path).to eq "/credits" end end @@ -76,8 +76,8 @@ class << subject it 'contains credit deposit details' do expect(subject[:credits]).to eq({ - "billing_account_id" => credit_deposit.billing_acct_id, - "credits_to_add" => credit_deposit.amount + "billing_acct_id" => credit_deposit.billing_acct_id, + "amount" => credit_deposit.amount }) end end diff --git a/spec/jobs/create_team_role_job_spec.rb b/spec/jobs/create_team_role_job_spec.rb index c725d28e..925657cb 100644 --- a/spec/jobs/create_team_role_job_spec.rb +++ b/spec/jobs/create_team_role_job_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -RSpec.describe UpdateTeamRoleJob, type: :job do +RSpec.describe CreateTeamRoleJob, type: :job do let(:stubs) { Faraday::Adapter::Test::Stubs.new } - let!(:team_role) { create(:team_role, role: "member") } + let!(:team_role) { build(:team_role, role: "member") } let(:new_role) { "admin" } let(:cloud_service_config) { create(:cloud_service_config) } - let(:update_team_roles_path) { "/update_team_role" } + let(:create_team_roles_path) { "/team_role" } let(:expected_url) { - "#{cloud_service_config.user_handler_base_url}#{update_team_roles_path}" + "#{cloud_service_config.user_handler_base_url}#{create_team_roles_path}" } - subject { UpdateTeamRoleJob::Runner.new(cloud_service_config: cloud_service_config, team_role: team_role, new_role: new_role) } + subject { CreateTeamRoleJob::Runner.new(cloud_service_config: cloud_service_config, team_role: team_role) } describe "url" do subject { super().send(:url) } @@ -32,10 +32,11 @@ }) end - it "contains the team role's project and billing ids" do + it "contains the team role's details" do expect(subject[:team_role]).to be_a Hash expect(subject[:team_role][:user_id]).to eq team_role.user.cloud_user_id expect(subject[:team_role][:project_id]).to eq team_role.team.project_id + expect(subject[:team_role][:role]).to eq team_role.role end end @@ -44,12 +45,12 @@ shared_examples "makes a request to the middleware" do it "makes a request to the middleware" do - runner = described_class::Runner.new(team_role: team_role, new_role: new_role, cloud_service_config: cloud_service_config) + runner = described_class::Runner.new(team_role: team_role, cloud_service_config: cloud_service_config) expect(described_class::Runner).to receive(:new) - .with(hash_including(team_role: team_role, new_role: new_role, cloud_service_config: cloud_service_config)) + .with(hash_including(team_role: team_role, cloud_service_config: cloud_service_config)) .and_return(runner) allow(runner).to receive(:call).and_call_original - described_class.perform_now(team_role, new_role, cloud_service_config) + described_class.perform_now(team_role, cloud_service_config) expect(runner).to have_received(:call) end end @@ -62,10 +63,10 @@ include_examples "makes a request to the middleware" - it "updates role" do + it "persists role" do expect { - described_class.perform_now(team_role, new_role, cloud_service_config, test_stubs: stubs) - }.to change(team_role, :role) + described_class.perform_now(team_role, cloud_service_config, test_stubs: stubs) + }.to change(TeamRole, :count).by(1) end end @@ -79,8 +80,8 @@ it "does not change the role" do expect { - described_class.perform_now(team_role, new_role ,cloud_service_config) - }.not_to change(team_role, :role) + described_class.perform_now(team_role,cloud_service_config) + }.not_to change(TeamRole, :count) end end end diff --git a/spec/jobs/create_team_then_role_job_spec.rb b/spec/jobs/create_team_then_role_job_spec.rb index 00d94ec1..20fcb05e 100644 --- a/spec/jobs/create_team_then_role_job_spec.rb +++ b/spec/jobs/create_team_then_role_job_spec.rb @@ -14,7 +14,7 @@ include_examples 'creating team job' describe "creating role on success" do - let(:team_service_path) { "/create_team" } + let(:team_service_path) { "/team" } before(:each) do clear_enqueued_jobs @@ -25,7 +25,7 @@ let(:project_id) { SecureRandom.uuid } let(:billing_acct_id) { SecureRandom.uuid } let(:response_body) { - {project_id: project_id, billing_account_id: billing_acct_id} + {project_id: project_id, billing_acct_id: billing_acct_id} .stringify_keys } diff --git a/spec/jobs/delete_team_job_spec.rb b/spec/jobs/delete_team_job_spec.rb index ed14ecd7..8c23bbe5 100644 --- a/spec/jobs/delete_team_job_spec.rb +++ b/spec/jobs/delete_team_job_spec.rb @@ -4,7 +4,7 @@ let(:stubs) { Faraday::Adapter::Test::Stubs.new } let!(:team) { create(:team, :with_openstack_details) } let(:cloud_service_config) { create(:cloud_service_config) } - let(:delete_team_path) { "/delete_team" } + let(:delete_team_path) { "/team" } let(:expected_url) { "#{cloud_service_config.user_handler_base_url}#{delete_team_path}" } diff --git a/spec/jobs/delete_team_role_job_spec.rb b/spec/jobs/delete_team_role_job_spec.rb index 8ec999a9..145b3387 100644 --- a/spec/jobs/delete_team_role_job_spec.rb +++ b/spec/jobs/delete_team_role_job_spec.rb @@ -4,8 +4,8 @@ let(:stubs) { Faraday::Adapter::Test::Stubs.new } let!(:team_role) { create(:team_role, role: "member") } let(:cloud_service_config) { create(:cloud_service_config) } - let(:delete_team_role_path) { "/delete_team_role" } - let(:path) { "#{cloud_service_config.user_handler_base_url}/delete_team_role" } + let(:delete_team_role_path) { "/team_role" } + let(:path) { "#{cloud_service_config.user_handler_base_url}#{delete_team_role_path}" } subject { DeleteTeamRoleJob::Runner.new(cloud_service_config: cloud_service_config, team_role: team_role) } @@ -20,10 +20,6 @@ class << subject it "uses the ip and port given in the config" do expect(subject.connection.url_prefix.to_s).to eq "#{cloud_service_config.user_handler_base_url}/" end - - it "uses a hard-coded path" do - expect(subject.path).to eq "/delete_team_role" - end end describe "path" do diff --git a/spec/jobs/get_draft_invoice_job_spec.rb b/spec/jobs/get_draft_invoice_job_spec.rb index b232c03c..a4b6d26b 100644 --- a/spec/jobs/get_draft_invoice_job_spec.rb +++ b/spec/jobs/get_draft_invoice_job_spec.rb @@ -28,7 +28,7 @@ it "contains invoice config" do expect(subject[:invoice]).to eq({ - "billing_account_id" => team.billing_acct_id, + "billing_acct_id" => team.billing_acct_id, "target_date" => "#{Date.today.year}-#{"%02d" % Date.today.month}-#{"%02d" % Date.today.day}", }) end diff --git a/spec/jobs/update_team_role_job_spec.rb b/spec/jobs/update_team_role_job_spec.rb index 1fd6fea1..fee898f9 100644 --- a/spec/jobs/update_team_role_job_spec.rb +++ b/spec/jobs/update_team_role_job_spec.rb @@ -5,9 +5,9 @@ let!(:team_role) { create(:team_role, role: "member") } let(:new_role) { "admin" } let(:cloud_service_config) { create(:cloud_service_config) } - let(:update_users_path) { "/update_team_role" } + let(:update_roles_path) { "/team_role" } let(:expected_url) { - "#{cloud_service_config.user_handler_base_url}#{update_users_path}" + "#{cloud_service_config.user_handler_base_url}#{update_roles_path}" } subject { UpdateTeamRoleJob::Runner.new(cloud_service_config: cloud_service_config, team_role: team_role, new_role: new_role) } @@ -56,7 +56,7 @@ context "when the request is successful" do before(:each) do - stubs.post(expected_url) { |env| [ 204, {}, "No Content"] } + stubs.patch(expected_url) { |env| [ 204, {}, "No Content"] } allow_any_instance_of(described_class::Runner).to receive(:test_stubs).and_return(stubs) end @@ -71,7 +71,7 @@ context "when the request is unsuccessful" do before(:each) do - stubs.post(expected_url) { |env| [ 500, {}, {"error" => "Some error message"}] } + stubs.patch(expected_url) { |env| [ 500, {}, {"error" => "Some error message"}] } allow_any_instance_of(described_class::Runner).to receive(:test_stubs).and_return(stubs) end diff --git a/spec/jobs/user_deletion_job_spec.rb b/spec/jobs/user_deletion_job_spec.rb index 04e0e0c4..7c86f19c 100644 --- a/spec/jobs/user_deletion_job_spec.rb +++ b/spec/jobs/user_deletion_job_spec.rb @@ -4,7 +4,7 @@ let(:stubs) { Faraday::Adapter::Test::Stubs.new } let!(:user) { create(:user, :with_openstack_account) } let(:cloud_service_config) { create(:cloud_service_config) } - let(:delete_user_path) { "/delete_user" } + let(:delete_user_path) { "/user" } let(:expected_url) { "#{cloud_service_config.user_handler_base_url}#{delete_user_path}" } diff --git a/spec/jobs/user_update_job_spec.rb b/spec/jobs/user_update_job_spec.rb index bf17fce3..6e1c8121 100644 --- a/spec/jobs/user_update_job_spec.rb +++ b/spec/jobs/user_update_job_spec.rb @@ -5,7 +5,7 @@ let!(:user) { create(:user, :with_openstack_account) } let(:changes) { {} } let(:cloud_service_config) { create(:cloud_service_config) } - let(:update_users_path) { "/change_user_details" } + let(:update_users_path) { "/user" } let(:expected_url) { "#{cloud_service_config.user_handler_base_url}#{update_users_path}" } @@ -90,7 +90,7 @@ context "when the request is successful" do before(:each) do - stubs.post(expected_url) { |env| [ 204, {}, "No Content"] } + stubs.patch(expected_url) { |env| [ 204, {}, "No Content"] } allow_any_instance_of(described_class::Runner).to receive(:test_stubs).and_return(stubs) end @@ -105,7 +105,7 @@ context "when the request is unsuccessful" do before(:each) do - stubs.post(expected_url) { |env| [ 500, {}, {"error" => "Some error message"}] } + stubs.patch(expected_url) { |env| [ 500, {}, {"error" => "Some error message"}] } allow_any_instance_of(described_class::Runner).to receive(:test_stubs).and_return(stubs) end diff --git a/spec/support/shared_examples/jobs.rb b/spec/support/shared_examples/jobs.rb index 2b23fda8..85de6582 100644 --- a/spec/support/shared_examples/jobs.rb +++ b/spec/support/shared_examples/jobs.rb @@ -15,7 +15,7 @@ RSpec.shared_examples "creating team job" do describe "url" do - let(:team_service_path) { "/create_team" } + let(:team_service_path) { "/team" } subject { super().send(:url) } @@ -53,7 +53,7 @@ it "contains the team's billing account id" do expect(team.billing_acct_id).not_to be_nil - expect(subject["billing_account_id"]).to eq team.billing_acct_id + expect(subject["billing_acct_id"]).to eq team.billing_acct_id end end @@ -76,7 +76,7 @@ end describe "updating the team's details from the response" do - let(:team_service_path) { "/create_team" } + let(:team_service_path) { "/team" } context "when response does not contain expected fields" do let(:response_body) { {} } @@ -101,7 +101,7 @@ let(:project_id) { SecureRandom.uuid } let(:billing_acct_id) { SecureRandom.uuid } let(:response_body) { - {project_id: project_id, billing_account_id: billing_acct_id} + {project_id: project_id, billing_acct_id: billing_acct_id} .stringify_keys } From 982d135535721a1380d36faee6844d8668258e32 Mon Sep 17 00:00:00 2001 From: timalces Date: Mon, 25 Mar 2024 13:51:43 +0000 Subject: [PATCH 14/15] include details type in device api response --- app/views/api/v1/devices/show.rabl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/api/v1/devices/show.rabl b/app/views/api/v1/devices/show.rabl index 4200cda4..8e12e87c 100644 --- a/app/views/api/v1/devices/show.rabl +++ b/app/views/api/v1/devices/show.rabl @@ -8,9 +8,9 @@ end glue :details do |details| extends "api/v1/devices/details/#{details.class.name.split('::').last.underscore}" - #node :type do |details| - # details.class.name - #end + node :type do |details| + details.class.name + end end attribute :template_id, unless: @include_full_template_details From 0e4451a30b3e2c8c18b80f1140767f20fdb63574 Mon Sep 17 00:00:00 2001 From: timalces Date: Wed, 27 Mar 2024 13:27:21 +0000 Subject: [PATCH 15/15] cast python False to ruby/rails false --- config/initializers/extended_false_values.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 config/initializers/extended_false_values.rb diff --git a/config/initializers/extended_false_values.rb b/config/initializers/extended_false_values.rb new file mode 100644 index 00000000..796269b0 --- /dev/null +++ b/config/initializers/extended_false_values.rb @@ -0,0 +1,9 @@ +# Update list of false values to include Python's False + +module ActiveModel::Type + class Boolean + existing_values = FALSE_VALUES.dup + remove_const(:FALSE_VALUES) + FALSE_VALUES = existing_values + ['False', :False] + end +end