Пример #1
0
def test_vcard_data_invalid_bday():
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max',
                                'Max Mustermann',
                                birthday='19760919')
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max',
                                'Max Mustermann',
                                birthday='1976-09-19TZ')
Пример #2
0
def test_vcard_data_rev():
    expected_vcard_data = 'BEGIN:VCARD\r\n' \
                          'VERSION:3.0\r\n' \
                          'N:Mustermann;Max\r\n' \
                          'FN:Max Mustermann\r\n' \
                          'REV:1976-09-19\r\n' \
                          'END:VCARD\r\n'
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    rev='1976-09-19')
    assert expected_vcard_data == vcard
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    rev=date(year=1976, month=9, day=19))
    assert expected_vcard_data == vcard
Пример #3
0
def test_vcard_title_escape():
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    title='Director, Research and Development')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'TITLE:Director\\, Research and Development\r\n' \
           'END:VCARD\r\n' == vcard
Пример #4
0
def test_photo_uri():
    photo_uris = ('https://www.example.org/image.jpg', 'https://www.example.com/image_another.gif')
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', photo_uri=photo_uris)
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nPHOTO;VALUE=uri:{0}\r\nPHOTO;VALUE=uri:{1}\r\nEND:VCARD\r\n'.format(*photo_uris) == vcard
    qr_from_data = segno.make_qr(vcard)
    assert qr_from_data
    assert qr_from_data.error == 'L'
    qr_from_vcard = helpers.make_vcard('Doe;John', 'John Doe', photo_uri=photo_uris)
    assert qr_from_vcard
    assert qr_from_vcard.error == 'L'
    assert qr_from_data == qr_from_vcard
Пример #5
0
def test_vcard_data_note():
    note = 'test cases,; we need more test cases'
    expected_vcard_data = 'BEGIN:VCARD\r\n' \
                          'VERSION:3.0\r\n' \
                          'N:Mustermann;Max\r\n' \
                          'FN:Max Mustermann\r\n' \
                          'NOTE:test cases\\,\\; we need more test cases\r\n' \
                          'END:VCARD\r\n'
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    memo=note)
    assert expected_vcard_data == vcard
Пример #6
0
def test_vcard_data_valid_geo():
    expected_vcard_data = 'BEGIN:VCARD\r\n' \
                          'VERSION:3.0\r\n' \
                          'N:Mustermann;Max\r\n' \
                          'FN:Max Mustermann\r\n' \
                          'GEO:46.235197;8.015445\r\n' \
                          'END:VCARD\r\n'
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    lat=46.235197,
                                    lng=8.015445)
    assert expected_vcard_data == vcard
Пример #7
0
def test_vcard_data_nickname():
    nickname = 'Mäxchen'
    expected_vcard_data = 'BEGIN:VCARD\r\n' \
                          'VERSION:3.0\r\n' \
                          'N:Mustermann;Max\r\n' \
                          'FN:Max Mustermann\r\n' \
                          'NICKNAME:{}\r\n' \
                          'END:VCARD\r\n'.format(nickname)
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    nickname=nickname)
    assert expected_vcard_data == vcard
Пример #8
0
def test_vcard_data_source_url():
    source_url = 'https://example.org/this-is-the-SOURCE-url'
    expected_vcard_data = 'BEGIN:VCARD\r\n' \
                          'VERSION:3.0\r\n' \
                          'N:Mustermann;Max\r\n' \
                          'FN:Max Mustermann\r\n' \
                          'SOURCE:{}\r\n' \
                          'END:VCARD\r\n'.format(source_url)
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    source=source_url)
    assert expected_vcard_data == vcard
Пример #9
0
def test_vcard_data_invalid_rev():
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', rev='19760919')
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', rev='1976-09-19TZ')
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', rev='1976-09-19T-06')
Пример #10
0
def test_vcard_data():
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    org='ABC, Inc.')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nORG:ABC\, Inc.\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data(
        'Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.', 'John Stevenson')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.\r\nFN:John Stevenson\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    street='Street',
                                    city='City',
                                    zipcode='123456')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nADR:;;Street;City;;123456;\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    street='123 Main Street',
                                    city='Any Town',
                                    region='CA',
                                    zipcode='91921-1234',
                                    country='Nummerland')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nADR:;;123 Main Street;Any Town;CA;91921-1234;Nummerland\r\nEND:VCARD\r\n' == vcard
