Skip to content

Commit d676d1f

Browse files
committed
"check_exists" should use same request format as "create" and "update". Bumped major version. 100% test coverage 💯
1 parent c2e482c commit d676d1f

15 files changed

Lines changed: 3625 additions & 86 deletions

lib/tess/api/api_resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def error_message(exception)
5454
begin
5555
JSON.parse(exception.response)
5656
rescue JSON::ParserError
57-
{ error_message: exception }
57+
{ 'exception' => "#{exception.class.name}: #{exception.message}" }
5858
end
5959
end
6060

lib/tess/api/uploader.rb

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,18 @@ module Tess
22
module API
33
class Uploader
44

5-
# The following methods are just to maintain backwards compatibility
6-
def self.check_material(material)
7-
warn '[DEPRECATION] Uploader.check_material is deprecated, please use Material#exists? instead'
8-
material.exists?
9-
end
10-
11-
def self.create_material(material)
12-
warn '[DEPRECATION] Uploader.create_material is deprecated, please use Material#create instead'
13-
material.create
14-
end
15-
16-
def self.update_material(material)
17-
warn '[DEPRECATION] Uploader.update_material is deprecated, please use Material#update instead'
18-
material.update
19-
end
20-
21-
def self.create_or_update_material(material)
22-
warn '[DEPRECATION] Uploader.create_or_update_material is deprecated, please use Material#create_or_update instead'
23-
material.create_or_update
24-
end
25-
26-
def self.check_event(event)
27-
warn '[DEPRECATION] Uploader.check_event is deprecated, please use Event#exists? instead'
28-
event.exists?
29-
end
30-
31-
def self.create_event(event)
32-
warn '[DEPRECATION] Uploader.create_event is deprecated, please use Event#create instead'
33-
event.create
34-
end
35-
36-
def self.update_event(event)
37-
warn '[DEPRECATION] Uploader.update_event is deprecated, please use Event#update instead'
38-
event.update
39-
end
40-
41-
def self.create_or_update_event(event)
42-
warn '[DEPRECATION] Uploader.create_or_update_event is deprecated, please use Event#create_or_update instead'
43-
event.create_or_update
44-
end
45-
46-
def self.check_content_provider(content_provider)
47-
warn '[DEPRECATION] Uploader.check_content_provider is deprecated, please use ContentProvider#exists? instead'
48-
content_provider.exists?
49-
end
50-
51-
def self.create_content_provider(content_provider)
52-
warn '[DEPRECATION] Uploader.create_content_provider is deprecated, please use ContentProvider#create instead'
53-
content_provider.create
54-
end
55-
56-
def self.update_content_provider(content_provider)
57-
warn '[DEPRECATION] Uploader.update_content_provider is deprecated, please use ContentProvider#update instead'
58-
content_provider.update
59-
end
60-
61-
def self.create_or_update_content_provider(content_provider)
62-
warn '[DEPRECATION] Uploader.create_or_update_content_provider is deprecated, please use ContentProvider#create_or_update instead'
63-
content_provider.create_or_update
64-
end
65-
665
def self.do_upload(data, auth, data_type, action, method)
67-
# The data to post must be converted to JSON and
68-
# the proper auth details added.
6+
payload = { data_type => data.dump }
7+
698
if auth
70-
payload = { user_email: Tess::API.config['user_email'],
71-
user_token: Tess::API.config['user_token'],
72-
data_type => data.dump
73-
}.to_json
74-
else
75-
payload = data.to_json
9+
payload[:user_email] = Tess::API.config['user_email']
10+
payload[:user_token] = Tess::API.config['user_token']
7611
end
7712

7813
response = RestClient::Request.execute(method: method.to_sym,
7914
url: (Tess::API.base_url + action),
80-
payload: payload,
15+
payload: payload.to_json,
8116
headers: { content_type: 'application/json'})
82-
8317
begin
8418
JSON.parse(response.body)
8519
rescue JSON::ParserError

tess_api_client.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Gem::Specification.new do |s|
22
s.name = 'tess_api_client'
3-
s.version = '0.2.0'
4-
s.date = '2016-11-11'
5-
s.summary = 'Libraries for uploading files to http://tess.oerc.ox.ac.uk'
3+
s.version = '0.3.0'
4+
s.date = '2017-03-17'
5+
s.summary = 'Libraries for uploading files to https://github.com/ElixirUK/TeSS'
66
s.description = 'Uses the a Custom RoR API on https://tess.elixir-uk.org to upload data in the format being used by the TeSS project.'
77
s.authors = ['Milo Thurston','Niall Beard','Aleksandra Nenadic','Finn Bacall']
88
s.email = 'milo.thurston@oerc.ox.ac.uk'

test/content_provider_test.rb

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ class ContentProviderTest < Test::Unit::TestCase
3939
title: 'Re-branded Content Provider',
4040
keywords: ['hip', '#hashtag']
4141
})
42+
43+
@content_provider_with_missing_fields = Tess::API::ContentProvider.new(
44+
{ title: '',
45+
url: '',
46+
})
47+
48+
@not_found_content_provider = Tess::API::ContentProvider.new(
49+
{ id: 404040404,
50+
title: 'I will return a 404 or something',
51+
url: 'http://example.com/content_providers/404',
52+
})
53+
54+
@bad_response_content_provider = Tess::API::ContentProvider.new(
55+
{ title: 'I will return a 500 or something',
56+
url: 'http://example.com/content_providers/500',
57+
})
4258
end
4359

4460
test 'can initialize a content provider' do
@@ -182,5 +198,26 @@ class ContentProviderTest < Test::Unit::TestCase
182198
assert @non_existing_content_provider.id
183199
end
184200
end
185-
201+
202+
test 'stores errors messages on bad create' do
203+
VCR.use_cassette('missing_fields_content_provider_create_response') do
204+
res = @content_provider_with_missing_fields.create
205+
assert res['errors']['title'].any?
206+
assert res['errors']['url'].any?
207+
end
208+
end
209+
210+
test 'stores 505 exception message on bad create' do
211+
VCR.use_cassette('bad_content_provider_create_response') do
212+
res = @bad_response_content_provider.create
213+
assert_equal 'RestClient::InternalServerError: 500 Internal Server Error', res['errors']['exception']
214+
end
215+
end
216+
217+
test 'stores 404 exception message on bad update' do
218+
VCR.use_cassette('bad_content_provider_update_response') do
219+
res = @not_found_content_provider.update
220+
assert_equal 'RestClient::NotFound: 404 Not Found', res['errors']['exception']
221+
end
222+
end
186223
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Main]
2+
host = localhost
3+
protocol = http
4+
port = 3000
5+
user_token = my_secret_api_string
6+
debug = true
7+
google_api_key = 12345

0 commit comments

Comments
 (0)