Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Uses the new onegov.testing webtest client
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Jul 13, 2017
1 parent 13c2508 commit 3391c3a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 130 deletions.
95 changes: 0 additions & 95 deletions onegov/org/testing.py

This file was deleted.

2 changes: 1 addition & 1 deletion onegov/org/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from onegov.org.initial_content import create_new_organisation
from onegov.org.layout import DefaultLayout
from onegov.org.new_elements import Element
from onegov.org.testing import Client
from onegov.testing import Client
from onegov.testing.utils import create_app
from onegov.user import User

Expand Down
6 changes: 5 additions & 1 deletion onegov/org/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from onegov.org.app import OrgApp
from onegov.org.forms import ExportForm
from onegov.org.models import Export
from onegov.org.testing import Client
from onegov.testing import Client as BaseClient


class Client(BaseClient):
skip_first_form = True


def test_export(request):
Expand Down
70 changes: 38 additions & 32 deletions onegov/org/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
import textwrap
import transaction

from base64 import b64decode, b64encode
from contextlib import contextmanager
from datetime import datetime, date, timedelta
from libres.modules.errors import AffectedReservationError
from lxml.html import document_fromstring
from onegov.core.utils import Bunch
from onegov.form import FormCollection, FormSubmission
from onegov.reservation import ResourceCollection, Reservation
from onegov.newsletter import RecipientCollection
from onegov.org.testing import Client
from onegov.org.testing import decode_map_value
from onegov.org.testing import encode_map_value
from onegov.org.testing import extract_href
from onegov.org.testing import get_message
from onegov.org.testing import select_checkbox
from onegov.testing import Client as BaseClient
from onegov.page import PageCollection
from onegov.pay import PaymentProviderCollection
from onegov.people import Person
from onegov.reservation import ResourceCollection, Reservation
from onegov.testing import utils
from onegov.ticket import TicketCollection
from onegov.user import UserCollection
from purl import URL
from webtest import Upload


class Client(BaseClient):
skip_first_form = True


def bound_reserve(client, allocation):

default_start = '{:%H:%M}'.format(allocation.start)
Expand Down Expand Up @@ -62,6 +62,14 @@ def reserve(
return reserve


def encode_map_value(dictionary):
return b64encode(json.dumps(dictionary).encode('utf-8'))


def decode_map_value(value):
return json.loads(b64decode(value).decode('utf-8'))


@contextmanager
def temporary_setting(app, section, setting, value):
section = getattr(app.settings, section)
Expand Down Expand Up @@ -1190,7 +1198,7 @@ def test_allocations(org_app):
assert slots.json[0]['title'] == "Ganztägig \nVerfügbar"

# change the daypasses
edit = client.get(extract_href(slots.json[0]['actions'][0]))
edit = client.get(client.extract_href(slots.json[0]['actions'][0]))
edit.form['daypasses'] = 2
edit.form.submit()

Expand Down Expand Up @@ -1220,11 +1228,11 @@ def test_allocations(org_app):
'?start=2015-08-04&end=2015-08-05'
))

edit = client.get(extract_href(slots.json[0]['actions'][0]))
edit = client.get(client.extract_href(slots.json[0]['actions'][0]))
edit.form['date'] = '2015-08-06'
edit.form.submit()

edit = client.get(extract_href(slots.json[1]['actions'][0]))
edit = client.get(client.extract_href(slots.json[1]['actions'][0]))
edit.form['date'] = '2015-08-07'
edit.form.submit()

Expand All @@ -1237,7 +1245,7 @@ def test_allocations(org_app):
assert len(slots.json) == 2

# delete an allocation
client.delete(extract_href(slots.json[0]['actions'][2]))
client.delete(client.extract_href(slots.json[0]['actions'][2]))