Пример #11
0
def test_vcard_data():
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', org='ABC, Inc.')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nORG:ABC\, Inc.\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.', 'John Stevenson')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.\r\nFN:John Stevenson\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', street='Street', city='City', zipcode='123456')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nADR:;;Street;City;;123456;\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', street='123 Main Street', city='Any Town',
                                    region='CA', zipcode='91921-1234', country='Nummerland')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nADR:;;123 Main Street;Any Town;CA;91921-1234;Nummerland\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', title='Python wrangler')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nTITLE:Python wrangler\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe',
                                    title=['Python wrangler', 'Snake charmer'])
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nTITLE:Python wrangler\r\nTITLE:Snake charmer\r\nEND:VCARD\r\n' == vcard
    photo_uri = 'https://www.example.org/image.jpg'
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', photo_uri=photo_uri)
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nPHOTO;VALUE=uri:{0}\r\nEND:VCARD\r\n'.format(photo_uri) == vcard
    photo_uris = ('https://www.example.org/image.jpg', 'https://www.example.com/image_another.gif')
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', photo_uri=photo_uris)
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nPHOTO;VALUE=uri:{0}\r\nPHOTO;VALUE=uri:{1}\r\nEND:VCARD\r\n'.format(*photo_uris) == vcard
Пример #12
0
def test_vcard_data():
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', org='ABC, Inc.')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nORG:ABC\\, Inc.\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.', 'John Stevenson')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.\r\nFN:John Stevenson\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', street='Street', city='City', zipcode='123456')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nADR:;;Street;City;;123456;\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', street='123 Main Street', city='Any Town',
                                    region='CA', zipcode='91921-1234', country='Nummerland')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nADR:;;123 Main Street;Any Town;CA;91921-1234;Nummerland\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', title='Python wrangler')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nTITLE:Python wrangler\r\nEND:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe',
                                    title=['Python wrangler', 'Snake charmer'])
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nTITLE:Python wrangler\r\nTITLE:Snake charmer\r\nEND:VCARD\r\n' == vcard
    photo_uri = 'https://www.example.org/image.jpg'
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', photo_uri=photo_uri)
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nPHOTO;VALUE=uri:{0}\r\nEND:VCARD\r\n'.format(photo_uri) == vcard
    photo_uris = ('https://www.example.org/image.jpg', 'https://www.example.com/image_another.gif')
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe', photo_uri=photo_uris)
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nPHOTO;VALUE=uri:{0}\r\nPHOTO;VALUE=uri:{1}\r\nEND:VCARD\r\n'.format(*photo_uris) == vcard
Пример #13
0
def test_vcard_data_invalid_rev():
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max',
                                'Max Mustermann',
                                rev='19760919')
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max',
                                'Max Mustermann',
                                rev='1976-09-19TZ')
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max',
                                'Max Mustermann',
                                rev='1976-09-19T-06')
Пример #14
0
def get_vcard_qrcode(request, *args, **kwargs):
    if request.method == 'POST':
        vcard_form = vCardForm(request.POST)
        if vcard_form.is_valid():
            config = helpers.make_vcard_data(
                name=vcard_form.cleaned_data['vcard_name'],
                displayname=vcard_form.cleaned_data['vcard_display_name'],
                nickname=vcard_form.cleaned_data['vcard_nick_name'],
                phone=vcard_form.cleaned_data['vcard_phone'],
                email=vcard_form.cleaned_data['vcard_email'],
                fax=vcard_form.cleaned_data['vcard_fax'],
                url=vcard_form.cleaned_data['vcard_url'],
                street=vcard_form.cleaned_data['vcard_street'],
                city=vcard_form.cleaned_data['vcard_city'],
                country=vcard_form.cleaned_data['vcard_country'],
                zipcode=vcard_form.cleaned_data['vcard_zipcode'],
                lat=vcard_form.cleaned_data['vcard_lat'],
                lng=vcard_form.cleaned_data['vcard_lng'])
            image = segno.make(config, micro=False, error="h")
            buffer = BytesIO()
            image.save(buffer, "PNG", scale=7, dark='black', light='white')
            img_str = base64.b64encode(buffer.getvalue())
            return str(img_str.decode("utf-8"))
Пример #15
0
def test_vcard_title_escape():
    vcard = helpers.make_vcard_data('Doe;John', 'John Doe',
                                    title='Director, Research and Development')
    assert 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Doe;John\r\nFN:John Doe\r\nTITLE:Director\, Research and Development\r\nEND:VCARD\r\n' == vcard
