Skip to content

Add simulator to device info #3723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/sentry/interfaces/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,38 @@
context_types = {}


class _IndexMapping(object):

def __init__(self, vars):
self.vars = vars

def __getitem__(self, key):
if key[:1] == '?':
try:
return self.vars[key[1:]]
except LookupError:
return None
return self.vars[key]


class _IndexFormatter(string.Formatter):

def format_field(self, value, format_spec):
if not format_spec and isinstance(value, bool):
return value and 'yes' or 'no'
if format_spec[:1] == '?':
args = format_spec[1:].split(':', 1)
if value:
return args[0]
if len(args) == 2:
return args[1]
return u''
if isinstance(value, bool):
return value and u'yes' or u'no'
return string.Formatter.format_field(self, value, format_spec)


def format_index_expr(format_string, data):
return unicode(_IndexFormatter().vformat(
unicode(format_string), (), data).strip())
unicode(format_string), (), _IndexMapping(data)).strip())


def contexttype(name):
Expand Down Expand Up @@ -83,8 +104,8 @@ class DefaultContextType(ContextType):
@contexttype('device')
class DeviceContextType(ContextType):
indexed_fields = {
'': u'{model}',
'family': u'{family}',
'': u'{model}{?simulator:? Simulator:}',
'family': u'{family}{?simulator:? Simulator:}',
}
# model_id, arch

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DeviceContextType = React.createClass({

render() {
let {name, family, model, model_id, arch, battery_level, orientation,
...data} = this.props.data;
simulator, ...data} = this.props.data;
return (
<ContextBlock
data={data}
Expand All @@ -23,6 +23,7 @@ const DeviceContextType = React.createClass({
['?Battery Level', defined(battery_level)
? `${battery_level}%` : null],
['?Orientation', orientation],
['?Simulator', simulator],
]}
alias={this.props.alias} />
);
Expand Down
58 changes: 58 additions & 0 deletions tests/sentry/interfaces/test_contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,64 @@ def test_device_with_alias(self):
}
}

def test_device_sim(self):
ctx = Contexts.to_python({
'device': {
'name': 'My iPad',
'model': 'iPad1,2',
'family': 'iPad',
'model_id': '1234AB',
'version': '1.2.3',
'arch': 'arm64',
'simulator': True,
},
})
assert sorted(ctx.iter_tags()) == [
('device', 'iPad1,2 Simulator'),
('device.family', 'iPad Simulator'),
]
assert ctx.to_json() == {
'device': {
'type': 'device',
'name': 'My iPad',
'model': 'iPad1,2',
'family': 'iPad',
'model_id': '1234AB',
'version': '1.2.3',
'arch': 'arm64',
'simulator': True,
}
}

def test_device_sim_explicit_off(self):
ctx = Contexts.to_python({
'device': {
'name': 'My iPad',
'model': 'iPad1,2',
'family': 'iPad',
'model_id': '1234AB',
'version': '1.2.3',
'arch': 'arm64',
'simulator': False,
},
})
assert sorted(ctx.iter_tags()) == [
('device', 'iPad1,2'),
('device.family', 'iPad'),
]
assert ctx.to_json() == {
'device': {
'type': 'device',
'name': 'My iPad',
'model': 'iPad1,2',
'family': 'iPad',
'model_id': '1234AB',
'version': '1.2.3',
'arch': 'arm64',
'simulator': False,
}
}

def test_default(self):
ctx = Contexts.to_python({
'whatever': {
Expand Down