# get the new slots
slots = client.get((
Expand All @@ -1248,7 +1256,7 @@ def test_allocations(org_app):
assert len(slots.json) == 1

# delete an allocation
client.delete(extract_href(slots.json[0]['actions'][2]))
client.delete(client.extract_href(slots.json[0]['actions'][2]))

# get the new slots
slots = client.get((
Expand Down Expand Up @@ -1381,7 +1389,7 @@ def test_reserve_allocation(org_app):
assert len(slots.json) == 1

with pytest.raises(AffectedReservationError):
client.delete(extract_href(slots.json[0]['actions'][2]))
client.delete(client.extract_href(slots.json[0]['actions'][2]))

# open the created ticket
ticket = client.get('/tickets/ALL/open').click('Annehmen').follow()
Expand Down Expand Up @@ -2055,15 +2063,15 @@ def test_reserve_and_deny_multiple_dates(org_app):
client.get(ticket.pyquery('a.delete-link')[-1].attrib['ic-get-from'])
assert resource.scheduler.managed_reserved_slots().count() == 2

message = get_message(org_app, 1)
message = client.get_email(1)
assert "abgesagt" in message
assert "29. April 2016" in message

# accept the others
ticket = ticket.click('Alle Reservationen annehmen').follow()
assert resource.scheduler.managed_reserved_slots().count() == 2

message = get_message(org_app, 2)
message = client.get_email(2)
assert "angenommen" in message
assert "27. April 2016" in message
assert "28. April 2016" in message
Expand All @@ -2072,7 +2080,7 @@ def test_reserve_and_deny_multiple_dates(org_app):
client.get(ticket.pyquery('a.delete-link')[-1].attrib['ic-get-from'])
assert resource.scheduler.managed_reserved_slots().count() == 1

message = get_message(org_app, 3)
message = client.get_email(3)
assert "abgesagt" in message
assert "27. April 2016" not in message
assert "28. April 2016" in message
Expand All @@ -2081,7 +2089,7 @@ def test_reserve_and_deny_multiple_dates(org_app):
client.get(ticket.pyquery('a.delete-link')[-1].attrib['ic-get-from'])
assert resource.scheduler.managed_reserved_slots().count() == 0

message = get_message(org_app, 4)
message = client.get_email(4)
assert "abgesagt" in message
assert "27. April 2016" in message
assert "28. April 2016" not in message
Expand Down Expand Up @@ -2652,10 +2660,8 @@ def test_newsletters_crud(org_app):
new = newsletter.click('Newsletter')
new.form['title'] = "Our town is AWESOME"
new.form['lead'] = "Like many of you, I just love our town..."

select_checkbox(new, "occurrences", "150 Jahre Govikon")
select_checkbox(new, "occurrences", "Gemeinsames Turnen")

new.select_checkbox("occurrences", "150 Jahre Govikon")
new.select_checkbox("occurrences", "Gemeinsames Turnen")
newsletter = new.form.submit().follow()

assert newsletter.pyquery('h1').text() == "Our town is AWESOME"
Expand All @@ -2667,7 +2673,7 @@ def test_newsletters_crud(org_app):

edit = newsletter.click("Bearbeiten")
edit.form['title'] = "I can't even"
select_checkbox(edit, "occurrences", "150 Jahre Govikon", checked=False)
edit.select_checkbox("occurrences", "150 Jahre Govikon", checked=False)

newsletter = edit.form.submit().follow()

Expand Down Expand Up @@ -2783,9 +2789,9 @@ def test_newsletter_send(org_app):
new.form['title'] = "Our town is AWESOME"
new.form['lead'] = "Like many of you, I just love our town..."

select_checkbox(new, "news", "Willkommen bei OneGov")
select_checkbox(new, "occurrences", "150 Jahre Govikon")
select_checkbox(new, "occurrences", "Gemeinsames Turnen")
new.select_checkbox("news", "Willkommen bei OneGov")
new.select_checkbox("occurrences", "150 Jahre Govikon")
new.select_checkbox("occurrences", "Gemeinsames Turnen")

newsletter = new.form.submit().follow()

Expand All @@ -2808,8 +2814,8 @@ def test_newsletter_send(org_app):

len(send.pyquery('input[name="recipients"]')) == 2

select_checkbox(send, 'recipients', 'one@example.org', checked=True)
select_checkbox(send, 'recipients', 'two@example.org', checked=False)
send.select_checkbox('recipients', 'one@example.org', checked=True)
send.select_checkbox('recipients', 'two@example.org', checked=False)

newsletter = send.form.submit().follow()

Expand Down Expand Up @@ -3027,12 +3033,12 @@ def test_registration(org_app):

assert "Vielen Dank" in register.form.submit().follow()

message = get_message(org_app, 0, 1)
message = client.get_email(0, 1)
assert "Anmeldung bestätigen" in message

expr = r'href="[^"]+">Anmeldung bestätigen</a>'
url = re.search(expr, message).group()
url = extract_href(url)
url = client.extract_href(url)

faulty = URL(url).query_param('token', 'asdf').as_string()

Expand Down Expand Up @@ -3183,7 +3189,7 @@ def test_add_new_user_with_activation_email(org_app):
assert "Passwort" not in added
assert "Anmeldungs-Anleitung wurde an den Benutzer gesendet" in added

email = get_message(org_app, 0)
email = client.get_email(0)
reset = re.search(r'(http://localhost/reset-password[^)]+)', email).group()

page = Client(org_app).get(reset)
Expand Down Expand Up @@ -3417,8 +3423,8 @@ def test_manual_form_payment(org_app):
assert '5.00 CHF' in page

page.form['e_mail'] = 'info@example.org'
select_checkbox(page, 'posters', "Executive Committee")
select_checkbox(page, 'posters', "Town Square")
page.select_checkbox('posters', "Executive Committee")
page.select_checkbox('posters', "Town Square")
page.form['delivery'] = 'Delivery'

page = page.form.submit().follow()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_long_description():
'onegov.testing',
'pyquery',
'pytest-localserver',
'requests-mock',
'requests-mock'
],
),
entry_points={
Expand Down

0 comments on commit 3391c3a

Please sign in to comment.