From 63acf588caab07e6978d388d56008355c95afd42 Mon Sep 17 00:00:00 2001 From: Skia Date: Sat, 20 May 2017 14:27:13 +0200 Subject: [PATCH 1/3] Add basic unfinished counter test --- core/management/commands/populate.py | 3 +- counter/tests.py | 53 ++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index 68f80458..b0962ff3 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() diff --git a/counter/tests.py b/counter/tests.py index b8fbbe1e..7a1ce787 100644 --- a/counter/tests.py +++ b/counter/tests.py @@ -22,6 +22,55 @@ # # -from django.test import TestCase +import re +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})) + # 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.post(reverse("counter:details", + 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.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__) -# Create your tests here. From 0af72500c6903d6afe71885292de1c26867b505a Mon Sep 17 00:00:00 2001 From: Krophil Date: Sun, 14 May 2017 12:54:26 +0200 Subject: [PATCH 2/3] Add some tests on counter --- core/management/commands/populate.py | 5 +++ counter/tests.py | 46 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/core/management/commands/populate.py b/core/management/commands/populate.py index b0962ff3..e03b04b9 100644 --- a/core/management/commands/populate.py +++ b/core/management/commands/populate.py @@ -473,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 7a1ce787..c1a3a198 100644 --- a/counter/tests.py +++ b/counter/tests.py @@ -22,6 +22,7 @@ # # +<<<<<<< 52a643878a10b52d9d7a17cd6c2854112c0a65d0 import re from pprint import pprint @@ -74,3 +75,48 @@ class CounterTest(TestCase): # TODO finir le test en vérifiant que les produits ont bien été clickés # hint: pprint(response.__dict__) + +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): + response_post = 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('

Enter client code:

' 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"}) + 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): + 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)) + + 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 From eb510e102c3fbac415f2e9a6a0fae7eb9c69d3ca Mon Sep 17 00:00:00 2001 From: Krophil Date: Fri, 2 Jun 2017 17:27:56 +0200 Subject: [PATCH 3/3] Test for click --- counter/tests.py | 97 +++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 43 deletions(-) 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))