Files
firefox/testing/mozbase/mozhttpd/tests/basic.py
T
Andrew Halberstadt bce781d9b8 Bug 1373294 - Fix E305 (two blank lines after method or class) in files enabled by flake8 linter, r=jmaher
This is needed before we can upgrade to flake8 3.3.0, as that version starts flagging these errors.

These files were modified by running:
autopep8 --select E305 --in-place -r <dir>

on the affected directories. I did it one dir at a time and verified the result after each.

MozReview-Commit-ID: FmlsfiKIbtr
2017-06-15 12:10:59 -04:00

50 lines
1.2 KiB
Python

#!/usr/bin/env python
import mozhttpd
import mozfile
import os
import tempfile
import unittest
import mozunit
class TestBasic(unittest.TestCase):
""" Test basic Mozhttpd capabilites """
def test_basic(self):
""" Test mozhttpd can serve files """
tempdir = tempfile.mkdtemp()
# sizes is a dict of the form: name -> [size, binary_string, filepath]
sizes = {'small': [128], 'large': [16384]}
for k in sizes.keys():
# Generate random binary string
sizes[k].append(os.urandom(sizes[k][0]))
# Add path of file with binary string to list
fpath = os.path.join(tempdir, k)
sizes[k].append(fpath)
# Write binary string to file
with open(fpath, 'wb') as f:
f.write(sizes[k][1])
server = mozhttpd.MozHttpd(docroot=tempdir)
server.start()
server_url = server.get_url()
# Retrieve file and check contents matchup
for k in sizes.keys():
retrieved_content = mozfile.load(server_url + k).read()
self.assertEqual(retrieved_content, sizes[k][1])
# Cleanup tempdir and related files
mozfile.rmtree(tempdir)
if __name__ == '__main__':
mozunit.main()