diff --git a/counter/tests.py b/counter/tests.py index c1a3a198..7337a8d0 100644 --- a/counter/tests.py +++ b/counter/tests.py @@ -22,10 +22,9 @@ # # -<<<<<<< 52a643878a10b52d9d7a17cd6c2854112c0a65d0 import re -from pprint import pprint +from pprint import pprint from django.test import TestCase from django.core.urlresolvers import reverse from django.core.management import call_command @@ -41,39 +40,46 @@ class CounterTest(TestCase): self.mde = Counter.objects.filter(name="MDE").first() 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, "password": "plop" }) - response = self.client.get(reverse("counter:details", kwargs={"counter_id":self.mde.id})) - # TODO check that barman is logged: - # 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) + response = self.client.get( + reverse("counter:details", kwargs={"counter_id": self.mde.id})) + + self.assertTrue( + 'class="link-button">S' Kia' 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", - kwargs={"counter_id":self.mde.id}), { - "code": "4000k", - "counter_token": counter_token, - }) + kwargs={"counter_id": self.mde.id}), { + "code": "4000k", + "counter_token": counter_token, + }) 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('

Richard Batsbak

' in str(response.content)) + response = self.client.post(location, { 'action': 'refill', 'amount': '10', 'payment_method': 'CASH', 'bank': 'OTHER', - }) + }) response = self.client.post(location, { 'action': 'code', 'code': 'BARB', - }) + }) response = self.client.post(location, { 'action': 'code', '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('

Client : Richard Batsbak - Nouveau montant : 8.30' in str(response_get.content)) class BarmanConnectionTest(TestCase): @@ -85,38 +91,43 @@ class BarmanConnectionTest(TestCase): self.krophil.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): - response_post = self.client.post(reverse('counter:login', args=[self.counter.id]), - {'username': "krophil", - 'password' : "plop"}) + self.client.post(reverse('counter:login', args=[self.counter.id]), + {'username': "krophil", + 'password': "plop"}) response_get = self.client.get(reverse("counter:details", - args=[self.counter.id])) + args=[self.counter.id])) - self.assertTrue('

Enter client code:

' in str(response_get.content)) + self.assertTrue( + '

Entrez un code client :

' in str(response_get.content)) def test_counters_list_barmen(self): - response_post = self.client.post(reverse('counter:login', args=[self.counter.id]), - {'username': "krophil", - 'password' : "plop"}) + 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.assertTrue('
  • Kro Phil'
  • ' in str(response_get.content)) - + args=[self.counter.id])) + + self.assertTrue( + '
  • Kro Phil'
  • ' in str(response_get.content)) + def test_barman_denied(self): - response_post = 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('

    Please, login

    ' in str(response_get.content)) + 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('

    Merci de vous identifier

    ' in str(response_get.content)) def test_counters_list_no_barmen(self): - response_post = 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('
  • S' Kia
  • ' in str(response_get.content)) \ No newline at end of file + 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( + '
  • S' Kia
  • ' in str(response_get.content))