Пример #16
0
def test_vcard_data_invalid_geo():
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', lat=1.234)
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', lng=1.234)
Пример #17
0
def test_vcard_data_invalid_rev(rev):
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', rev=rev)
Пример #18
0
def test_vcard_data_valid_bday():
    expected_vcard_data = 'BEGIN:VCARD\r\nVERSION:3.0\r\nN:Mustermann;Max\r\nFN:Max Mustermann\r\nBDAY:1976-09-19\r\nEND:VCARD\r\n'
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', birthday='1976-09-19')
    assert expected_vcard_data == vcard
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', birthday=date(year=1976, month=9, day=19))
    assert expected_vcard_data == vcard
#Generation of QR code
#STEP 1: Prepare the data in the form of 'vCard' data structure
#STEP 2: Convert 'vCard' into 'QRCode' data structure
#STEP 3: Save it as image

import segno
from segno import helpers

#STEP 1: Prepare the data in the form of 'vCard' data structure
#Reference:
#https://pypi.org/project/segno/
#https://readthedocs.org/projects/segno/downloads/pdf/0.3.0/
vcard = helpers.make_vcard_data(name='EFG;ABCD',
                                displayname='Abcd Efg',
                                email='*****@*****.**',
                                phone='+1234567890',
                                url='http://www.abcd.org')
print(vcard)

#STEP 2: Convert 'vCard' into 'QRCode' data structure
qr = segno.make(vcard)

#STEP 3: Save it as image
qr.save('abcd.png', scale=4)

#Load and display the QRCode image
#We use 'openCV' library for loading image, and
#For displaying the image we use 'matplotlib' library

import cv2
Пример #20
0
def test_vcard_data():
    vcard = helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Mustermann;Max\r\n' \
           'FN:Max Mustermann\r\n' \
           'END:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Mustermann;Max',
                                    'Max Mustermann',
                                    org='ABC, Inc.')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Mustermann;Max\r\n' \
           'FN:Max Mustermann\r\n' \
           'ORG:ABC\\, Inc.\r\n' \
           'END:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data(
        'Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.', 'John Stevenson')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P.\r\n' \
           'FN:John Stevenson\r\n' \
           'END:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    street='Street',
                                    city='City',
                                    zipcode='123456')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'ADR:;;Street;City;;123456;\r\n' \
           'END:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    street='123 Main Street',
                                    city='Any Town',
                                    region='CA',
                                    zipcode='91921-1234',
                                    country='Nummerland')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'ADR:;;123 Main Street;Any Town;CA;91921-1234;Nummerland\r\n' \
           'END:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    title='Python wrangler')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\nFN:John Doe\r\n' \
           'TITLE:Python wrangler\r\n' \
           'END:VCARD\r\n' == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    title=['Python wrangler', 'Snake charmer'])
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'TITLE:Python wrangler\r\n' \
           'TITLE:Snake charmer\r\n' \
           'END:VCARD\r\n' == vcard
    photo_uri = 'https://www.example.org/image.jpg'
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    photo_uri=photo_uri)
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'PHOTO;VALUE=uri:{0}\r\n' \
           'END:VCARD\r\n'.format(photo_uri) == vcard
    photo_uris = ('https://www.example.org/image.jpg',
                  'https://www.example.com/image_another.gif')
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    photo_uri=photo_uris)
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'PHOTO;VALUE=uri:{0}\r\n' \
           'PHOTO;VALUE=uri:{1}\r\n' \
           'END:VCARD\r\n'.format(*photo_uris) == vcard
    vcard = helpers.make_vcard_data('Doe;John',
                                    'John Doe',
                                    phone='+1',
                                    fax='+12',
                                    videophone='+123',
                                    cellphone='+1234',
                                    homephone='+12345',
                                    workphone='+123456')
    assert 'BEGIN:VCARD\r\n' \
           'VERSION:3.0\r\n' \
           'N:Doe;John\r\n' \
           'FN:John Doe\r\n' \
           'TEL:+1\r\n' \
           'TEL;TYPE=FAX:+12\r\n' \
           'TEL;TYPE=VIDEO:+123\r\n' \
           'TEL;TYPE=CELL:+1234\r\n' \
           'TEL;TYPE=HOME:+12345\r\n' \
           'TEL;TYPE=WORK:+123456\r\n' \
           'END:VCARD\r\n' == vcard
Пример #21
0
def test_vcard_data_invalid_bday():
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', birthday='19760919')
    with pytest.raises(ValueError):
        helpers.make_vcard_data('Mustermann;Max', 'Max Mustermann', birthday='1976-09-19TZ')