-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Jupyter support for QRCode auth (Closes #36)
- Loading branch information
1 parent
763e63d
commit 439da44
Showing
4 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from qrcode import QRCode | ||
|
||
|
||
def print_qr_code(uuid: str): | ||
qr = QRCode() | ||
qr.add_data(uuid) | ||
try: | ||
get_ipython | ||
from IPython.display import display | ||
display(qr.make_image(fill_color="#111", back_color="#ccc")) | ||
except NameError: | ||
qr.print_ascii(invert=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pytest==3.2.2 | ||
pytest-cov==2.5.1 | ||
python-coveralls==2.9.1 | ||
python-coveralls==2.9.1 | ||
pillow==6.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import builtins | ||
|
||
import pytest | ||
from qrcode import QRCode | ||
|
||
from pynubank import utils | ||
|
||
|
||
@pytest.mark.skip(reason="no way of currently testing this") | ||
def test_print_qr_code_on_jupyter_prints_image(monkeypatch): | ||
def fake_print(x): | ||
raise Exception('Should not call print') | ||
|
||
def fake_ipython(): | ||
pass | ||
|
||
try: | ||
builtins.get_ipython = fake_ipython | ||
|
||
monkeypatch.setattr('builtins.print', fake_print) | ||
utils.print_qr_code('some-uuid-1234') | ||
finally: | ||
del (builtins.get_ipython) | ||
|
||
|
||
def test_print_qr_code_on_terminal_prints_ascii(): | ||
def fake_make_image(self, image_factory=None, **kwargs): | ||
raise Exception('Should not call make_image') | ||
|
||
QRCode.make_image = fake_make_image | ||
utils.print_qr_code('some-uuid-1234') |