pisoni 1.24.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4dc7a68d6d7ae8b6523c0956c9425a587c53b4cac5a18eb7466e9455c38ef15
4
- data.tar.gz: e930a4713a961846d6c84207a2435c72f1a957acc6c4ea313c48123a5d953678
3
+ metadata.gz: e9b028a5986ee4a1afc4e1a07c3029e30861b4563b936084fc0c8f9c684b78f3
4
+ data.tar.gz: '00391525ce6ea29046aed52421a9df0882bf878d0e9e8a25e336efb4674626e3'
5
5
  SHA512:
6
- metadata.gz: 5aa1351666750cd74d9b55652268155898ec5e3554bd085f8d0590fadc8d1a60d63152f6e31d7f7f48da191f26a503a543a6b6b31a470739f6af1a23d0aad11d
7
- data.tar.gz: a40c08e47e58ec21db44a12e01dc0b202f0d264a34677ca9029fa23816689acb7426f4fe7d2a24abd6cb08f17c4833ea417a8d46e4833fdd3885b56b29c2d095
6
+ metadata.gz: a2bd6747faf1121c04e66149bf60cbf0b246e5dffc893fb599988034b2609cf8fee2e4fafd54bdcfdbb7a246c0aae32958f93bb5e3d009f8da4645f10b7b3edb
7
+ data.tar.gz: fced6e7795fffaf5489d63bb41cf911a1ad661aeb6e96bb99d8a897af6c9e04a903e7b64b687685c6f533329f9c9e32f82bd3a17c125eef7a71d285951d5ac4b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Notable changes to Pisoni will be tracked in this document.
4
4
 
