mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Merge branch 'counter' into 'master'
Tests for counter See merge request !77
This commit is contained in:
commit
10ee5e1708
@ -333,7 +333,7 @@ Welcome to the wiki page!
|
|||||||
|
|
||||||
# Counters
|
# Counters
|
||||||
Customer(user=skia, account_id="6568j", amount=0).save()
|
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 = ProductType(name="Bières bouteilles")
|
||||||
p.save()
|
p.save()
|
||||||
c = ProductType(name="Cotisations")
|
c = ProductType(name="Cotisations")
|
||||||
@ -362,6 +362,7 @@ Welcome to the wiki page!
|
|||||||
mde = Counter.objects.filter(name="MDE").first()
|
mde = Counter.objects.filter(name="MDE").first()
|
||||||
mde.products.add(barb)
|
mde.products.add(barb)
|
||||||
mde.products.add(cble)
|
mde.products.add(cble)
|
||||||
|
mde.sellers.add(skia)
|
||||||
mde.save()
|
mde.save()
|
||||||
|
|
||||||
eboutic = Counter.objects.filter(name="Eboutic").first()
|
eboutic = Counter.objects.filter(name="Eboutic").first()
|
||||||
@ -472,6 +473,11 @@ Welcome to the wiki page!
|
|||||||
start=s.subscription_start)
|
start=s.subscription_start)
|
||||||
s.save()
|
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
|
# Create an election
|
||||||
public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID)
|
public_group = Group.objects.get(id=settings.SITH_GROUP_PUBLIC_ID)
|
||||||
subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP)
|
subscriber_group = Group.objects.get(name=settings.SITH_MAIN_MEMBERS_GROUP)
|
||||||
|
110
counter/tests.py
110
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</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",
|
||||||
|
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('<p>Richard Batsbak</p>' 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('<p>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(
|
||||||
|
'<p>Entrez un code client : </p>' 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(
|
||||||
|
'<li><a href="/user/10/">Kro Phil'</a></li>' 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('<p>Merci de vous identifier</p>' 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(
|
||||||
|
'<li><a href="/user/1/">S' Kia</a></li>' in str(response_get.content))
|
||||||
|
Loading…
Reference in New Issue
Block a user