Ejemplo n.º 1
0
def test_vote_success_different_orgs_same_person():
    settings.TEST_TIME = datetime(1923, 1, 3)
    place = Place(
        name="Testplace",
        description="foo",
        )
    place.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="1234",
        electionname=e,
        hasvoted=False,
        votestyle=0,
        hetu='foob',
        organization='tukkk.fi',
        id=1,
        )
    p.save()
    p1 = Person(
        personnumber="2345",
        electionname=e,
        hasvoted=False,
        votestyle=0,
        hetu='foob',
        organization='utu.fi',
        id=2,
        )
    p1.save()
    c = Client()
    User(username='******', password='******').save()

    fake_request = HttpRequest()
    fake_request.META['HTTP_MAIL'] = '*****@*****.**'
    fake_request.META['HTTP_DISPLAYNAME'] = ''
    fake_request.META['HTTP_SN'] = ''

    c.login(request=fake_request)
    response = c.post(
        '/tarkistus/commit/',
        {'number': '1234', 'organization': 'tukkk.fi', 'place': 1}
        )
    eq(response.status_code, 200)
    try:
        cont = simplejson.loads(response.content)
    except ValueError, e:
        print response.content
        raise
Ejemplo n.º 2
0
def test_vote_different_submit():
    place = Place(
        name="Testplace",
        description="foo",
        )
    place.save()
    splace = Place(name='Submit')
    splace.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="1234",
        electionname=e,
        hasvoted=True,
        votestyle=0,
        hetu='foob',
        organization='tukkk.fi',
        id=1,
        )
    p.save()
    u = User(username='******', password='******')
    u.save()
    t = Ticket(
        voter=p,
        release_place=place,
        releaser=u,
        )
    t.save()
    c = Client()

    fake_request = HttpRequest()
    fake_request.META['HTTP_MAIL'] = '*****@*****.**'
    fake_request.META['HTTP_DISPLAYNAME'] = ''
    fake_request.META['HTTP_SN'] = ''

    c.login(request=fake_request)
    response = c.post(
        '/tarkistus/commit/',
        {'number': '1234', 'organization': 'tukkk.fi', 'place': 2}
        )
    eq(response.status_code, 200)
    try:
        c = simplejson.loads(response.content)
    except ValueError, e:
        print response.content
        raise
Ejemplo n.º 3
0
def test_get_person_data():
    t = Place(
        name='Testplace',
        description='Foo',
        )
    t.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="123",
        electionname=e,
        lastname="bar",
        firstname="foo",
        emailaddress="foo@bar",
        address="...",
        hasvoted=False,
        votestyle=1,
        hetu='foob',
        organization='tse',
        id=1,
        )
    p.save()
    c = Client()
    User(username='******', password='******').save()

    fake_request = HttpRequest()
    fake_request.META['HTTP_MAIL'] = '*****@*****.**'
    fake_request.META['HTTP_DISPLAYNAME'] = ''
    fake_request.META['HTTP_SN'] = ''

    c.login(request=fake_request)
    response = c.post(
        '/tarkistus/whois/',
        {'number': '123',
         'organization': 'tse',
         'place': 1,}
        )
    eq(response.status_code, 200)
    try:
        c = simplejson.loads(response.content)
    except ValueError, e:
        print response.content
        raise
Ejemplo n.º 4
0
def test_vote_no_ticket():
    place = Place(
        name="Testplace",
        description="foo",
        )
    place.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="1234",
        electionname=e,
        hasvoted=True,
        votestyle=1,
        votedate=datetime(2009,1,1,18,0),
        hetu='foob',
        organization='tukkk.fi',
        id=1,
        )
    p.save()
    c = Client()
    User(username='******', password='******').save()

    fake_request = HttpRequest()
    fake_request.META['HTTP_MAIL'] = '*****@*****.**'
    fake_request.META['HTTP_DISPLAYNAME'] = ''
    fake_request.META['HTTP_SN'] = ''

    c.login(request=fake_request)
    response = c.post(
        '/tarkistus/commit/',
        {'number': '1234', 'organization': 'tukkk.fi', 'place': 1}
        )
    eq(response.status_code, 200)
    try:
        c = simplejson.loads(response.content)
    except ValueError:
        print repr(response.content)
        raise
    eq(
        c['errors'],
        {'__all__': ['Person has already voted.']}
        )
Ejemplo n.º 5
0
def test_json_serializer():
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="123",
        electionname=e,
        hasvoted=True,
        votestyle=1,
        hetu='foob',
        organization='tse.fi',
        )
    p.save()

    person = Person.objects.get(personnumber='123')
    r = utils.serialized_json_response([person])
    assert isinstance(r, HttpResponse)
    eq(r['Content-Type'], 'application/json')
    try:
        c = simplejson.loads(r.content)
    except ValueError:
        print repr(r.content)
        raise
    c = c[0]
    eq(c['model'], 'votechecker.person')
    eq(c['fields'], {
            'personnumber': '123',
            'hasvoted': True,
            'city': None,
            'firstname': None,
            'electionname': 'testelect',
            'votestyle': 1,
            'hetu': 'foob',
            'votedate': None,
            'emailaddress': None,
            'address': None,
            'zipcode': None,
            'organization': 'tse.fi',
            'password': None,
            'lastname': None,
            })
