Skip to content

Commit

Permalink
Merge branch 'master' of git+ssh://github.com/sydney-linux-user-group…
Browse files Browse the repository at this point in the history
…/slug
  • Loading branch information
mithro committed May 29, 2012
2 parents 5bd5e01 + a5f0e65 commit db4ff3d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 10 deletions.
9 changes: 9 additions & 0 deletions doc/hitlist.rst
Expand Up @@ -130,6 +130,8 @@ Done in :func:`TestEventEditing.test_republished_event_shows_as_ready_for_reanno
* Load the event list as an anonymous user
* Verify that the event list shows the new issue details

Done in :func:`TestEventEditing.test_republished_event_displays_for_anonymous_user`

Re-announce a re-published event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -158,12 +160,19 @@ Anonymous user clicks "offers a talk"
* Click "Offer Talk"
* Get redirected to the login page

.. py:currentmodule:: usergroup.selenium_tests.talk_offer_test
Done in :func:`TestAnonymousUserClicksOffer.test_anonymous_user_clicks_offer_talk`

Logged-in user offers a talk
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* Browse the main page as a logged-in user
* Click "Offer Talk"
* A second window opens with the "Offer Talk" form

Done in :func:`TestLoggedInUserClicksLogin.test_logged_in_user_clicks_offer_talk`

* Enter values into all fields
* Submit the form
* Verify that the window has redirected to "/offer/add#prevoffers"
Expand Down
22 changes: 22 additions & 0 deletions usergroup/django_tests/event_manipulation_test.py
Expand Up @@ -239,3 +239,25 @@ def test_republished_event_shows_as_ready_for_reannouncement(self):
self.assertContains(
response, '<form name="sendemail" action="/event/1/email"')

def test_republished_event_displays_for_anonymous_user(self):
self.buffer = True
self.request_data['name'] = 'Republished Meeting'
self.client.post('/event/1', data=self.request_data)
self.client.post('/event/1/publish')
self.client.logout()
response = self.client.get('/events')
self.assertContains(
response, '<a class=eventname href="/event/1">Republished '
'Meeting</a>')

def test_reannounced_event_shows_reannounced(self):
self.buffer = True
self.request_data['name'] = 'Republished Meeting'
self.request_data['input'] = 'Republished location'
self.client.post('/event/1', data=self.request_data)
self.client.post('/event/1/publish')
self.client.post('/event/1/email', follow=True)
body = django.core.mail.outbox[1].body
subject = django.core.mail.outbox[1].subject
self.assertIn('Republished Meeting', subject)
self.assertIn('Republished location', body)
26 changes: 26 additions & 0 deletions usergroup/django_tests/talk_offer_test.py
@@ -0,0 +1,26 @@
#!/usr/bin/env python
"""Tests around creating, publishing, and announcing meetings.
Does not use selenium, so cannot test client behaviour."""

import datetime
import random

import django.test

import usergroup.event_edit

#TestCases have lots of public methods
#pylint: disable=R0904

class TestTalkOfferLogin(django.test.TestCase):
"""Before we test anything else, let's see if login actually works"""
fixtures = ['test_admin_user', 'test_existing_user']

def test_offer_page(self):
"""Ensure that the offer page loads."""
self.client.login(username='existing', password='password')
offer_page = self.client.get("/offer/add")
self.assertContains(offer_page, 'input name="consent"')


14 changes: 5 additions & 9 deletions usergroup/offer_edit.py
Expand Up @@ -24,32 +24,28 @@

@auth.login_required
@method.require_http_methods(["GET", "POST"])
def handler(request):
def handler(request, key):
"""Handler for creating and editing Event objects."""

q = models.TalkOffer.objects.all()
if not request.user.is_staff():
if not request.user.is_staff:
q = q.filter(created_by__exact=request.user)
offers = q[:100]

# /offer/<key> (POST/Get)
# /offer/add (POST/Get)
try:
unused_offer, key = request.path_info.split('/')
except IndexError:
return shortcuts.redirect('/offers')

if key == 'add':
offer = models.Offer()
offer = models.TalkOffer()
else:
offer = shortcuts.get_object_or_404(models.TalkOffer, pk=key)

if request.method == 'GET':
offer_list = q[:100]

return shortcut.render(
return shortcuts.render(request,
'offertalk.html', {
'offer': offer, 'offer_list': offers, 'self': self})
'offer': offer, 'offer_list': offers})
elif request.method == 'POST':
return handler_edit(request, offer, offers)

Expand Down
46 changes: 46 additions & 0 deletions usergroup/selenium_tests/talk_offer_test.py
@@ -0,0 +1,46 @@
#!/usr/bin/python
#
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:

"""Uses webdriver to test the login work flow.
Steps are:
* A new user can sign up for the website.
* Can sign up for an event.
* Can cancel their sign up.
"""

import re

from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
import time

from django.core import mail
from django.utils import unittest
from django import test as djangotest

from base import SeleniumTestCase


class TestAnonymousUserClicksOffer(SeleniumTestCase):

def test_anonymous_user_clicks_offer_talk(self):
self.assertEqual(1, len(self.browser.window_handles))
offer_link = self.browser.find_element_by_id('offer')
self.assertEqual(1, len(self.browser.window_handles))

class TestLoggedInUserClicksOffer(SeleniumTestCase):

fixtures = [ 'test_admin_user', 'test_existing_user' ]

def test_logged_in_user_clicks_offer_talk(self):
"""Check that talk offer page opens in new window"""
self.doLogin(username="existing", password="password")
self.assertEqual(1, len(self.browser.window_handles))
offer_link = self.browser.find_element_by_id('offer')
self.assertEqual(1, len(self.browser.window_handles))
2 changes: 1 addition & 1 deletion usergroup/templates/index.html
Expand Up @@ -60,7 +60,7 @@ <h2> Sponsor </h2>
<td id=speak class="box hover">
<a href="/offer/add">
<h2> Give a talk </h2>
<span class=minor> Educate your fellows </span>
<span class=minor id=offer> Educate your fellows </span>
</a>
</td>
<tr>
Expand Down

0 comments on commit db4ff3d

Please sign in to comment.