Test for click

This commit is contained in:
Pierre Brunet 2017-06-02 17:27:56 +02:00
parent 0af72500c6
commit eb510e102c

View File

@ -22,10 +22,9 @@
# #
# #
<<<<<<< 52a643878a10b52d9d7a17cd6c2854112c0a65d0
import re import re
from pprint import pprint
from pprint import pprint
from django.test import TestCase from django.test import TestCase
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.management import call_command from django.core.management import call_command
@ -41,39 +40,46 @@ class CounterTest(TestCase):
self.mde = Counter.objects.filter(name="MDE").first() self.mde = Counter.objects.filter(name="MDE").first()
def test_full_click(self): def test_full_click(self):
response = self.client.post(reverse("counter:login", kwargs={"counter_id":self.mde.id}), { response = self.client.post(reverse("counter:login", kwargs={"counter_id": self.mde.id}), {
"username": self.skia.username, "username": self.skia.username,
"password": "plop" "password": "plop"
}) })
response = self.client.get(reverse("counter:details", kwargs={"counter_id":self.mde.id})) response = self.client.get(
# TODO check that barman is logged: reverse("counter:details", kwargs={"counter_id": self.mde.id}))
# self.assertTrue(mon barman est bien dans le HTML de response.content)
counter_token = re.search(r'name="counter_token" value="([^"]*)"', str(response.content)).group(1) self.assertTrue(
'class="link-button">S&#39; Kia</button>' in str(response.content))
counter_token = re.search(
r'name="counter_token" value="([^"]*)"', str(response.content)).group(1)
response = self.client.post(reverse("counter:details", response = self.client.post(reverse("counter:details",
kwargs={"counter_id":self.mde.id}), { kwargs={"counter_id": self.mde.id}), {
"code": "4000k", "code": "4000k",
"counter_token": counter_token, "counter_token": counter_token,
}) })
location = response.get('location') location = response.get('location')
# TODO check qu'on a bien eu la bonne page, avec le bon client, etc...
# response = self.client.get(response.get('location')) response = self.client.get(response.get('location'))
self.assertTrue('<p>Richard Batsbak</p>' in str(response.content))
response = self.client.post(location, { response = self.client.post(location, {
'action': 'refill', 'action': 'refill',
'amount': '10', 'amount': '10',
'payment_method': 'CASH', 'payment_method': 'CASH',
'bank': 'OTHER', 'bank': 'OTHER',
}) })
response = self.client.post(location, { response = self.client.post(location, {
'action': 'code', 'action': 'code',
'code': 'BARB', 'code': 'BARB',
}) })
response = self.client.post(location, { response = self.client.post(location, {
'action': 'code', 'action': 'code',
'code': 'fin', 'code': 'fin',
}) })
# TODO finir le test en vérifiant que les produits ont bien été clickés
# hint: pprint(response.__dict__) response_get = self.client.get(response.get('location'))
self.assertTrue('<p>Client : Richard Batsbak - Nouveau montant : 8.30' in str(response_get.content))
class BarmanConnectionTest(TestCase): class BarmanConnectionTest(TestCase):
@ -85,38 +91,43 @@ class BarmanConnectionTest(TestCase):
self.krophil.customer.save() self.krophil.customer.save()
self.skia.customer.save() self.skia.customer.save()
self.counter = Counter.objects.filter(id = 2).first() self.counter = Counter.objects.filter(id=2).first()
def test_barman_granted(self): def test_barman_granted(self):
response_post = self.client.post(reverse('counter:login', args=[self.counter.id]), self.client.post(reverse('counter:login', args=[self.counter.id]),
{'username': "krophil", {'username': "krophil",
'password' : "plop"}) 'password': "plop"})
response_get = self.client.get(reverse("counter:details", response_get = self.client.get(reverse("counter:details",
args=[self.counter.id])) args=[self.counter.id]))
self.assertTrue('<p>Enter client code:</p>' in str(response_get.content)) self.assertTrue(
'<p>Entrez un code client : </p>' in str(response_get.content))
def test_counters_list_barmen(self): def test_counters_list_barmen(self):
response_post = self.client.post(reverse('counter:login', args=[self.counter.id]), self.client.post(reverse('counter:login', args=[self.counter.id]),
{'username': "krophil", {'username': "krophil",
'password' : "plop"}) 'password': "plop"})
response_get = self.client.get(reverse("counter:activity", response_get = self.client.get(reverse("counter:activity",
args=[self.counter.id])) args=[self.counter.id]))
self.assertTrue('<li><a href="/user/10/">Kro Phil&#39;</a></li>' in str(response_get.content)) self.assertTrue(
'<li><a href="/user/10/">Kro Phil&#39;</a></li>' in str(response_get.content))
def test_barman_denied(self): def test_barman_denied(self):
response_post = self.client.post(reverse('counter:login', args=[self.counter.id]), self.client.post(reverse('counter:login', args=[self.counter.id]),
{'username': "skia", {'username': "skia",
'password' : "plop"}) 'password': "plop"})
response_get = self.client.get(reverse("counter:details", args=[self.counter.id])) response_get = self.client.get(
reverse("counter:details", args=[self.counter.id]))
self.assertTrue('<p>Please, login</p>' in str(response_get.content)) self.assertTrue('<p>Merci de vous identifier</p>' in str(response_get.content))
def test_counters_list_no_barmen(self): def test_counters_list_no_barmen(self):
response_post = self.client.post(reverse('counter:login', args=[self.counter.id]), self.client.post(reverse('counter:login', args=[self.counter.id]),
{'username': "krophil", {'username': "krophil",
'password' : "plop"}) 'password': "plop"})
response_get = self.client.get(reverse("counter:activity", args=[self.counter.id])) response_get = self.client.get(
reverse("counter:activity", args=[self.counter.id]))
self.assertFalse('<li><a href="/user/1/">S&#39; Kia</a></li>' in str(response_get.content)) self.assertFalse(
'<li><a href="/user/1/">S&#39; Kia</a></li>' in str(response_get.content))