Skip to content

Commit

Permalink
moved request data to a separate .json file and fixed failing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperionel authored and Chocksy committed May 12, 2016
1 parent c8b53ef commit f8a1e06
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 62 deletions.
6 changes: 3 additions & 3 deletions lib/error_store/interfaces/sdk.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module ErrorStore::Interfaces
class Sdk < ErrorStore::BaseInterface

def self.display_name
def self.display_name
'Sdk'
end

def type
:sdk
end

def sanitize_data (data)
def sanitize_data (data)
raise ErrorStore::ValidationError.new(self), "No 'name' value" if !data[:name].present?
raise ErrorStore::ValidationError.new(self), "No 'version' value" if !data[:version].present?
self._data =
Expand All @@ -18,6 +18,6 @@ def sanitize_data (data)
version: trim(data[:version])
}
self
end
end
end
end
47 changes: 47 additions & 0 deletions spec/factories/web_responses/python_exception.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{"exception":
{"values":
[{"stacktrace":
{"frames":
[{"function":"<module>",
"abs_path":"./testing.py",
"pre_context":
["import pdb, raven, os",
"",
"client = raven.Client(dsn= 'http://01823eb4e74f172b7df08d682f36eedc:39fc7ea388a3be5e13f459d942ac94b1@localhost:3000/39fc7ea388a3be5e13f459d942ac94b1')",
"",
"try:"],
"post_context":["except ZeroDivisionError:", " client.captureException()"],
"vars":
{"__builtins__":"<module '__builtin__' (built-in)>",
"__file__":"'./testing.py'",
"__package__":null,
"client":"<raven.base.Client object at 0x7fa3f82cbd90>",
"__doc__":null,
"__name__":"'__main__'",
"os":"<module 'os' from '/usr/lib/python2.7/os.pyc'>",
"pdb":"<module 'pdb' from '/usr/lib/python2.7/pdb.py'>",
"raven":"<module 'raven' from '/home/hyperionel/.local/lib/python2.7/site-packages/raven/__init__.pyc'>"},
"module":"__main__",
"filename":"testing.py",
"lineno":8,
"context_line":" 1 / 0"}]},
"type":"ZeroDivisionError",
"module":"exceptions",
"value":"integer division or modulo by zero"}]},
"culprit":"__main__ in <module>",
"server_name":"hyperionel",
"extra":{"sys.argv":["'./testing.py'"]},
"event_id":"e7f31444bf1e425dbdbb8411b2dbc0d0",
"timestamp":1463040891,
"level":40,
"modules":{"python":"2.7.10"},
"time_spent":null,
"platform":"python",
"message":"ZeroDivisionError: integer division or modulo by zero",
"tags":{},
"sdk":{"version":"5.15.0", "name":"raven-python"},
"website":1,
"errors":[],
"interfaces":{},
"site":null,
"checksum":null}
58 changes: 3 additions & 55 deletions spec/lib/error_store/interfaces/sdk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,9 @@
include ErrorStore::Utils

RSpec.describe ErrorStore::Interfaces::Sdk do
# let(:website) { create :website }
# let(:post_request) { post_error_request(web_response_factory('ruby_exception'), website) }

let(:post_request) {
{:exception=>
{:values=>
[{:stacktrace=>
{:frames=>
[{:function=>"<module>",
:abs_path=>"./testing.py",
:pre_context=>
["import pdb, raven, os",
"",
"client = raven.Client(dsn= 'http://01823eb4e74f172b7df08d682f36eedc:39fc7ea388a3be5e13f459d942ac94b1@localhost:3000/39fc7ea388a3be5e13f459d942ac94b1')",
"",
"try:"],
:post_context=>["except ZeroDivisionError:", " client.captureException()"],
:vars=>
{:__builtins__=>"<module '__builtin__' (built-in)>",
:__file__=>"'./testing.py'",
:__package__=>nil,
:client=>"<raven.base.Client object at 0x7fdfcb66ad90>",
:__doc__=>nil,
:__name__=>"'__main__'",
:os=>"<module 'os' from '/usr/lib/python2.7/os.pyc'>",
:pdb=>"<module 'pdb' from '/usr/lib/python2.7/pdb.py'>",
:raven=>
"<module 'raven' from '/home/hyperionel/.local/lib/python2.7/site-packages/raven/__init__.pyc'>"},
:module=>"__main__",
:filename=>"testing.py",
:lineno=>8,
:context_line=>" 1 / 0"}]},
:type=>"ZeroDivisionError",
:module=>"exceptions",
:value=>"integer division or modulo by zero"}]},
:culprit=>"__main__ in <module>",
:server_name=>"hyperionel",
:extra=>{:"sys.argv"=>["'./testing.py'"]},
:event_id=>"bb31075106d043f9a78a28772a0672fc",
:timestamp=>1462964330,
:level=>40,
:modules=>{:python=>"2.7.10"},
:time_spent=>nil,
:platform=>"python",
:message=>"ZeroDivisionError: integer division or modulo by zero",
:tags=>{},
:sdk=>{:version=>"5.15.0", :name=>"raven-python"},
:website=>1,
:errors=>[],
:interfaces=>{},
:site=>nil,
:checksum=>nil}
}

let(:post_data) { post_request[:sdk] }
let(:website) { create :website }
let(:post_request) { post_error_request(web_response_factory('python_exception'), website) }
let(:post_data) { validated_request(post_request)[:interfaces][:sdk] }
let(:sdk) { ErrorStore::Interfaces::Sdk.new(post_data) }


Expand Down
9 changes: 5 additions & 4 deletions spec/lib/error_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
describe 'find_interfaces' do
it 'contains all the interfaces in the folder' do
check = subject.available_interfaces.map do |i|
true if %w(query frame message exception stacktrace template user single_exception http).include?(i[:type].to_s)
true if %w(query frame message exception stacktrace template user single_exception http sdk).include?(i[:type].to_s)
end.uniq
expect(check).to eq([true])
expect(subject.available_interfaces.length).to eq(9)
expect(subject.available_interfaces.length).to eq(10)
end
end

Expand All @@ -51,7 +51,7 @@

it 'gives the interfaces with all of them if find_interfaces called' do
expect(subject.available_interfaces).to be_kind_of(Array)
expect(subject.available_interfaces.length).to eq(9)
expect(subject.available_interfaces.length).to eq(10)
expect(subject.available_interfaces).to eq(subject.class_variable_get(:@@interfaces_list))
end
end
Expand All @@ -61,7 +61,7 @@
subject.class_variable_set(:@@interfaces_list, []) # reset the interfaces list
subject.find_interfaces

expect(subject.interfaces_types).to eq([:exception, :frame, :http, :message, :query, :single_exception, :stacktrace, :template, :user])
expect(subject.interfaces_types).to eq([:exception, :frame, :http, :message, :query, :sdk, :single_exception, :stacktrace, :template, :user])
end
end

Expand All @@ -88,6 +88,7 @@
:user=>:user,
:csp=>:csp,
:http=>:http,
:sdk=>:sdk,
:"sentry.interfaces.Exception"=>:exception,
:"sentry.interfaces.Message"=>:message,
:"sentry.interfaces.Stacktrace"=>:stacktrace,
Expand Down

0 comments on commit f8a1e06

Please sign in to comment.