diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 68f80458..e03b04b9 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -333,7 +333,7 @@ Welcome to the wiki page! # Counters Customer(user=skia, account_id="6568j", amount=0).save() - Customer(user=r, account_id="4000", amount=0).save() + Customer(user=r, account_id="4000k", amount=0).save() p = ProductType(name="Bières bouteilles") p.save() c = ProductType(name="Cotisations") @@ -362,6 +362,7 @@ Welcome to the wiki page! mde = Counter.objects.filter(name="MDE").first() mde.products.add(barb) mde.products.add(cble) + mde.sellers.add(skia) mde.save() eboutic = Counter.objects.filter(name="Eboutic").first() @@ -472,6 +473,11 @@ Welcome to the wiki page! start=s.subscription_start) s.save() + # Add barman to counter + c = Counter.objects.get(id=2) + c.sellers.add(User.objects.get(pk=krophil.pk)) + c.save() + # Create an election public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID) subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP) diff --git a/counter/tests.py b/counter/tests.py index b8fbbe1e..7337a8d0 100644 --- a/counter/tests.py +++ b/counter/tests.py @@ -22,6 +22,112 @@ # # -from django.test import TestCase +import re -# Create your tests here. +from pprint import pprint +from django.test import TestCase +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): + 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})) + + 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, + }) + location = 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', + }) + + 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): + 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() + + self.counter = Counter.objects.filter(id=2).first() + + def test_barman_granted(self): + 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])) + + self.assertTrue( + '

Entrez un code client :

' in str(response_get.content)) + + def test_counters_list_barmen(self): + 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)) + + def test_barman_denied(self): + 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): + 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))