Skip to content

Commit

Permalink
fix functional test and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
simodalla committed Mar 11, 2014
1 parent 51db0b0 commit 04d043a
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 39 deletions.
19 changes: 15 additions & 4 deletions functional_tests/test_simple_booking_creation.py
Expand Up @@ -11,8 +11,9 @@

from django.test.utils import override_settings

from nowait.tests.factories import UserF, BookingType30F, RootNowaitPageF
from nowait.models import SlotTime
from nowait.tests.factories import (UserF, BookingType30F, RootNowaitPageF,
MyBookingLinkF)
from nowait.models import Booking, SlotTime
from .base import FunctionalTest


Expand All @@ -21,6 +22,7 @@ def setUp(self):
super(UserCreateBookingTest, self).setUp()
self.user = UserF()
self.root = RootNowaitPageF()
MyBookingLinkF()
# self.create_pre_authenticated_session(self.admin)
# 2013-9-9 is a Monday
start = date(2013, 9, 9)
Expand Down Expand Up @@ -51,13 +53,15 @@ def test_user_choose_slottime_make_login_and_create_booking(
left_panel_tree = self.get_left_panel_tree()
left_panel_tree.find_element_by_link_text(
self.bookingtype.title).click()

# user click on link "Make your reservation"
self.browser.find_element_by_partial_link_text(
'Make your reservation').click()
slottime_selected = self.browser.find_elements_by_css_selector(
'.tab-content .active a.thumbnail')[0]
slottime_selected_id = slottime_selected.get_attribute('id')
slottime_selected.click()

# user is redirected to login page and now insert his credentials
self.browser.find_element_by_id('id_username').send_keys(
self.user.username)
Expand All @@ -77,9 +81,8 @@ def test_user_choose_slottime_make_login_and_create_booking(
self.live_server_url + reverse(
'nowait:slottime_select',
kwargs={'slug': self.bookingtype.slug}))

# user insert optionl data notes and telephone and confirm the booking
import ipdb
ipdb.set_trace()
notes = "Additional notes to me"
telephone = "0518800990"
self.browser.find_element_by_name('notes').send_keys(notes)
Expand All @@ -92,3 +95,11 @@ def test_user_choose_slottime_make_login_and_create_booking(
self.assertEqual(slottime.booking.telephone, telephone)
self.assertEqual(slottime.booking.booker, self.user)

# user is redirected to list of Booking and click on link for view
# detail
table = self.browser.find_element_by_id('booking_list')
table.find_element_by_link_text(str(slottime.booking.pk)).click()

table = self.browser.find_element_by_id('booking_detail')
print(table)

2 changes: 1 addition & 1 deletion nowait/models.py
Expand Up @@ -107,7 +107,7 @@ def get_or_create_link(self):
except ImproperlyConfigured as e:
raise e
link, created = Link.objects.get_or_create(
slug=self.get_absolute_url(),
slug=self.get_absolute_url().rstrip('/').lstrip('/'),
parent=root_page,
defaults={'title': self.title})
if self.link != link:
Expand Down
22 changes: 22 additions & 0 deletions nowait/templates/nowait/booking_detail.html
@@ -0,0 +1,22 @@
{% extends 'pages/page.html' %}
{% load l10n i18n %}

{% block breadcrumb_menu %}
{{ block.super }}
<li class="active">
{{ title }}
</li>
{% endblock %}

{% block main %}
{{ block.super }}
<table id="booking_detail" class="table table-striped table-bordered table-center">
<tbody>
<tr><th>{% trans "Id" %}</th><td>{{ booking.pk }}</td></tr>
<tr><th>{% trans "Type" %}</th><td>{{ booking.slottime.booking_type.title }}</td></tr>
<tr><th>{% trans "Date" %}</th><td>{{ booking.slottime.start|date:"l d F Y" }}</td></tr>
<tr><th>{% trans "Start Time" %}</th><td>{{ booking.slottime.start|date:"H:i" }}</td></tr>
<tr><th>{% trans "End Time" %}</th><td>{{ booking.slottime.end|date:"H:i" }}</td></tr>
</tbody>
</table>
{% endblock %}
52 changes: 27 additions & 25 deletions nowait/templates/nowait/booking_list.html
Expand Up @@ -12,33 +12,35 @@
{% block main %}
{{ block.super }}
{% if booking_list %}
<table id="booking_list" class="table table-striped">
<thead>
<tr>
<th>{% trans "Id" %}</th>
<th>{% trans "Type" %}</th>
<th>{% trans "Date" %}</th>
<th>{% trans "Start Time" %}</th>
<th>{% trans "End Time" %}</th>
</tr>
</thead>
<tbody>
{% for booking in booking_list %}
<div class="table-responsive">
<table id="booking_list" class="table table-striped">
<thead>
<tr>
<td>
<a href="{% url 'nowait:booking_detail' booking.pk %}"
title="{% trans "View details of booking with id" %}&nbsp;{{ booking.pk }}">
{{ booking.pk }}
</a>
</td>
<td>{{ booking.slottime.booking_type.title }}</td>
<td>{{ booking.slottime.start|date:"l d F Y" }}</td>
<td>{{ booking.slottime.start|date:"H:i" }}</td>
<td>{{ booking.slottime.end|date:"H:i" }}</td>
<th>{% trans "Id" %}</th>
<th>{% trans "Type" %}</th>
<th>{% trans "Date" %}</th>
<th>{% trans "Start Time" %}</th>
<th>{% trans "End Time" %}</th>
</tr>
{% endfor %}
</tbody>
</table>
</thead>
<tbody>
{% for booking in booking_list %}
<tr>
<td>
<a href="{% url 'nowait:booking_detail' booking.pk %}"
title="{% trans "View details of booking with id" %}&nbsp;{{ booking.pk }}">
{{ booking.pk }}
</a>
</td>
<td>{{ booking.slottime.booking_type.title }}</td>
<td>{{ booking.slottime.start|date:"l d F Y" }}</td>
<td>{{ booking.slottime.start|date:"H:i" }}</td>
<td>{{ booking.slottime.end|date:"H:i" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="alert alert-info text-center">
<h3>{% trans "You have not made ​​any booking" %}</h3>
Expand Down
5 changes: 0 additions & 5 deletions nowait/templates/nowait/bookingtype_detail.html
@@ -1,11 +1,6 @@
{% extends 'pages/page.html' %}
{% load i18n mezzanine_tags %}

{% block breadcrumb_menu %}
{{ block.super }}
<li class="active">{{ object.title|capfirst }}</li>
{% endblock %}

{% block title %}
<div id="bookingtype_title" class="jumbotron">
<h1>{{ object.title }}</h1>
Expand Down
12 changes: 11 additions & 1 deletion nowait/tests/factories.py
Expand Up @@ -2,7 +2,8 @@

import factory
from django.contrib.auth.models import User, Permission, Group
from mezzanine.pages.models import RichTextPage
from django.core.urlresolvers import reverse
from mezzanine.pages.models import RichTextPage, Link
from .. import models
from ..defaults import (NOWAIT_ROOT_SLUG, NOWAIT_GROUP_ADMINS,
NOWAIT_GROUP_OPERATORS)
Expand Down Expand Up @@ -101,6 +102,15 @@ class RootNowaitPageF(RichTextPageF):
slug = NOWAIT_ROOT_SLUG


class MyBookingLinkF(factory.DjangoModelFactory):
FACTORY_FOR = Link

title = 'My Bookings'
slug = reverse('nowait:booking_list').lstrip('/').rstrip('/')
parent = factory.SubFactory(RootNowaitPageF)
login_required = True


class BookingTypeF(factory.DjangoModelFactory):
FACTORY_FOR = models.BookingType
FACTORY_DJANGO_GET_OR_CREATE = ('title', 'calendar',)
Expand Down
12 changes: 10 additions & 2 deletions nowait/views.py
Expand Up @@ -123,7 +123,7 @@ class BookingListView(PageContextTitleMixin, LoginRequiredMixin, ListView):

def get_queryset(self):
return Booking.objects.filter(
booker=self.request.user.pk).order_by('-pk')
booker=self.request.user.pk).order_by('created')

def get_context_data(self, **kwargs):
context = super(BookingListView, self).get_context_data(**kwargs)
Expand All @@ -135,10 +135,18 @@ class BookingDetailView(PageContextTitleMixin, LoginRequiredMixin,
DetailView):
model = Booking

def get_breadcrumb_menu(self):
data = ['']
return data

def get_context_data(self, **kwargs):
context = super(BookingDetailView, self).get_context_data(**kwargs)

return context

def get_page_title(self):
return _('Details of booking %(pk)s') % {'pk': self.object.pk}

def get_queryset(self):
print(self.request.user)
return super(BookingDetailView, self).get_queryset().filter(
booker=self.request.user)
2 changes: 1 addition & 1 deletion project_template/settings.py
Expand Up @@ -399,7 +399,7 @@
except ImportError:
pass

CRISPY_TEMPLATE_PACK = 'bootstrap'
CRISPY_TEMPLATE_PACK = 'bootstrap3'
# for functional tests
INSTALLED_APPS = list(INSTALLED_APPS) + [
PACKAGE_NAME_GRAPPELLI, PACKAGE_NAME_FILEBROWSER,
Expand Down

0 comments on commit 04d043a

Please sign in to comment.