<s> """<STR_LIT>""" <EOL> from datetime import datetime , timedelta <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from django . core . urlresolvers import reverse <EOL> from django . core . files . uploadedfile import SimpleUploadedFile <EOL> from xmlunittest import XmlTestMixin <EOL> from freezegun import freeze_time <EOL> from mock import patch <EOL> from bitmapist import DayEvents <EOL> from omaha . tests import fixtures <EOL> from omaha . tests . utils import temporary_media_root <EOL> from omaha . factories import ApplicationFactory , ChannelFactory , PlatformFactory , VersionFactory <EOL> from omaha . models import Action , Request , EVENT_DICT_CHOICES , Data , NAME_DATA_DICT_CHOICES <EOL> from omaha . utils import redis , get_id <EOL> class UpdateViewTest ( TestCase , XmlTestMixin ) : <EOL> def setUp ( self ) : <EOL> self . client = Client ( ) <EOL> redis . flushdb ( ) <EOL> def tearDown ( self ) : <EOL> redis . flushdb ( ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_updatecheck_negative ( self ) : <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> fixtures . request_update_check , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertXmlDocument ( response . content ) <EOL> self . assertXmlEquivalentOutputs ( response . content , <EOL> fixtures . response_update_check_negative ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> @ temporary_media_root ( MEDIA_URL = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , lambda o , f : f ) <EOL> def test_updatecheck_positive ( self ) : <EOL> app = ApplicationFactory . create ( id = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> platform = PlatformFactory . create ( name = '<STR_LIT>' ) <EOL> channel = ChannelFactory . create ( name = '<STR_LIT>' ) <EOL> obj = VersionFactory . create ( <EOL> app = app , <EOL> platform = platform , <EOL> channel = channel , <EOL> version = '<STR_LIT>' , <EOL> file = SimpleUploadedFile ( '<STR_LIT>' , b'<STR_LIT:_>' * <NUM_LIT> ) , <EOL> file_size = <NUM_LIT> ) <EOL> obj . file_hash = '<STR_LIT>' <EOL> obj . save ( ) <EOL> Action . objects . create ( <EOL> version = obj , <EOL> arguments = '<STR_LIT>' , <EOL> event = EVENT_DICT_CHOICES [ '<STR_LIT>' ] , <EOL> run = '<STR_LIT>' <EOL> ) <EOL> Action . objects . create ( <EOL> version = obj , <EOL> event = EVENT_DICT_CHOICES [ '<STR_LIT>' ] , <EOL> other = dict ( <EOL> version = '<STR_LIT>' , <EOL> onsuccess = '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> fixtures . request_update_check , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertXmlDocument ( response . content ) <EOL> self . assertXmlEquivalentOutputs ( response . content , <EOL> fixtures . response_update_check_positive ) <EOL> @ temporary_media_root ( MEDIA_URL = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , lambda o , f : f ) <EOL> def test_userid_counting ( self ) : <EOL> now = datetime . utcnow ( ) <EOL> userid = '<STR_LIT>' <EOL> user_id = get_id ( userid ) <EOL> appid1 = '<STR_LIT>' <EOL> appid2 = '<STR_LIT>' <EOL> install_date = datetime ( year = <NUM_LIT> , month = <NUM_LIT:1> , day = <NUM_LIT:1> , hour = <NUM_LIT:15> , minute = <NUM_LIT> , second = <NUM_LIT> ) <EOL> update_date = install_date + timedelta ( days = <NUM_LIT> ) <EOL> request_events = DayEvents ( '<STR_LIT>' , install_date . year , install_date . month , install_date . day ) <EOL> app1_install_events = DayEvents ( '<STR_LIT>' % appid1 , install_date . year , install_date . month , install_date . day ) <EOL> app2_install_events = DayEvents ( '<STR_LIT>' % appid2 , install_date . year , install_date . month , install_date . day ) <EOL> app1_update_events = DayEvents ( '<STR_LIT>' % appid1 , update_date . year , update_date . month , update_date . day ) <EOL> app2_update_events = DayEvents ( '<STR_LIT>' % appid2 , update_date . year , update_date . month , update_date . day ) <EOL> self . assertEqual ( len ( request_events ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( app1_install_events ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( app2_install_events ) , <NUM_LIT:0> ) <EOL> app = ApplicationFactory . create ( id = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> platform = PlatformFactory . create ( name = '<STR_LIT>' ) <EOL> channel = ChannelFactory . create ( name = '<STR_LIT>' ) <EOL> obj = VersionFactory . create ( <EOL> app = app , <EOL> platform = platform , <EOL> channel = channel , <EOL> version = '<STR_LIT>' , <EOL> file = SimpleUploadedFile ( '<STR_LIT>' , b'<STR_LIT:_>' * <NUM_LIT> ) ) <EOL> obj . file_hash = '<STR_LIT>' <EOL> obj . save ( ) <EOL> Action . objects . create ( <EOL> version = obj , <EOL> arguments = '<STR_LIT>' , <EOL> event = EVENT_DICT_CHOICES [ '<STR_LIT>' ] , <EOL> run = '<STR_LIT>' <EOL> ) <EOL> Action . objects . create ( <EOL> version = obj , <EOL> event = EVENT_DICT_CHOICES [ '<STR_LIT>' ] , <EOL> other = dict ( <EOL> version = '<STR_LIT>' , <EOL> onsuccess = '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> with freeze_time ( install_date ) : <EOL> self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> fixtures . request_update_check , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( request_events ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( app1_install_events ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( app2_install_events ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( user_id in request_events ) <EOL> self . assertTrue ( user_id in app1_install_events ) <EOL> self . assertTrue ( user_id in app2_install_events ) <EOL> with freeze_time ( update_date ) : <EOL> self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> fixtures . request_update_check , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( len ( app1_update_events ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( app2_update_events ) , <NUM_LIT:1> ) <EOL> self . assertTrue ( user_id in app1_update_events ) <EOL> self . assertTrue ( user_id in app2_update_events ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> def test_event ( self ) : <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> fixtures . request_event , <EOL> REMOTE_ADDR = "<STR_LIT>" , <EOL> content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertXmlDocument ( response . content ) <EOL> self . assertXmlEquivalentOutputs ( response . content , <EOL> fixtures . response_event ) <EOL> request = Request . objects . get ( ) <EOL> self . assertEqual ( request . ip , '<STR_LIT>' ) <EOL> @ freeze_time ( '<STR_LIT>' ) <EOL> @ temporary_media_root ( MEDIA_URL = '<STR_LIT>' ) <EOL> @ patch ( '<STR_LIT>' , lambda o , f : f ) <EOL> def test_data ( self ) : <EOL> app = ApplicationFactory . create ( id = '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> platform = PlatformFactory . create ( name = '<STR_LIT>' ) <EOL> channel = ChannelFactory . create ( name = '<STR_LIT>' ) <EOL> obj = VersionFactory . create ( <EOL> app = app , <EOL> platform = platform , <EOL> channel = channel , <EOL> version = '<STR_LIT>' , <EOL> file = SimpleUploadedFile ( '<STR_LIT>' , b'<STR_LIT:_>' * <NUM_LIT> ) , <EOL> file_size = <NUM_LIT> ) <EOL> obj . file_hash = '<STR_LIT>' <EOL> obj . save ( ) <EOL> Data . objects . create ( <EOL> app = app , <EOL> name = NAME_DATA_DICT_CHOICES [ '<STR_LIT>' ] , <EOL> index = '<STR_LIT>' , <EOL> value = '<STR_LIT>' ) <EOL> Data . objects . create ( <EOL> app = app , <EOL> name = NAME_DATA_DICT_CHOICES [ '<STR_LIT>' ] ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , <EOL> fixtures . request_data , content_type = '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertXmlDocument ( response . content ) <EOL> self . assertXmlEquivalentOutputs ( response . content , <EOL> fixtures . response_data ) <EOL> def test_bad_request ( self ) : <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) ) <EOL> msg = b"""<STR_LIT>""" <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( response . content , msg ) </s>
