44
55import errno
66import os
7- try :
8- import unittest2 as unittest
9- except ImportError :
10- import unittest
7+ import unittest
118import tempfile
129import shutil
1310import re
1714import random
1815from configparser import ConfigParser
1916
20- from parameterized import parameterized
17+ import pytest
2118
2219
2320# Path to the actual CGI script that should be tested
6360CACHE_DIR = 'srv/cache/lookaside'
6461
6562
66- class UploadTest ( unittest . TestCase ) :
63+ class TestUpload :
6764
68- def setUp (self ):
65+ def setup_method (self ):
6966 self .hostname = 'localhost'
7067 # Koji can run multiple builds on the same host in parallel
7168 self .port = random .randrange (10000 , 20000 , step = 1 )
@@ -93,7 +90,7 @@ def setUp(self):
9390 self .setup_module (module )
9491 self .touch ('%s/%s/hello.txt/%s/hello.txt' % (CACHE_DIR , module , HASH ))
9592
96- def tearDown (self ):
93+ def teardown_method (self ):
9794 shutil .rmtree (self .topdir )
9895 if not self .server .poll ():
9996 # The server did not exit yet, so let's kill it.
@@ -152,7 +149,7 @@ def upload(self, name, hash, hashtype='md5', filename=None, filepath=None, mtime
152149
153150 response = requests .post (self .url , data = args , files = files )
154151 self ._log_output ()
155- self . assertEqual ( response .status_code , 200 )
152+ assert response .status_code == 200
156153 return response .text
157154
158155 def touch (self , filename , contents = None ):
@@ -174,85 +171,85 @@ def setup_module(self, name):
174171
175172 def assertFileExists (self , module_name , filename , hash , mtime = None ):
176173 path = os .path .join (self .topdir , CACHE_DIR , module_name , filename , hash , filename )
177- self . assertTrue ( os .path .exists (path ), '%s should exist' % path )
174+ assert os .path .exists (path ), '%s should exist' % path
178175 if mtime :
179- self . assertEqual ( os .stat (path ).st_mtime , mtime )
176+ assert os .stat (path ).st_mtime == mtime
180177
181- @parameterized . expand ( EXISTING_MODULES + OLD_FILE_MODULES )
178+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES + OLD_FILE_MODULES )
182179 def test_check_existing_file (self , module , ns_module ):
183180 resp = self .upload (module , hash = HASH , filename = 'hello.txt' )
184- self . assertEqual ( resp , 'Available\n ' )
181+ assert resp == 'Available\n '
185182
186- @parameterized . expand ( EXISTING_MODULES )
183+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
187184 def test_check_existing_file_with_bad_hash (self , module , ns_module ):
188185 resp = self .upload (module , hash = 'abc' , filename = 'hello.txt' )
189- self . assertEqual ( resp , 'Missing\n ' )
186+ assert resp == 'Missing\n '
190187
191- @parameterized . expand ( EXISTING_MODULES )
188+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
192189 def test_check_missing_file (self , module , ns_module ):
193190 resp = self .upload (module , hash = 'abc' , filename = 'foo.txt' )
194- self . assertEqual ( resp , 'Missing\n ' )
191+ assert resp == 'Missing\n '
195192
196- @parameterized . expand ( EXISTING_MODULES )
193+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
197194 def test_upload_file (self , module , ns_module ):
198195 test_file = self .touch ('new.txt' )
199196 resp = self .upload (module , hash = NEW_HASH , filepath = test_file )
200- self . assertEqual ( resp , 'File new.txt size 7 MD5 %s stored OK\n ' % NEW_HASH )
197+ assert resp == 'File new.txt size 7 MD5 %s stored OK\n ' % NEW_HASH
201198 self .assertFileExists (ns_module , 'new.txt' , NEW_HASH )
202199 self .assertFileExists (ns_module , 'new.txt' , 'md5/' + NEW_HASH )
203200
204- @parameterized . expand ( EXISTING_MODULES )
201+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
205202 def test_upload_file_bad_checksum (self , module , ns_module ):
206203 test_file = self .touch ('hello.txt' )
207204 resp = self .upload (module , hash = 'ABC' , filepath = test_file )
208- self . assertEqual ( resp , 'MD5 check failed. Received %s instead of ABC.\n ' % HASH )
205+ assert resp == 'MD5 check failed. Received %s instead of ABC.\n ' % HASH
209206
210- @parameterized . expand ( NON_EXISTING_MODULES )
207+ @pytest . mark . parametrize ( "module,ns_module" , NON_EXISTING_MODULES )
211208 def test_upload_to_non_existing_module (self , module , ns_module ):
212209 test_file = self .touch ('hello.txt' )
213210 resp = self .upload (module , hash = HASH , filepath = test_file )
214- self . assertEqual ( resp , 'Module "%s" does not exist!\n ' % ns_module )
211+ assert resp == 'Module "%s" does not exist!\n ' % ns_module
215212
216- @parameterized . expand ( EXISTING_MODULES )
213+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
217214 def test_rejects_unknown_hash (self , module , ns_module ):
218215 test_file = self .touch ('hello.txt' )
219216 resp = self .upload (module , hash = 'deadbeef' , hashtype = 'crc32' , filepath = test_file )
220- self . assertEqual ( resp , "Required checksum is not present\n " )
217+ assert resp == "Required checksum is not present\n "
221218
222- @parameterized . expand ( EXISTING_MODULES )
219+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
223220 def test_accepts_sha_512_hash (self , module , ns_module ):
224221 test_file = self .touch ('new.txt' )
225222 resp = self .upload (module , hash = NEW_SHA512 , hashtype = 'sha512' , filepath = test_file )
226- self . assertEqual ( resp , 'File new.txt size 7 SHA512 %s stored OK\n ' % NEW_SHA512 )
223+ assert resp == 'File new.txt size 7 SHA512 %s stored OK\n ' % NEW_SHA512
227224 self .assertFileExists (ns_module , 'new.txt' , 'sha512/' + NEW_SHA512 )
228225
229- @parameterized . expand ( EXISTING_MODULES )
226+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
230227 def test_bad_sha512_hash (self , module , ns_module ):
231228 test_file = self .touch ('hello.txt' )
232229 resp = self .upload (module , hash = 'ABC' , hashtype = 'sha512' , filepath = test_file )
233- self . assertEqual ( resp , 'SHA512 check failed. Received %s instead of ABC.\n ' % SHA512 )
230+ assert resp == 'SHA512 check failed. Received %s instead of ABC.\n ' % SHA512
234231
235- @parameterized . expand ( EXISTING_MODULES )
232+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
236233 def test_check_existing_sha512_correct (self , module , ns_module ):
237234 resp = self .upload (module , hash = SHA512 , hashtype = 'sha512' , filename = 'hello.txt' )
238- self . assertEqual ( resp , 'Available\n ' )
235+ assert resp == 'Available\n '
239236
240- @parameterized . expand ( EXISTING_MODULES )
237+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
241238 def test_check_existing_sha512_mismatch (self , module , ns_module ):
242239 resp = self .upload (module , hash = 'abc' , hashtype = 'sha512' , filename = 'hello.txt' )
243- self . assertEqual ( resp , 'Missing\n ' )
240+ assert resp == 'Missing\n '
244241
245- @parameterized . expand ( EXISTING_MODULES )
242+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
246243 def test_upload_mtime (self , module , ns_module ):
247244 test_file = self .touch ('new.txt' )
248245 resp = self .upload (module , hash = NEW_HASH , filepath = test_file , mtime = "1234" )
249246 self .assertFileExists (ns_module , 'new.txt' , NEW_HASH , mtime = 1234 )
250247
251- @parameterized . expand ( EXISTING_MODULES )
248+ @pytest . mark . parametrize ( "module,ns_module" , EXISTING_MODULES )
252249 def test_upload_invalid_mtime (self , module , ns_module ):
253250 test_file = self .touch ('new.txt' )
254251 resp = self .upload (module , hash = NEW_HASH , filepath = test_file , mtime = "abc" )
255- self . assertEqual ( resp , 'Invalid value sent for mtime "abc". Aborting.\n ' )
252+ assert resp == 'Invalid value sent for mtime "abc". Aborting.\n '
256253
257254
258255def _copy_tweak (source_file , dest_file , topdir ):
0 commit comments