| Conditions | 4 |
| Total Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # coding: utf8 |
||
| 102 | @temporary_media_root(MEDIA_URL='http://cache.pack.google.com/edgedl/chrome/install/782.112/') |
||
| 103 | @patch('omaha.models.version_upload_to', lambda o, f: f) |
||
| 104 | def test_userid_counting(self): |
||
| 105 | now = datetime.utcnow() |
||
| 106 | userid = '{D0BBD725-742D-44ae-8D46-0231E881D58E}' |
||
| 107 | user_id = get_id(userid) |
||
| 108 | appid1 = '{430FD4D0-B729-4F61-AA34-91526481799D}' |
||
| 109 | appid2 = '{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}' |
||
| 110 | install_date = datetime(year=2014, month=1, day=1, hour=15, minute=41, second=48) |
||
| 111 | update_date = install_date + timedelta(days=31) |
||
| 112 | |||
| 113 | request_events = DayEvents('request', install_date.year, install_date.month, install_date.day) |
||
| 114 | app1_install_events = DayEvents('new_install:%s' % appid1, install_date.year, install_date.month, install_date.day) |
||
| 115 | app2_install_events = DayEvents('new_install:%s' % appid2, install_date.year, install_date.month, install_date.day) |
||
| 116 | app1_update_events = DayEvents('request:%s' % appid1, update_date.year, update_date.month, update_date.day) |
||
| 117 | app2_update_events = DayEvents('request:%s' % appid2, update_date.year, update_date.month, update_date.day) |
||
| 118 | |||
| 119 | self.assertEqual(len(request_events), 0) |
||
| 120 | self.assertEqual(len(app1_install_events), 0) |
||
| 121 | self.assertEqual(len(app2_install_events), 0) |
||
| 122 | |||
| 123 | app = ApplicationFactory.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='chrome') |
||
| 124 | platform = PlatformFactory.create(name='win') |
||
| 125 | channel = ChannelFactory.create(name='stable') |
||
| 126 | obj = VersionFactory.create( |
||
| 127 | app=app, |
||
| 128 | platform=platform, |
||
| 129 | channel=channel, |
||
| 130 | version='13.0.782.112', |
||
| 131 | file=SimpleUploadedFile('./chrome_installer.exe', b'_' * 23963192)) |
||
| 132 | obj.file_hash = 'VXriGUVI0TNqfLlU02vBel4Q3Zo=' |
||
| 133 | obj.save() |
||
| 134 | |||
| 135 | Action.objects.create( |
||
| 136 | version=obj, |
||
| 137 | arguments='--do-not-launch-chrome', |
||
| 138 | event=EVENT_DICT_CHOICES['install'], |
||
| 139 | run='chrome_installer.exe' |
||
| 140 | ) |
||
| 141 | |||
| 142 | Action.objects.create( |
||
| 143 | version=obj, |
||
| 144 | event=EVENT_DICT_CHOICES['postinstall'], |
||
| 145 | other=dict( |
||
| 146 | version='13.0.782.112', |
||
| 147 | onsuccess='exitsilentlyonlaunchcmd', |
||
| 148 | ) |
||
| 149 | ) |
||
| 150 | |||
| 151 | with freeze_time(install_date): # 56508 sec |
||
| 152 | self.client.post(reverse('update'), |
||
| 153 | fixtures.request_update_check, content_type='text/xml') |
||
| 154 | |||
| 155 | self.assertEqual(len(request_events), 1) |
||
| 156 | self.assertEqual(len(app1_install_events), 1) |
||
| 157 | self.assertEqual(len(app2_install_events), 1) |
||
| 158 | self.assertTrue(user_id in request_events) |
||
| 159 | self.assertTrue(user_id in app1_install_events) |
||
| 160 | self.assertTrue(user_id in app2_install_events) |
||
| 161 | |||
| 162 | with freeze_time(update_date): |
||
| 163 | self.client.post(reverse('update'), |
||
| 164 | fixtures.request_update_check, content_type='text/xml') |
||
| 165 | |||
| 166 | self.assertEqual(len(app1_update_events), 1) |
||
| 167 | self.assertEqual(len(app2_update_events), 1) |
||
| 168 | self.assertTrue(user_id in app1_update_events) |
||
| 169 | self.assertTrue(user_id in app2_update_events) |
||
| 170 | |||
| 234 |