Unverified Commit 82f4566f authored by Damian Johnson's avatar Damian Johnson Committed by Philipp Winter
Browse files

Type fix for generation of qrcodes

Fixing the following test failures...

  Traceback (most recent call last):
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_qrcodes.py", line 49, in test_generateQR
      self.assertTrue(qrcodes.generateQR(self.bridgelines))
    File "/usr/local/lib/python3.5/dist-packages/twisted/trial/_synctest.py", line 395, in assertTrue
      super(_Assertions, self).assertTrue(condition, msg)
    File "/usr/lib/python3.5/unittest/case.py", line 677, in assertTrue
      raise self.failureException(msg)
  twisted.trial.unittest.FailTest: None is not true

The actual problem was being masked by another catch-all...

  Traceback (most recent call last):
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_qrcodes.py", line 68, in test_generateQR_bridgeSchema
      self.assertTrue(qrcodes.generateQR(self.bridgelines, bridgeSchema=True))
    File "/home/atagar/Desktop/tor/bridgedb/bridgedb/qrcodes.py", line 65, in generateQR
      img.save(buf, imageFormat)
    File "/usr/local/lib/python3.5/dist-packages/PIL/Image.py", line 2084, in save
      save_handler(self, fp, filename)
    File "/usr/local/lib/python3.5/dist-packages/PIL/JpegImagePlugin.py", line 770, in _save
      ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize)
    File "/usr/local/lib/python3.5/dist-packages/PIL/ImageFile.py", line 513, in _save
      fp.write(d)
  builtins.TypeError: string argument expected, got 'bytes'

Test results changed as follows...

  before: FAILED (skips=115, failures=23, successes=846)
  after:  FAILED (skips=115, failures=21, successes=848)
parent 34d1eeb0
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ except ImportError: # pragma: no cover
                   "python-qrcode package."))


def generateQR(bridgelines, imageFormat=u'JPEG', bridgeSchema=False):
def generateQR(bridgelines, imageFormat='JPEG', bridgeSchema=False):
    """Generate a QRCode for the client's bridge lines.

    :param str bridgelines: The Bridge Lines which we are distributing to the
@@ -60,7 +60,7 @@ def generateQR(bridgelines, imageFormat=u'JPEG', bridgeSchema=False):
        qr = qrcode.QRCode()
        qr.add_data(bridgelines)

        buf = io.StringIO()
        buf = io.BytesIO()
        img = qr.make_image().resize([350, 350])
        img.save(buf, imageFormat)
        buf.seek(0)