<s> from __future__ import absolute_import <EOL> import pytest <EOL> from datetime import timedelta <EOL> from django . core import mail <EOL> from django . core . urlresolvers import reverse <EOL> from django . db import connection <EOL> from django . utils import timezone <EOL> from exam import fixture <EOL> from sentry . db . models . fields . node import NodeData , NodeIntegrityFailure <EOL> from sentry . models import ProjectKey , Event , LostPasswordHash <EOL> from sentry . testutils import TestCase <EOL> from sentry . utils . compat import pickle <EOL> from sentry . utils . strings import compress <EOL> class ProjectKeyTest ( TestCase ) : <EOL> def test_get_dsn ( self ) : <EOL> key = ProjectKey ( project_id = <NUM_LIT:1> , public_key = '<STR_LIT>' , secret_key = '<STR_LIT>' ) <EOL> with self . options ( { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> self . assertEquals ( key . get_dsn ( ) , '<STR_LIT>' ) <EOL> def test_get_dsn_with_ssl ( self ) : <EOL> key = ProjectKey ( project_id = <NUM_LIT:1> , public_key = '<STR_LIT>' , secret_key = '<STR_LIT>' ) <EOL> with self . options ( { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> self . assertEquals ( key . get_dsn ( ) , '<STR_LIT>' ) <EOL> def test_get_dsn_with_port ( self ) : <EOL> key = ProjectKey ( project_id = <NUM_LIT:1> , public_key = '<STR_LIT>' , secret_key = '<STR_LIT>' ) <EOL> with self . options ( { '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> self . assertEquals ( key . get_dsn ( ) , '<STR_LIT>' ) <EOL> def test_get_dsn_with_public_endpoint_setting ( self ) : <EOL> key = ProjectKey ( project_id = <NUM_LIT:1> , public_key = '<STR_LIT>' , secret_key = '<STR_LIT>' ) <EOL> with self . settings ( SENTRY_PUBLIC_ENDPOINT = '<STR_LIT>' ) : <EOL> self . assertEquals ( key . get_dsn ( public = True ) , '<STR_LIT>' ) <EOL> def test_get_dsn_with_endpoint_setting ( self ) : <EOL> key = ProjectKey ( project_id = <NUM_LIT:1> , public_key = '<STR_LIT>' , secret_key = '<STR_LIT>' ) <EOL> with self . settings ( SENTRY_ENDPOINT = '<STR_LIT>' ) : <EOL> self . assertEquals ( key . get_dsn ( ) , '<STR_LIT>' ) <EOL> def test_key_is_created_for_project ( self ) : <EOL> self . create_user ( '<STR_LIT>' ) <EOL> team = self . create_team ( name = '<STR_LIT>' ) <EOL> project = self . create_project ( name = '<STR_LIT>' , team = team ) <EOL> assert project . key_set . exists ( ) is True <EOL> class LostPasswordTest ( TestCase ) : <EOL> @ fixture <EOL> def password_hash ( self ) : <EOL> return LostPasswordHash . objects . create ( <EOL> user = self . user , <EOL> ) <EOL> def test_send_recover_mail ( self ) : <EOL> with self . options ( { '<STR_LIT>' : '<STR_LIT>' } ) , self . tasks ( ) : <EOL> self . password_hash . send_recover_mail ( ) <EOL> assert len ( mail . outbox ) == <NUM_LIT:1> <EOL> msg = mail . outbox [ <NUM_LIT:0> ] <EOL> assert msg . to == [ self . user . email ] <EOL> assert msg . subject == '<STR_LIT>' <EOL> url = '<STR_LIT>' + reverse ( '<STR_LIT>' , <EOL> args = [ self . password_hash . user_id , self . password_hash . hash ] ) <EOL> assert url in msg . body <EOL> class GroupIsOverResolveAgeTest ( TestCase ) : <EOL> def test_simple ( self ) : <EOL> group = self . group <EOL> group . last_seen = timezone . now ( ) - timedelta ( hours = <NUM_LIT:2> ) <EOL> group . project . update_option ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> assert group . is_over_resolve_age ( ) is True <EOL> group . last_seen = timezone . now ( ) <EOL> assert group . is_over_resolve_age ( ) is False <EOL> class EventNodeStoreTest ( TestCase ) : <EOL> def test_does_transition_data_to_node ( self ) : <EOL> group = self . group <EOL> data = { '<STR_LIT:key>' : '<STR_LIT:value>' } <EOL> query_bits = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> params = [ group . id , group . project_id , compress ( pickle . dumps ( data ) ) , '<STR_LIT:test>' , timezone . now ( ) ] <EOL> if connection . features . can_return_id_from_insert : <EOL> r_fmt , r_params = connection . ops . return_insert_id ( ) <EOL> if r_fmt : <EOL> query_bits . append ( r_fmt % Event . _meta . pk . column ) <EOL> params += r_params <EOL> cursor = connection . cursor ( ) <EOL> cursor . execute ( '<STR_LIT:U+0020>' . join ( query_bits ) , params ) <EOL> if connection . features . can_return_id_from_insert : <EOL> event_id = connection . ops . fetch_returned_insert_id ( cursor ) <EOL> else : <EOL> event_id = connection . ops . last_insert_id ( <EOL> cursor , Event . _meta . db_table , Event . _meta . pk . column ) <EOL> event = Event . objects . get ( id = event_id ) <EOL> assert type ( event . data ) == NodeData <EOL> assert event . data == data <EOL> assert event . data . id is None <EOL> event . save ( ) <EOL> assert event . data == data <EOL> assert event . data . id is not None <EOL> node_id = event . data . id <EOL> event = Event . objects . get ( id = event_id ) <EOL> Event . objects . bind_nodes ( [ event ] , '<STR_LIT:data>' ) <EOL> assert event . data == data <EOL> assert event . data . id == node_id <EOL> def test_screams_bloody_murder_when_ref_fails ( self ) : <EOL> project1 = self . create_project ( ) <EOL> project2 = self . create_project ( ) <EOL> group1 = self . create_group ( project1 ) <EOL> invalid_event = self . create_event ( group = group1 ) <EOL> group2 = self . create_group ( project2 ) <EOL> event = self . create_event ( group = group2 ) <EOL> event . data . bind_ref ( invalid_event ) <EOL> event . save ( ) <EOL> assert event . data . get_ref ( event ) != event . data . get_ref ( invalid_event ) <EOL> with pytest . raises ( NodeIntegrityFailure ) : <EOL> Event . objects . bind_nodes ( [ event ] , '<STR_LIT:data>' ) <EOL> def test_accepts_valid_ref ( self ) : <EOL> event = self . create_event ( ) <EOL> event . data . bind_ref ( event ) <EOL> event . save ( ) <EOL> Event . objects . bind_nodes ( [ event ] , '<STR_LIT:data>' ) <EOL> assert event . data . ref == event . project . id <EOL> def test_basic_ref_binding ( self ) : <EOL> event = self . create_event ( ) <EOL> assert event . data . get_ref ( event ) == event . project . id </s>