5
+ ## 1.25.0 - 2019-02-20
6
+
7
+ ### Added
8
+
9
+ - Applications can now be activated/deactivated. [#12](https://github.com/3scale/pisoni/pull/12)
10
+ - Users of a service can now be deleted. [#15](https://github.com/3scale/pisoni/pull/15)
11
+
5
12
  ## 1.24.0 - 2018-06-29
6
13
 
7
14
  ### Added
@@ -38,6 +38,23 @@ module ThreeScale
38
38
  api_delete({}, uri: app_uri(service_id, id))
39
39
  end
40
40
 
41
+ def initialize(attributes = {})
42
+ @state = :active
43
+ super(attributes)
44
+ end
45
+
46
+ def activate
47
+ self.state = :active
48
+ end
49
+
50
+ def deactivate
51
+ self.state = :suspended
52
+ end
53
+
54
+ def active?
55
+ state == :active
56
+ end
57
+
41
58
  def save
42
59
  api_save uri: self.class.send(:app_uri, service_id, id)
43
60
  end
@@ -62,6 +79,12 @@ module ThreeScale
62
79
  api_delete({}, uri: key_uri(service_id, user_key))
63
80
  end
64
81
 
82
+ private
83
+
84
+ def state=(value)
85
+ # only :active or nil will be considered as :active
86
+ @state = value.nil? || value.to_sym == :active ? :active : :suspended
87
+ end
65
88
  end
66
89
  end
67
90
  end
@@ -10,6 +10,11 @@ module ThreeScale
10
10
  end
11
11
  private_class_method :base_uri
12
12
 
13
+ def self.users_base_uri(service_id)
14
+ "#{default_uri}#{service_id}/users"
15
+ end
16
+ private_class_method :users_base_uri
17
+
13
18
  def self.check_params(service_id, username)
14
19
  raise UserRequiresUsername if username.nil? || username == ''.freeze
15
20
  raise UserRequiresServiceId if service_id.nil? || service_id == ''.freeze
@@ -42,6 +47,12 @@ module ThreeScale
42
47
  check_params service_id, username
43
48
  api_delete({}, uri: base_uri(service_id, username))
44
49
  end
50
+
51
+ def self.delete_all_for_service(service_id)
52
+ raise UserRequiresServiceId if service_id.nil? || service_id == ''.freeze
53
+
54
+ api_delete({}, uri: users_base_uri(service_id))
55
+ end
45
56
  end
46
57
  end
47
58
  end
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module Core
3
- VERSION = '1.24.0'
3
+ VERSION = '1.25.0'
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ module ThreeScale
20
20
 
21
21
  application.service_id.must_equal '2001'
22
22
  application.id.must_equal '8011'
23
- application.state.must_equal 'suspended'
23
+ application.active?.must_equal false
24
24
  application.plan_id.must_equal '3066'
25
25
  application.plan_name.must_equal 'crappy'
26
26
  application.redirect_url.must_equal 'blah'
@@ -93,7 +93,7 @@ module ThreeScale
93
93
  it 'returns an Application object with correct fields' do
94
94
  @app.id.must_equal '8011'
95
95
  @app.service_id.must_equal '2001'
96
- @app.state.must_equal 'suspended'
96
+ @app.active?.must_equal false
97
97
  @app.plan_id.must_equal '3066'
98
98
  @app.plan_name.must_equal 'crappy'
99
99
  @app.redirect_url.must_equal 'blah'
@@ -152,6 +152,77 @@ module ThreeScale
152
152
  newapp.plan_name.must_equal 'some_other_plan'
153
153
  end
154
154
 
155
+ it 'save active application' do
156
+ @app.activate
157
+ @app.save
158
+ newapp = Application.load @app.service_id, @app.id
159
+ newapp.active?.must_equal true
160
+ end
161
+
162
+ it 'save inactive application' do
163
+ @app.deactivate
164
+ @app.save
165
+ newapp = Application.load @app.service_id, @app.id
166
+ newapp.active?.must_equal false
167
+ end
168
+
169
+ it 'save application with no explicit state' do
170
+ svc_id = 2001
171
+ app_id = 9011
172
+ # Make sure there is nothing in db
173
+ Application.delete(svc_id, app_id)
174
+ Application.load(svc_id, app_id).must_be_nil
175
+ app_def_state = Application.new service_id: svc_id, id: app_id
176
+ app_def_state.save
177
+ newapp = Application.load app_def_state.service_id, app_def_state.id
178
+ newapp.wont_be_nil
179
+ newapp.active?.must_equal true
180
+ end
181
+ end
182
+
183
+ describe '.active?' do
184
+ it 'should be active when application is initialized as active' do
185
+ [
186
+ { state: :active },
187
+ { state: 'active' },
188
+ # even when state is not set
189
+ {},
190
+ # even when state is intentionally set as nil
191
+ { state: nil }
192
+ ].each do |app_attrs|
193
+ Application.new(app_attrs).active?.must_equal true
194
+ end
195
+ end
196
+
197
+ it 'should be inactive when application is initialized as disabled' do
198
+ [
199
+ { state: :suspended },
200
+ { state: 'suspended' },
201
+ { state: :something },
202
+ { state: :disable },
203
+ { state: :disabled },
204
+ { state: '1' },
205
+ { state: '0' },
206
+ { state: 'true' },
207
+ { state: 'false' }
208
+ ].each do |app_attrs|
209
+ Application.new(app_attrs).active?.must_equal false
210
+ end
211
+ end
212
+
213
+ it 'should be active when the application is activated' do
214
+ app = Application.new(state: :disable)
215
+ app.active?.must_equal false
216
+ app.activate
217
+ app.active?.must_equal true
218
+ end
219
+
220
+ it 'should be inactive when the application is deactivated' do
221
+ app = Application.new(state: :active)
222
+ app.active?.must_equal true
223
+ app.deactivate
224
+ app.active?.must_equal false
225
+ end
155
226
  end
156
227
 
157
228
  describe 'by_key' do
@@ -4,7 +4,8 @@ require_relative './private_endpoints/service_error'
4
4
  module ThreeScale
5
5
  module Core
6
6
  describe ServiceError do
7
- let(:service_id) { '7575' }
7
+ let(:service_id) { '7575_service_error_spec' }
8
+ let(:provider_key) { 'foo_service_error_spec' }
8
9
  let(:non_existing_service_id) { service_id.to_i.succ.to_s }
9
10
 
10
11
  describe '.load_all' do
@@ -17,7 +18,7 @@ module ThreeScale
17
18
 
18
19
  before do
19
20
  Service.delete_by_id!(service_id)
20
- Service.save!(provider_key: 'foo', id: service_id)
21
+ Service.save!(provider_key: provider_key, id: service_id)
21
22
  ServiceError.delete_all(service_id)
22
23
  ServiceError.save(service_id, error_messages)
23
24
  end
@@ -100,7 +101,7 @@ module ThreeScale
100
101
  describe '.delete_all' do
101
102
  before do
102
103
  Service.delete_by_id!(service_id)
103
- Service.save!(provider_key: 'foo', id: service_id)
104
+ Service.save!(provider_key: provider_key, id: service_id)
104
105
  ServiceError.delete_all(service_id)
105
106
  end
106
107
 
data/spec/service_spec.rb CHANGED
@@ -6,10 +6,10 @@ module ThreeScale
6
6
  let(:default_service_id) { 7001 }
7
7
  let(:non_default_service_id) { default_service_id.succ }
8
8
  let(:non_existent_service_id) { non_default_service_id.succ }
9
- let(:default_provider_key) { 'foo' }
10
- let(:other_provider_key) { 'bazinga' }
11
- let(:another_provider_key) { 'bar' }
12
- let(:non_existent_provider_key) { 'bunga' }
9
+ let(:default_provider_key) { 'foo_service_spec' }
10
+ let(:other_provider_key) { 'bazinga_service_spec' }
11
+ let(:another_provider_key) { 'bar_service_spec' }
12
+ let(:non_existent_provider_key) { 'bunga_service_spec' }
13
13
 
14
14
  before do
15
15
  # We create a new service for our provider as the default, then
@@ -62,23 +62,22 @@ module ThreeScale
62
62
  end
63
63
 
64
64
  describe '.delete_by_id!' do
65
- before do
66
- Service.save! provider_key: default_provider_key,
67
- id: default_service_id,
68
- default_service: true
69
- end
70
-
71
65
  it 'returns true if deleting a non-default service' do
72
66
  Service.save! provider_key: default_provider_key,
73
67
  id: non_default_service_id
74
68
  Service.delete_by_id!(non_default_service_id).must_equal true
75
69
  end
76
70
 
77
- it 'raises an exception when deleting a default service' do
71
+ it 'raises an exception when deleting a default service and not unique' do
72
+ Service.save! provider_key: default_provider_key, id: non_default_service_id
78
73
  lambda do
79
74
  Service.delete_by_id! default_service_id
80
75
  end.must_raise ServiceIsDefaultService
81
76
  end
77
+
78
+ it 'returns true when deleting a default service and is unique for the provider' do
79
+ Service.delete_by_id!(default_service_id).must_equal true
80
+ end
82
81
  end
83
82
 
84
83
  describe '.save!' do
@@ -6,11 +6,11 @@ module ThreeScale
6
6
  describe Transaction do
7
7
  before do
8
8
  Service.delete_by_id!(service_id)
9
- Service.save!(provider_key: 'foo', id: service_id)
9
+ Service.save!(provider_key: 'foo_transaction_spec', id: service_id)
10
10
  end
11
11
 
12
12
  describe '.load_all' do
13
- let(:service_id) { '7575' }
13
+ let(:service_id) { '7575_transaction_spec' }
14
14
  let(:non_existing_service_id) { service_id.to_i.succ.to_s }
15
15
 
16
16
  before do
data/spec/user_spec.rb CHANGED
@@ -159,6 +159,34 @@ module ThreeScale
159
159
  plan_id: plan_id, plan_name: plan_name
160
160
  end
161
161
  end
162
+
163
+ describe '.delete_all_for_service' do
164
+ let(:service_id) { '2001_delete_all_for_service' }
165
+ let(:provider_key) { 'provider_for_delete_all_for_service' }
166
+ let(:state) { :active }
167
+
168
+ before do
169
+ Service.save! provider_key: provider_key, id: service_id, default_service: true
170
+ end
171
+
172
+ it 'deletes all users' do
173
+ user01 = User.save!(service_id: service_id, username: 'username01', state: :active,
174
+ plan_id: 'plan_id_01', plan_name: 'plan_01')
175
+ user02 = User.save!(service_id: service_id, username: 'username02', state: :active,
176
+ plan_id: 'plan_id_02', plan_name: 'plan_02')
177
+ User.delete_all_for_service(service_id).must_equal true
178
+ User.load(service_id, user01.username).must_be_nil
179
+ User.load(service_id, user02.username).must_be_nil
180
+ end
181
+
182
+ it 'raises error on empty service' do
183
+ proc { User.delete_all_for_service('') }.must_raise UserRequiresServiceId
184
+ end
185
+
186
+ it 'raises error on nil service' do
187
+ proc { User.delete_all_for_service(nil) }.must_raise UserRequiresServiceId
188
+ end
189
+ end
162
190
  end
163
191
  end
164
192
  end
@@ -3,9 +3,9 @@ require_relative './spec_helper'
3
3
  module ThreeScale
4
4
  module Core
5
5
  describe Utilization do
6
- let(:service_id) { '1001' }
6
+ let(:service_id) { '1001_utilization_spec' }
7
7
  let(:non_existing_service_id) { service_id.to_i.succ.to_s }
8
- let(:provider_key) { 'foo' }
8
+ let(:provider_key) { 'foo_utilization_spec' }
9
9
 
10
10
  let(:app_id) { '2001' }
11
11
  let(:non_existing_app_id) { app_id.to_i.succ.to_s }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pisoni
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.24.0
4
+ version: 1.25.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Martinez Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2019-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -158,8 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  requirements: []
161
- rubyforge_project:
162
- rubygems_version: 2.7.7
161
+ rubygems_version: 3.0.1
163
162
  signing_key:
164
163
  specification_version: 4
165
164
  summary: Client for the Apisonator internal API for model data