<s> from . import BaseTest <EOL> import datetime <EOL> import sys <EOL> from sentry import app , capture <EOL> from sentry . models import Event , Tag , Group <EOL> class SentryTest ( BaseTest ) : <EOL> def test_create ( self ) : <EOL> now = datetime . datetime . now ( ) <EOL> event , group = app . client . store ( <EOL> '<STR_LIT>' , <EOL> tags = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) , <EOL> date = now , <EOL> time_spent = <NUM_LIT> , <EOL> data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:message>' : '<STR_LIT>' <EOL> } <EOL> } , <EOL> event_id = '<STR_LIT>' , <EOL> ) <EOL> group_id = group . pk <EOL> self . assertTrue ( group . pk ) <EOL> self . assertEquals ( group . type , '<STR_LIT>' ) <EOL> self . assertEquals ( group . time_spent , <NUM_LIT> ) <EOL> self . assertEquals ( group . count , <NUM_LIT:1> ) <EOL> self . assertEquals ( len ( group . tags ) , <NUM_LIT:2> ) <EOL> tag = group . tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> tag = group . tags [ <NUM_LIT:1> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> events = group . get_relations ( Event ) <EOL> self . assertEquals ( len ( events ) , <NUM_LIT:1> ) <EOL> event = events [ <NUM_LIT:0> ] <EOL> self . assertEquals ( event . time_spent , group . time_spent ) <EOL> self . assertEquals ( event . type , group . type ) <EOL> self . assertEquals ( event . date , group . last_seen ) <EOL> self . assertEquals ( len ( event . tags ) , <NUM_LIT:2> ) <EOL> tag = event . tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> tag = event . tags [ <NUM_LIT:1> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> event , group = app . client . store ( <EOL> '<STR_LIT>' , <EOL> tags = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) , <EOL> date = now + datetime . timedelta ( seconds = <NUM_LIT:1> ) , <EOL> time_spent = <NUM_LIT:100> , <EOL> data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:message>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> event_id = '<STR_LIT>' , <EOL> ) <EOL> self . assertEquals ( group . pk , group_id ) <EOL> self . assertEquals ( group . count , <NUM_LIT:2> ) <EOL> self . assertEquals ( group . time_spent , <NUM_LIT> ) <EOL> self . assertEquals ( len ( group . tags ) , <NUM_LIT:2> ) <EOL> tag = group . tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> tag = group . tags [ <NUM_LIT:1> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> events = group . get_relations ( Event , desc = False ) <EOL> self . assertEquals ( len ( events ) , <NUM_LIT:2> ) <EOL> event = events [ <NUM_LIT:1> ] <EOL> self . assertEquals ( event . time_spent , <NUM_LIT:100> ) <EOL> self . assertEquals ( event . type , group . type ) <EOL> self . assertEquals ( group . last_seen , event . date ) <EOL> self . assertEquals ( len ( event . tags ) , <NUM_LIT:1> ) <EOL> tag = event . tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> tags = Tag . objects . order_by ( '<STR_LIT>' ) <EOL> self . assertEquals ( len ( tags ) , <NUM_LIT:2> , tags ) <EOL> groups = Group . objects . all ( ) <EOL> self . assertEquals ( len ( groups ) , <NUM_LIT:1> ) <EOL> event , group = app . client . store ( <EOL> '<STR_LIT>' , <EOL> tags = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) , <EOL> date = now + datetime . timedelta ( seconds = <NUM_LIT:1> ) , <EOL> time_spent = <NUM_LIT:100> , <EOL> data = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:message>' : '<STR_LIT>' , <EOL> } , <EOL> } , <EOL> event_id = '<STR_LIT>' , <EOL> ) <EOL> self . assertNotEquals ( group . pk , group_id ) <EOL> self . assertEquals ( group . count , <NUM_LIT:1> ) <EOL> self . assertEquals ( group . time_spent , <NUM_LIT:100> ) <EOL> self . assertEquals ( len ( group . tags ) , <NUM_LIT:1> ) <EOL> tag = group . tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> events = group . get_relations ( Event , desc = False ) <EOL> self . assertEquals ( len ( events ) , <NUM_LIT:1> ) <EOL> event = events [ <NUM_LIT:0> ] <EOL> self . assertEquals ( event . time_spent , <NUM_LIT:100> ) <EOL> self . assertEquals ( event . type , group . type ) <EOL> self . assertEquals ( group . last_seen , event . date ) <EOL> self . assertEquals ( len ( event . tags ) , <NUM_LIT:1> ) <EOL> tag = event . tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEquals ( tag [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> tags = Tag . objects . order_by ( '<STR_LIT>' ) <EOL> self . assertEquals ( len ( tags ) , <NUM_LIT:2> , tags ) <EOL> tag = tags [ <NUM_LIT:0> ] <EOL> self . assertEquals ( tag . key , '<STR_LIT>' ) <EOL> self . assertEquals ( tag . value , '<STR_LIT>' ) <EOL> self . assertEquals ( tag . count , <NUM_LIT:2> ) <EOL> tag = tags [ <NUM_LIT:1> ] <EOL> self . assertEquals ( tag . key , '<STR_LIT>' ) <EOL> self . assertEquals ( tag . value , '<STR_LIT>' ) <EOL> self . assertEquals ( tag . count , <NUM_LIT:1> ) <EOL> groups = Group . objects . all ( ) <EOL> self . assertEquals ( len ( groups ) , <NUM_LIT:2> ) <EOL> def test_tags ( self ) : <EOL> event_id = capture ( '<STR_LIT>' , message = '<STR_LIT:foo>' , tags = [ ( '<STR_LIT>' , '<STR_LIT:info>' ) ] ) <EOL> event = Event . objects . get ( event_id ) <EOL> self . assertEquals ( len ( event . tags ) , <NUM_LIT:2> , event . tags ) <EOL> tags = dict ( event . tags ) <EOL> self . assertTrue ( '<STR_LIT>' in tags ) <EOL> self . assertEquals ( tags [ '<STR_LIT>' ] , '<STR_LIT:info>' ) <EOL> self . assertTrue ( '<STR_LIT>' in tags ) <EOL> self . assertEquals ( tags [ '<STR_LIT>' ] , app . config [ '<STR_LIT>' ] ) <EOL> def test_message_event ( self ) : <EOL> event_id = capture ( '<STR_LIT>' , message = '<STR_LIT:foo>' ) <EOL> event = Event . objects . get ( event_id ) <EOL> self . assertEquals ( event . type , '<STR_LIT>' ) <EOL> self . assertEquals ( event . time_spent , <NUM_LIT:0> ) <EOL> self . assertTrue ( '<STR_LIT>' in event . data ) <EOL> event_data = event . data [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT:message>' in event_data ) <EOL> self . assertEquals ( event_data [ '<STR_LIT:message>' ] , '<STR_LIT:foo>' ) <EOL> self . assertTrue ( '<STR_LIT>' in event_data ) <EOL> self . assertEquals ( event_data [ '<STR_LIT>' ] , [ ] ) <EOL> def test_query_event ( self ) : <EOL> event_id = capture ( '<STR_LIT>' , query = '<STR_LIT>' , engine = '<STR_LIT>' , time_spent = <NUM_LIT> ) <EOL> event = Event . objects . get ( event_id ) <EOL> self . assertEquals ( event . type , '<STR_LIT>' ) <EOL> self . assertEquals ( event . time_spent , <NUM_LIT> ) <EOL> def test_exception_event_without_exc_info ( self ) : <EOL> try : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> event_id = capture ( '<STR_LIT>' ) <EOL> event = Event . objects . get ( event_id ) <EOL> self . assertEquals ( event . type , '<STR_LIT>' ) <EOL> self . assertEquals ( event . time_spent , <NUM_LIT:0> ) <EOL> data = event . data <EOL> self . assertTrue ( '<STR_LIT>' in data ) <EOL> event_data = data [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT:value>' in event_data ) <EOL> self . assertEquals ( event_data [ '<STR_LIT:value>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT:type>' in event_data ) <EOL> self . assertEquals ( event_data [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in data ) <EOL> event_data = data [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT>' in event_data ) <EOL> self . assertEquals ( len ( event_data [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> frame = event_data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in frame ) <EOL> self . assertEquals ( frame [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in frame ) <EOL> self . assertTrue ( frame [ '<STR_LIT>' ] > <NUM_LIT:0> ) <EOL> self . assertTrue ( '<STR_LIT>' in frame ) <EOL> self . assertEquals ( frame [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT:id>' in frame ) <EOL> self . assertTrue ( '<STR_LIT:filename>' in frame ) <EOL> def test_exception_event_with_exc_info ( self ) : <EOL> try : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> except : <EOL> exc_info = sys . exc_info ( ) <EOL> try : <EOL> raise SyntaxError ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> event_id = capture ( '<STR_LIT>' , exc_info = exc_info ) <EOL> event = Event . objects . get ( event_id ) <EOL> self . assertEquals ( event . type , '<STR_LIT>' ) <EOL> self . assertEquals ( event . time_spent , <NUM_LIT:0> ) <EOL> data = event . data <EOL> self . assertTrue ( '<STR_LIT>' in data ) <EOL> event_data = data [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT:value>' in event_data ) <EOL> self . assertEquals ( event_data [ '<STR_LIT:value>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT:type>' in event_data ) <EOL> self . assertEquals ( event_data [ '<STR_LIT:type>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in data ) <EOL> event_data = data [ '<STR_LIT>' ] <EOL> self . assertTrue ( '<STR_LIT>' in event_data ) <EOL> self . assertEquals ( len ( event_data [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> frame = event_data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in frame ) <EOL> self . assertEquals ( frame [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in frame ) <EOL> self . assertTrue ( frame [ '<STR_LIT>' ] > <NUM_LIT:0> ) <EOL> self . assertTrue ( '<STR_LIT>' in frame ) <EOL> self . assertEquals ( frame [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT:id>' in frame ) <EOL> self . assertTrue ( '<STR_LIT:filename>' in frame ) <EOL> def test_context_processors ( self ) : <EOL> try : <EOL> username = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> except : <EOL> exc_info = sys . exc_info ( ) <EOL> try : <EOL> raise SyntaxError ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> event_id = capture ( '<STR_LIT>' ) <EOL> event = Event . objects . get ( event_id ) <EOL> self . assertTrue ( '<STR_LIT>' in event . data ) <EOL> event_data = event . data [ '<STR_LIT>' ] <EOL> frame = event_data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEquals ( frame [ '<STR_LIT>' ] [ '<STR_LIT:password>' ] , '<STR_LIT>' ) </s>
