def test_download_package_not_found(self): app = MrPyPi(self._test_index()) status, headers, content = app.request('GET', '/download/packageUnknown/1.0.1/packageUnknown-1.0.1.tar.gz') self.assertEqual(status, '404 Not Found') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'Not Found')
def test_index_not_found(self): app = MrPyPi(self._test_index()) status, headers, content = app.request('GET', '/simple/packageUnknown') self.assertEqual(status, '404 Not Found') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'Not Found')
def test_download(self): app = MrPyPi(self._test_index()) status, headers, content = app.request('GET', '/download/package1/1.0.1/package1-1.0.1.tar.gz') self.assertEqual(status, '200 OK') self.assertTrue(('Content-Type', 'application/octet-stream') in headers) self.assertEqual(content, b'package1-1.0.1')
def test_download_filename_mismatch(self): app = MrPyPi(self._test_index()) status, headers, content = app.request('GET', '/download/package1/1.0.1/package2-1.0.2.tar.gz') self.assertEqual(status, '404 Not Found') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'Not Found')
def test_upload_bad_content(self): upload_environ = { 'CONTENT_TYPE': 'multipart/form-data; boundary=--------------GHSKFJDLGDS7543FJKLFHRE75642756743254', } upload_content = b''' ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="filetype" sdist ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="content";filename="package3-1.0.0.tar.gz" ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="version" 1.0.0 ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name=":action" file_upload ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="name" package3 ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254-- ''' app = MrPyPi(self._test_index()) status, headers, content = app.request('POST', '/simple', environ=upload_environ, wsgi_input=upload_content) self.assertEqual(status, '400 Bad Request') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'')
def test_upload_bad_content(self): upload_content = b'''\ ---123 Content-Disposition: form-data; name="filetype" sdist ---123 Content-Disposition: form-data; name="content";filename="package3-1.0.0.tar.gz" ---123 Content-Disposition: form-data; name="version" 1.0.0 ---123 Content-Disposition: form-data; name=":action" file_upload ---123 Content-Disposition: form-data; name="name" package3 ---123-- ''' upload_environ = { 'CONTENT_LENGTH': str(len(upload_content)), 'CONTENT_TYPE': 'multipart/form-data; boundary=-123' } app = MrPyPi(self._test_index()) status, headers, content = app.request('POST', '/simple', environ=upload_environ, wsgi_input=upload_content) self.assertEqual(status, '400 Bad Request') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'Bad Request')
def test_upload_bad_content_type(self): upload_environ = { 'CONTENT_TYPE': 'text/plain', } upload_content = b'' app = MrPyPi(self._test_index()) status, headers, content = app.request('POST', '/simple', environ=upload_environ, wsgi_input=upload_content) self.assertEqual(status, '400 Bad Request') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'')
def test_index_unverified(self): app = MrPyPi(self._test_index()) status, headers, content = app.request('GET', '/simple/package2') self.assertEqual(status, '200 OK') self.assertTrue(('Content-Type', 'text/html') in headers) expected_content = b'''\ <!doctype html> <html lang="en"> <head> <title>Links for package2</title> <meta name="api-version" value="2"> </head> <body> <h1>Links for package2</h1> <a href="../../download/package2/1.0.0/package2-1.0.0.tar.gz#md5=e5bb63cbaf57f917dec872455807ea9a" rel="internal">package2-1.0.0.tar.gz</a><br> <a href="../../download/package2/1.0.1/package2-1.0.1.tar.gz#md5=5196a17e0ebf66da9ac16f09a836d60f" rel="internal">package2-1.0.1.tar.gz</a><br> </body> </html>''' self.assertEqual(content, expected_content)
def test_mrpypi_pypi_index(self): app = MrPyPi(self._test_index()) status, headers, content = app.request('GET', '/simple/package1') self.assertEqual(status, '200 OK') self.assertTrue(('Content-Type', 'text/html') in headers) expected_content = b'''\ <!doctype html> <html lang="en"> <head> <title>Links for package1</title> <meta name="api-version" value="2"> </head> <body> <h1>Links for package1</h1> <a href="../../download/package1/1.0.0/package1-1.0.0.tar.gz#md5=5f832e6e6b2107ba3b0463fc171623d7" rel="internal">package1-1.0.0.tar.gz</a><br> <a href="../../download/package1/1.0.1/package1-1.0.1.tar.gz#md5=7ff99f5a955518cece354b9a0e94007d" rel="internal">package1-1.0.1.tar.gz</a><br> </body> </html>''' self.assertEqual(content, expected_content)
def test_upload(self): upload_environ = { 'CONTENT_TYPE': 'multipart/form-data; boundary=--------------GHSKFJDLGDS7543FJKLFHRE75642756743254', } upload_content = b''' ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="filetype" sdist ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="content";filename="package3-1.0.0.tar.gz" package3 content ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="version" 1.0.0 ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name=":action" file_upload ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254 Content-Disposition: form-data; name="name" package3 ----------------GHSKFJDLGDS7543FJKLFHRE75642756743254-- ''' app = MrPyPi(self._test_index()) status, headers, content = app.request('POST', '/simple', environ=dict(upload_environ), wsgi_input=upload_content) self.assertEqual(status, '200 OK') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'') status, headers, content = app.request('POST', '/simple', environ=upload_environ, wsgi_input=upload_content) self.assertEqual(status, '400 File Exists') self.assertTrue(('Content-Type', 'text/plain') in headers) self.assertEqual(content, b'') status, headers, content = app.request('GET', '/simple/package3') self.assertEqual(status, '200 OK') self.assertTrue(('Content-Type', 'text/html') in headers) expected_content = b'''\ <!doctype html> <html lang="en"> <head> <title>Links for package3</title> <meta name="api-version" value="2"> </head> <body> <h1>Links for package3</h1> <a href="../../download/package3/1.0.0/package3-1.0.0.tar.gz#md5=df9f61bece81c091f7044368fcf62501" rel="internal">package3-1.0.0.tar.gz</a><br> </body> </html>''' self.assertEqual(content, expected_content) status, headers, content = app.request('GET', '/download/package3/1.0.0/package3-1.0.0.tar.gz') self.assertEqual(status, '200 OK') self.assertTrue(('Content-Type', 'application/octet-stream') in headers) self.assertEqual(content, b'package3 content')