2017-04-24 15:51:12 +00:00
|
|
|
# -*- coding:utf-8 -*
|
|
|
|
#
|
|
|
|
# Copyright 2016,2017
|
|
|
|
# - Skia <skia@libskia.so>
|
|
|
|
#
|
|
|
|
# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM,
|
|
|
|
# http://ae.utbm.fr.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU General Public License a published by the Free Software
|
|
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple
|
|
|
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
2017-05-20 12:27:13 +00:00
|
|
|
import re
|
|
|
|
|
2016-03-28 12:54:35 +00:00
|
|
|
from django.test import TestCase
|
2017-05-20 12:27:13 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.core.management import call_command
|
|
|
|
|
|
|
|
from core.models import User
|
|
|
|
from counter.models import Counter
|
|
|
|
|
|
|
|
|
|
|
|
class CounterTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command("populate")
|
|
|
|
self.skia = User.objects.filter(username="skia").first()
|
|
|
|
self.mde = Counter.objects.filter(name="MDE").first()
|
|
|
|
|
|
|
|
def test_full_click(self):
|
2017-06-02 15:27:56 +00:00
|
|
|
response = self.client.post(reverse("counter:login", kwargs={"counter_id": self.mde.id}), {
|
2017-05-20 12:27:13 +00:00
|
|
|
"username": self.skia.username,
|
|
|
|
"password": "plop"
|
|
|
|
})
|
2017-06-02 15:27:56 +00:00
|
|
|
response = self.client.get(
|
|
|
|
reverse("counter:details", kwargs={"counter_id": self.mde.id}))
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
'class="link-button">S' Kia</button>' in str(response.content))
|
|
|
|
|
|
|
|
counter_token = re.search(
|
|
|
|
r'name="counter_token" value="([^"]*)"', str(response.content)).group(1)
|
2017-05-20 12:27:13 +00:00
|
|
|
|
|
|
|
response = self.client.post(reverse("counter:details",
|
2017-06-02 15:27:56 +00:00
|
|
|
kwargs={"counter_id": self.mde.id}), {
|
|
|
|
"code": "4000k",
|
|
|
|
"counter_token": counter_token,
|
|
|
|
})
|
2017-05-20 12:27:13 +00:00
|
|
|
location = response.get('location')
|
2017-06-02 15:27:56 +00:00
|
|
|
|
|
|
|
response = self.client.get(response.get('location'))
|
2018-06-07 17:57:56 +00:00
|
|
|
self.assertTrue('>Richard Batsbak</' in str(response.content))
|
2017-06-02 15:27:56 +00:00
|
|
|
|
2017-05-20 12:27:13 +00:00
|
|
|
response = self.client.post(location, {
|
|
|
|
'action': 'refill',
|
|
|
|
'amount': '10',
|
|
|
|
'payment_method': 'CASH',
|
|
|
|
'bank': 'OTHER',
|
2017-06-02 15:27:56 +00:00
|
|
|
})
|
2017-05-20 12:27:13 +00:00
|
|
|
response = self.client.post(location, {
|
|
|
|
'action': 'code',
|
|
|
|
'code': 'BARB',
|
2017-06-02 15:27:56 +00:00
|
|
|
})
|
2017-05-20 12:27:13 +00:00
|
|
|
response = self.client.post(location, {
|
|
|
|
'action': 'code',
|
|
|
|
'code': 'fin',
|
2017-06-02 15:27:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
response_get = self.client.get(response.get('location'))
|
|
|
|
self.assertTrue('<p>Client : Richard Batsbak - Nouveau montant : 8.30' in str(response_get.content))
|
2016-03-28 12:54:35 +00:00
|
|
|
|
2017-05-14 10:54:26 +00:00
|
|
|
|
|
|
|
class BarmanConnectionTest(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
call_command("populate")
|
|
|
|
self.krophil = User.objects.get(username="krophil")
|
|
|
|
self.skia = User.objects.get(username="skia")
|
|
|
|
self.skia.customer.account = 800
|
|
|
|
self.krophil.customer.save()
|
|
|
|
self.skia.customer.save()
|
|
|
|
|
2017-06-02 15:27:56 +00:00
|
|
|
self.counter = Counter.objects.filter(id=2).first()
|
2017-05-14 10:54:26 +00:00
|
|
|
|
|
|
|
def test_barman_granted(self):
|
2017-06-02 15:27:56 +00:00
|
|
|
self.client.post(reverse('counter:login', args=[self.counter.id]),
|
|
|
|
{'username': "krophil",
|
|
|
|
'password': "plop"})
|
2017-05-14 10:54:26 +00:00
|
|
|
response_get = self.client.get(reverse("counter:details",
|
2017-06-02 15:27:56 +00:00
|
|
|
args=[self.counter.id]))
|
2017-05-14 10:54:26 +00:00
|
|
|
|
2017-06-02 15:27:56 +00:00
|
|
|
self.assertTrue(
|
|
|
|
'<p>Entrez un code client : </p>' in str(response_get.content))
|
2017-05-14 10:54:26 +00:00
|
|
|
|
|
|
|
def test_counters_list_barmen(self):
|
2017-06-02 15:27:56 +00:00
|
|
|
self.client.post(reverse('counter:login', args=[self.counter.id]),
|
|
|
|
{'username': "krophil",
|
|
|
|
'password': "plop"})
|
2017-05-14 10:54:26 +00:00
|
|
|
response_get = self.client.get(reverse("counter:activity",
|
2017-06-02 15:27:56 +00:00
|
|
|
args=[self.counter.id]))
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
'<li><a href="/user/10/">Kro Phil'</a></li>' in str(response_get.content))
|
|
|
|
|
2017-05-14 10:54:26 +00:00
|
|
|
def test_barman_denied(self):
|
2017-06-02 15:27:56 +00:00
|
|
|
self.client.post(reverse('counter:login', args=[self.counter.id]),
|
|
|
|
{'username': "skia",
|
|
|
|
'password': "plop"})
|
|
|
|
response_get = self.client.get(
|
|
|
|
reverse("counter:details", args=[self.counter.id]))
|
|
|
|
|
|
|
|
self.assertTrue('<p>Merci de vous identifier</p>' in str(response_get.content))
|
2017-05-14 10:54:26 +00:00
|
|
|
|
|
|
|
def test_counters_list_no_barmen(self):
|
2017-06-02 15:27:56 +00:00
|
|
|
self.client.post(reverse('counter:login', args=[self.counter.id]),
|
|
|
|
{'username': "krophil",
|
|
|
|
'password': "plop"})
|
|
|
|
response_get = self.client.get(
|
|
|
|
reverse("counter:activity", args=[self.counter.id]))
|
|
|
|
|
|
|
|
self.assertFalse(
|
|
|
|
'<li><a href="/user/1/">S' Kia</a></li>' in str(response_get.content))
|