Ejemplo n.º 6
0
def view_empty_tickets_list():
    place = Place(name='Foobarland')
    place.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    response = c.get('/tarkistus/list/%d/' % place.id)
    eq(response.status_code, 200)
    eq(response.content, simplejson.dump([]))
Ejemplo n.º 7
0
def test_form_wrong_org():
    t = Place(
        name='Testplace',
        description='Foo',
        )
    t.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="123",
        electionname=e,
        lastname="bar",
        firstname="foo",
        emailaddress="foo@bar",
        address="...",
        hasvoted=True,
        votestyle=1,
        hetu='foob',
        organization='utu.fi',
        )
    p.save()
    f = VoterForm({'organization': 'tse.fi', 'number': '123', 'place': 1})
    assert not f.is_valid()
    eq(f.errors,
       {
            '__all__': ['Invalid student number']
            })
Ejemplo n.º 8
0
def test_get_tickets_out():
    u = User(username='******', password='******')
    u.save()

    place = Place(name='Foobarland')
    place.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        personnumber="42434",
        electionname=e,
        hasvoted=False,
        votestyle=0,
        hetu='foob',
        organization='tukkk.fi',
        id=1,
        )
    p.save()
    p.give_slip(place, u)
    p = Person(
        personnumber="1234",
        electionname=e,
        hasvoted=False,
        votestyle=0,
        hetu='foob',
        organization='utu.fi',
        id=2,
        )
    p.save()
    p.give_slip(place, u)
    p = Person(
        personnumber="32234",
        electionname=e,
        hasvoted=False,
        votestyle=0,
        hetu='foob',
        organization='tukkk.fi',
        id=3,
        )
    p.save()
    p.give_slip(place, u)
    c = Client()

    fake_request = HttpRequest()
    fake_request.META['HTTP_MAIL'] = '*****@*****.**'
    fake_request.META['HTTP_DISPLAYNAME'] = ''
    fake_request.META['HTTP_SN'] = ''

    c.login(request=fake_request)
    response = c.get('/tarkistus/list/%d/' % place.id)
    eq(response.status_code, 200)
    try:
        c = simplejson.loads(response.content)
    except ValueError:
        print response.content
        raise
    eq(len(c), 3)
    eq(c,
       [{'number': '1234', 'organization': 'utu.fi'},
        {'number': '32234', 'organization': 'tukkk.fi'},
        {'number': '42434', 'organization': 'tukkk.fi'},
        ])
Ejemplo n.º 9
0
def test_vote_whole_procedure():
    place = Place(
        name="Testplace",
        description="foo",
        )
    place.save()
    e = Election(
        name="testelect",
        password="******",
        authurl="bar",
        isopen=True,
        production=True,
        ispublic=True,
        firstpassword=True,
        secondpassword=True,
        stv=True,
        government=True,
        toelect=100,
        )
    e.save()
    p = Person(
        id=1,
        personnumber="1234",
        electionname=e,
        hasvoted=False,
        votestyle=0,
        hetu='foob',
        organization='tukkk.fi'
        )
    p.save()
    c = Client()
    User(username='******', password='******').save()

    fake_request = HttpRequest()
    fake_request.META['HTTP_MAIL'] = '*****@*****.**'
    fake_request.META['HTTP_DISPLAYNAME'] = ''
    fake_request.META['HTTP_SN'] = ''

    c.login(request=fake_request)
    settings.TEST_TIME = datetime(1900, 1, 1)
    response = c.post('/tarkistus/commit/',
                      {'number': '1234', 'organization': 'tukkk.fi', 'place': 1})
    eq(response.status_code, 200)
    eq(response.content, simplejson.dumps({'ok': 'OK. Give ticket.'}))
    t = Ticket.objects.get(
        release_place=place,
        release_time=datetime(1900, 1, 1),
        voter=p,
        submit_place=None,
        submit_time=None,
        )
    settings.TEST_TIME = datetime(1900, 1, 2)
    response = c.post('/tarkistus/commit/',
                      {'number': '1234', 'organization': 'tukkk.fi', 'place': 1})
    eq(response.status_code, 200)
    eq(response.content,
       simplejson.dumps({'ok': 'OK. Ticket can be stamped.'}))
    t = Ticket.objects.get(
        release_place=place,
        release_time=datetime(1900, 1, 1),
        voter=p,
        submit_place=place,
        submit_time=datetime(1900, 1, 2),
        )

    response = c.post('/tarkistus/commit/',
                      {'number': '1234', 'organization': 'tukkk.fi', 'place': 1})
    eq(response.status_code, 200)
    eq(response.content,
       simplejson.dumps(
            {'errors': {'__all__':
                            ['Person has voted in Testplace on 02.01.1900'+
                             ' at 00:00']}}))
    Person.objects.get(
        personnumber="1234",
        electionname=e,
        hasvoted=True,
        votestyle=1,
        hetu='foob',
        organization='tukkk.fi',
        votedate=datetime(1900, 1, 2),
        id=1,
        )