mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-11-21 09:01:31 -08:00
remove cv2 because QRCodeDetector is broken and replace with decode from
pyzbar.pyzbar
This commit is contained in:
parent
9a15dc8bb6
commit
f00b2df592
@ -3,9 +3,9 @@ from django.contrib.auth.models import User
|
|||||||
from accounts.models import Account
|
from accounts.models import Account
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import cv2
|
|
||||||
from cairosvg import svg2png
|
from cairosvg import svg2png
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from pyzbar.pyzbar import decode
|
||||||
import pyotp
|
import pyotp
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
@ -77,10 +77,10 @@ class TestEnableTOTPViewTestCase(TestCase):
|
|||||||
background = Image.new("RGB", t_image.size, (255, 255, 255))
|
background = Image.new("RGB", t_image.size, (255, 255, 255))
|
||||||
background.paste(t_image, mask=t_image.split()[3])
|
background.paste(t_image, mask=t_image.split()[3])
|
||||||
background.save('qr.jpg', "JPEG", quality=100)
|
background.save('qr.jpg', "JPEG", quality=100)
|
||||||
image = cv2.imread('qr.jpg')
|
image = Image.open('qr.jpg')
|
||||||
qr_det = cv2.QRCodeDetector()
|
img_data = decode(image)
|
||||||
qrdata = qr_det.detectAndDecode(image)
|
qr_data = img_data[0].data.decode("utf-8")
|
||||||
totp_code = pyotp.TOTP(pyotp.parse_uri(qrdata[0]).secret).now()
|
totp_code = pyotp.TOTP(pyotp.parse_uri(qr_data).secret).now()
|
||||||
response = self.client.post(reverse('accounts:enable_totp'), {
|
response = self.client.post(reverse('accounts:enable_totp'), {
|
||||||
'totp_code': totp_code}, follow=True)
|
'totp_code': totp_code}, follow=True)
|
||||||
self.assertEquals(response.status_code, 200)
|
self.assertEquals(response.status_code, 200)
|
||||||
@ -88,7 +88,7 @@ class TestEnableTOTPViewTestCase(TestCase):
|
|||||||
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
|
self.assertEquals(response.request['PATH_INFO'], '/accounts/edit-profile/')
|
||||||
user_a = User.objects.get(username='user_a')
|
user_a = User.objects.get(username='user_a')
|
||||||
self.assertTrue(user_a.account.use_totp)
|
self.assertTrue(user_a.account.use_totp)
|
||||||
self.assertEquals(len(user_a.account.totp_key), 16)
|
self.assertEquals(len(user_a.account.totp_key), 32)
|
||||||
pathlib.Path('qr.svg').unlink()
|
pathlib.Path('qr.svg').unlink()
|
||||||
pathlib.Path('qr.png').unlink()
|
pathlib.Path('qr.png').unlink()
|
||||||
pathlib.Path('qr.jpg').unlink()
|
pathlib.Path('qr.jpg').unlink()
|
||||||
|
Loading…
Reference in New Issue
Block a user