13 changed files with 143 additions and 614 deletions
-
30abonapp/locale/ru/LC_MESSAGES/django.po
-
241abonapp/models.py
-
2abonapp/templates/abonapp/buy_tariff.html
-
26abonapp/templates/abonapp/peoples.html
-
54abonapp/templates/abonapp/service.html
-
101abonapp/templates/abonapp/services.html
-
225abonapp/tests.py
-
2abonapp/urls_abon.py
-
67abonapp/views.py
-
3bugs.txt
-
2clientsideapp/views.py
-
2cron.py
-
2djing/utils/save_from_nodeny.py
@ -0,0 +1,54 @@ |
|||||
|
{% extends request.is_ajax|yesno:'nullcont.htm,abonapp/ext.htm' %} |
||||
|
{% load i18n %} |
||||
|
{% block content %} |
||||
|
|
||||
|
<div class="row"> |
||||
|
<div class="col-sm-6"> |
||||
|
|
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"> |
||||
|
<h3 class="panel-title">{% trans 'Services of subscriber' %}</h3> |
||||
|
</div> |
||||
|
<div class="panel-body"> |
||||
|
{% if abon_tariff %} |
||||
|
<p> |
||||
|
<b>{% trans 'Service' %}</b>: |
||||
|
{% if perms.tariff_app.change_tariff %} |
||||
|
<a href="{% url 'tarifs:edit' abon_tariff.pk %}" title="{{ abon_tariff.time_start|default:'' }}"> |
||||
|
{{ abon_tariff.tariff.title }} |
||||
|
</a> |
||||
|
{% else %} |
||||
|
{{ abon_tariff.tariff.title }} |
||||
|
{% endif %} |
||||
|
</p> |
||||
|
<i><b>{% trans 'Sum' %}</b>: {{ abon_tariff.tarif.amount }} руб.</i> |
||||
|
<p><b>{% trans 'Input speed' %}</b>: {{ abon_tariff.tariff.speedIn }}</p> |
||||
|
<p><b>{% trans 'Output speed' %}</b>: {{ abon_tariff.tariff.speedOut }}</p> |
||||
|
<p><b>{% trans 'Works until' %}</b>: {{ abon_tariff.deadline|date:"d E Y, l" }}</p> |
||||
|
<p>{{ abon_tariff.tarif.descr }}</p> |
||||
|
{% else %} |
||||
|
No service, <a href="{% url 'abonapp:pick_tariff' abon_group.pk abon.pk %}" class="btn btn-sm btn-success"> |
||||
|
<span class="glyphicon glyphicon-plus"></span> {% trans 'Buy service' %} |
||||
|
</a> |
||||
|
{% endif %} |
||||
|
|
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div class="col-sm-6"> |
||||
|
<div class="panel panel-default"> |
||||
|
<div class="panel-heading"> |
||||
|
<h3 class="panel-title">Услуги для заказа</h3> |
||||
|
</div> |
||||
|
<div class="panel-body"> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
{% endblock %} |
||||
@ -1,101 +0,0 @@ |
|||||
{% extends request.is_ajax|yesno:'nullcont.htm,abonapp/ext.htm' %} |
|
||||
{% load i18n %} |
|
||||
{% block content %} |
|
||||
|
|
||||
<legend>{% trans 'Services of subscriber' %}</legend> |
|
||||
<table class="table table-striped table-bordered"> |
|
||||
<thead> |
|
||||
<tr> |
|
||||
<th width="50">{% trans 'Priority' %}</th> |
|
||||
<th>{% trans 'Service' %}</th> |
|
||||
<th>{% trans 'Sum' %}</th> |
|
||||
<th>{% trans 'Input speed' %}</th> |
|
||||
<th>{% trans 'Output speed' %}</th> |
|
||||
<th>{% trans 'Works until' %}</th> |
|
||||
<th>{% trans 'Do' %}</th> |
|
||||
</tr> |
|
||||
</thead> |
|
||||
|
|
||||
<tbody> |
|
||||
{% for trf in abon_tarifs %} |
|
||||
<tr{% if trf.id == active_abontariff_id %} class="active"{% endif %}> |
|
||||
<td>{{ trf.tariff_priority }}</td> |
|
||||
<td> |
|
||||
|
|
||||
{% if perms.tariff_app.change_tariff %} |
|
||||
<a href="{% url 'tarifs:edit' trf.tariff.id %}" title="{{ trf.time_start|default:'' }}"> |
|
||||
{{ trf.tariff.title }} |
|
||||
</a> |
|
||||
{% else %} |
|
||||
{{ trf.tariff.title }} |
|
||||
{% endif %} |
|
||||
|
|
||||
</td> |
|
||||
<td>{{ trf.tariff.amount }}</td> |
|
||||
<td>{{ trf.tariff.speedIn }}</td> |
|
||||
<td>{{ trf.tariff.speedOut }}</td> |
|
||||
<td>{{ trf.deadline|date:"d E Y, l" }}</td> |
|
||||
{% if trf.id != active_abontariff_id %} |
|
||||
<td class="btn-group"> |
|
||||
|
|
||||
{% if perms.abonapp.can_activate_service %} |
|
||||
{% if not active_abontariff_id %} |
|
||||
<a href="{% url 'abonapp:activate_service' abon_group.id abon.id trf.id %}" |
|
||||
class="btn btn-success btn-sm" title="{% trans 'Activate service' %}"> |
|
||||
<i class="glyphicon glyphicon-shopping-cart"></i> |
|
||||
</a> |
|
||||
{% endif %} |
|
||||
{% endif %} |
|
||||
|
|
||||
<!-- "{ % url 'abonapp:chpriority_tariff' abon_group.id abon.id % }?t={ { trf.id } }&a=up" --> |
|
||||
<a href="#" |
|
||||
class="btn btn-default btn-sm disabled" title="{% trans 'Priority up' %}"> |
|
||||
<i class="glyphicon glyphicon-hand-up"></i> |
|
||||
</a> |
|
||||
|
|
||||
<!-- "{ % url 'abonapp:chpriority_tariff' abon_group.id abon.id % }?t={ { trf.id } }&a=down" --> |
|
||||
<a href="#" |
|
||||
class="btn btn-default btn-sm disabled" title="{% trans 'Priority down' %}"> |
|
||||
<i class="glyphicon glyphicon-hand-down"></i> |
|
||||
</a> |
|
||||
|
|
||||
{% if perms.abonapp.delete_abontariff %} |
|
||||
<a href="{% url 'abonapp:unsubscribe_service' abon_group.id abon.id trf.id %}" |
|
||||
class="btn btn-danger btn-sm" title="{% trans 'Delete service' %}"> |
|
||||
<i class="glyphicon glyphicon-remove"></i> |
|
||||
</a> |
|
||||
{% endif %} |
|
||||
</td> |
|
||||
{% else %} |
|
||||
<td> |
|
||||
<a href="{% url 'abonapp:compl_srv' abon_group.id abon.id trf.id %}" class="btn btn-danger btn-sm"> |
|
||||
<i class="glyphicon glyphicon-remove"></i> {% trans 'Finish service' %} |
|
||||
</a> |
|
||||
</td> |
|
||||
{% endif %} |
|
||||
</tr> |
|
||||
{% empty %} |
|
||||
<tr> |
|
||||
<td colspan="7">{% trans 'Services of subscribers not found' %}. |
|
||||
{% if perms.abonapp.can_buy_tariff %} |
|
||||
<a href="{% url 'abonapp:pick_tariff' abon_group.id abon.id %}" class="lgtbx">{% trans 'Buy' %}</a> |
|
||||
{% endif %} |
|
||||
</td> |
|
||||
</tr> |
|
||||
{% endfor %} |
|
||||
</tbody> |
|
||||
{% if perms.abonapp.can_buy_tariff %} |
|
||||
<tfoot> |
|
||||
<tr> |
|
||||
<th colspan="7"> |
|
||||
<a href="{% url 'abonapp:pick_tariff' abon_group.id abon.id %}" class="btn btn-sm btn-success"> |
|
||||
<span class="glyphicon glyphicon-plus"></span> {% trans 'Buy service' %} |
|
||||
</a> |
|
||||
</th> |
|
||||
</tr> |
|
||||
</tfoot> |
|
||||
{% endif %} |
|
||||
</table> |
|
||||
|
|
||||
|
|
||||
{% endblock %} |
|
||||
@ -1,225 +0,0 @@ |
|||||
from django.shortcuts import resolve_url |
|
||||
from django.test import TestCase |
|
||||
from django.test.client import Client |
|
||||
from agent import NasNetworkError |
|
||||
from .models import AbonTariff, Abon, AbonGroup, AbonRawPassword |
|
||||
from tariff_app.models import Tariff |
|
||||
from mydefs import LogicError |
|
||||
|
|
||||
|
|
||||
class AbonTestCase(TestCase): |
|
||||
def setUp(self): |
|
||||
try: |
|
||||
Tariff.objects.create( |
|
||||
title='test_tariff', |
|
||||
descr='taroff descr', |
|
||||
speedIn=1.2, |
|
||||
speedOut=3.0, |
|
||||
amount=3 |
|
||||
) |
|
||||
abon = Abon() |
|
||||
abon.username = '1234567' |
|
||||
abon.fio = 'mainuser' |
|
||||
abon.telephone = '+79788328884' |
|
||||
abon.set_password('ps') |
|
||||
abon.is_superuser = True |
|
||||
abon.save() |
|
||||
abon_group = AbonGroup.objects.create(title='abon_group') |
|
||||
abon_group.profiles.add(abon) |
|
||||
except NasNetworkError: |
|
||||
pass |
|
||||
|
|
||||
# проверка на пополнение счёта |
|
||||
def test_add_ballance(self): |
|
||||
try: |
|
||||
abon = Abon.objects.get(username='1234567') |
|
||||
ballance = abon.ballance |
|
||||
abon.add_ballance(abon, 13, 'test pay') |
|
||||
abon.save(update_fields=['ballance']) |
|
||||
self.assertEqual(abon.ballance, ballance+13) |
|
||||
ballance = abon.ballance |
|
||||
abon.add_ballance(abon, 5.34, 'test float pay') |
|
||||
abon.save(update_fields=['ballance']) |
|
||||
self.assertEqual(abon.ballance, ballance+5.34) |
|
||||
except NasNetworkError: |
|
||||
pass |
|
||||
|
|
||||
# пробуем выбрать услугу |
|
||||
def test_pick_tariff(self): |
|
||||
try: |
|
||||
tariff = Tariff.objects.get(title='test_tariff') |
|
||||
abon = Abon.objects.get(username='1234567') |
|
||||
try: |
|
||||
abon.pick_tariff(tariff, abon) |
|
||||
# нет денег, должно всплыть исключение и сюда дойти мы не должны |
|
||||
self.assertFalse(True) |
|
||||
except LogicError: |
|
||||
pass |
|
||||
act_tar = abon.active_tariff() |
|
||||
# если недостаточно денег на счету |
|
||||
assert abon.ballance <= tariff.amount |
|
||||
# У абонента на счету 0, не должна быть куплена услуга |
|
||||
self.assertEqual(act_tar, None) |
|
||||
# Раз услуги нет то и доступа быть не должно |
|
||||
self.assertTrue(not abon.is_access()) |
|
||||
|
|
||||
# с деньгами |
|
||||
abon.add_ballance(abon, 7.34, 'add pay for test pick tariff') |
|
||||
abon.pick_tariff(tariff, abon) |
|
||||
act_tar = abon.active_tariff() |
|
||||
# должны получить указанную услугу |
|
||||
self.assertEqual(act_tar, tariff) |
|
||||
# и получить доступ |
|
||||
self.assertTrue(abon.is_access()) |
|
||||
except NasNetworkError: |
|
||||
pass |
|
||||
|
|
||||
# тестим очередь услуг |
|
||||
def test_services_queue(self): |
|
||||
abon = Abon.objects.get(username='1234567') |
|
||||
tariff = Tariff.objects.get(title='test_tariff') |
|
||||
abon.add_ballance(abon, 9, 'add pay for test services queue') |
|
||||
abon.save() |
|
||||
abon.pick_tariff(tariff, abon) |
|
||||
abon.pick_tariff(tariff, abon) |
|
||||
abon.pick_tariff(tariff, abon) |
|
||||
# снять деньги должно было только за первый выбор, остальные стают в очередь услуг |
|
||||
self.assertEqual(abon.ballance, 6) |
|
||||
|
|
||||
c = Client() |
|
||||
# login |
|
||||
c.post(resolve_url('acc_app:login'), {'login': '1234567', 'password': 'ps'}) |
|
||||
url = resolve_url('abonapp:compl_srv', gid=1, uid=1, srvid=1) |
|
||||
resp = c.get(url) |
|
||||
print('RESP:', resp) |
|
||||
self.assertEqual(resp.status_code, 200) |
|
||||
resp = c.post(url, data={ |
|
||||
'finish_confirm': 'yes' |
|
||||
}) |
|
||||
print('RESP:', resp) |
|
||||
# при успешной остановке услуги идёт редирект на др страницу |
|
||||
self.assertEqual(resp.status_code, 302) |
|
||||
# текущей услуги быть не должно |
|
||||
act_tar = abon.active_tariff() |
|
||||
self.assertIsNone(act_tar) |
|
||||
# не активных услуг останется 2 |
|
||||
noact_count = AbonTariff.objects.filter(abon=abon).filter(time_start=None).count() |
|
||||
self.assertEqual(noact_count, 2) |
|
||||
|
|
||||
# проверяем платёжку alltime |
|
||||
def test_allpay(self): |
|
||||
from hashlib import md5 |
|
||||
from djing.settings import pay_SECRET, pay_SERV_ID |
|
||||
import xmltodict |
|
||||
|
|
||||
def sig(act, pay_account, pay_id): |
|
||||
md = md5() |
|
||||
s = '_'.join((str(act), str(pay_account), pay_SERV_ID, str(pay_id), pay_SECRET)) |
|
||||
md.update(bytes(s, 'utf-8')) |
|
||||
return md.hexdigest() |
|
||||
|
|
||||
c = Client() |
|
||||
url = resolve_url('abonapp:terminal_pay') |
|
||||
r = c.get(url, { |
|
||||
'ACT': 1, 'PAY_ACCOUNT': '1234567', |
|
||||
'SERVICE_ID': pay_SERV_ID, |
|
||||
'PAY_ID': 3561234, |
|
||||
'TRADE_POINT': 377, |
|
||||
'SIGN': sig(1, 1234567, 3561234) |
|
||||
}) |
|
||||
xobj = xmltodict.parse(r.content) |
|
||||
self.assertEqual(int(xobj['pay-response']['status_code']), 21) |
|
||||
r = c.get(url, { |
|
||||
'ACT': 4, 'PAY_ACCOUNT': '1234567', |
|
||||
'SERVICE_ID': pay_SERV_ID, |
|
||||
'PAY_ID': 3561234, |
|
||||
'PAY_AMOUNT': 1.0, |
|
||||
'TRADE_POINT': 377, |
|
||||
'SIGN': sig(4, 1234567, 3561234) |
|
||||
}) |
|
||||
xobj = xmltodict.parse(r.content) |
|
||||
self.assertEqual(int(xobj['pay-response']['status_code']), 22) |
|
||||
r = c.get(url, { |
|
||||
'ACT': 4, 'PAY_ACCOUNT': '1234567', |
|
||||
'SERVICE_ID': pay_SERV_ID, |
|
||||
'PAY_ID': 3561234, |
|
||||
'PAY_AMOUNT': 1.0, |
|
||||
'TRADE_POINT': 377, |
|
||||
'SIGN': sig(4, 1234567, 3561234) |
|
||||
}) |
|
||||
xobj = xmltodict.parse(r.content) |
|
||||
self.assertEqual(int(xobj['pay-response']['status_code']), -100) |
|
||||
r = c.get(url, { |
|
||||
'ACT': 7, 'PAY_ACCOUNT': '1234567', |
|
||||
'SERVICE_ID': pay_SERV_ID, |
|
||||
'PAY_ID': 3561234, |
|
||||
'PAY_AMOUNT': 1.0, |
|
||||
'TRADE_POINT': 377, |
|
||||
'SIGN': sig(7, 1234567, 3561234) |
|
||||
}) |
|
||||
xobj = xmltodict.parse(r.content) |
|
||||
self.assertEqual(int(xobj['pay-response']['status_code']), 11) |
|
||||
abon = Abon.objects.get(username='1234567') |
|
||||
self.assertEqual(abon.ballance, 1) |
|
||||
|
|
||||
# пробуем добавить группу абонентов |
|
||||
def test_add_abongroup(self): |
|
||||
abon = Abon.objects.get(username='1234567') |
|
||||
ag = AbonGroup.objects.create(title='%&34%$&*(') |
|
||||
ag.profiles.add(abon) |
|
||||
|
|
||||
# пробуем добавить абонента |
|
||||
def test_add_abon(self): |
|
||||
c = Client() |
|
||||
c.login(username='1234567', password='ps') |
|
||||
url = resolve_url('abonapp:add_abon', gid=1) |
|
||||
r = c.get(url) |
|
||||
# поглядим на страницу добавления абонента |
|
||||
self.assertEqual(r.status_code, 200) |
|
||||
r = c.post(url, { |
|
||||
'username': '123', |
|
||||
'password': 'ps', |
|
||||
'fio': 'Abon Fio', |
|
||||
'telephone': '+79783753914', |
|
||||
'is_active': True |
|
||||
}) |
|
||||
self.assertEqual(r.status_code, 302) |
|
||||
r = c.get(resolve_url('abonapp:add_abon', gid=324)) |
|
||||
self.assertEqual(r.status_code, 404) |
|
||||
try: |
|
||||
abn = Abon.objects.get(username='123') |
|
||||
self.assertIsNotNone(abn) |
|
||||
psw = AbonRawPassword.objects.get(account=abn, passw_text='ps') |
|
||||
self.assertIsNotNone(psw) |
|
||||
except Abon.DoesNotExist: |
|
||||
# абонент должен был создаться |
|
||||
self.assertTrue(False) |
|
||||
except AbonRawPassword.DoesNotExist: |
|
||||
# должен быть пароль абонента простым текстом |
|
||||
self.assertTrue(False) |
|
||||
|
|
||||
# пробуем удалить абонента |
|
||||
def test_view_delentity(self): |
|
||||
c = Client() |
|
||||
c.login(username='1234567', password='ps') |
|
||||
url = resolve_url('abonapp:del_abon') + '?t=a&id=1' |
|
||||
r = c.get('/abons/1/addabon') |
|
||||
|
|
||||
|
|
||||
class AbonTariffTestCase(TestCase): |
|
||||
def setUp(self): |
|
||||
abon = Abon.objects.create( |
|
||||
username='1234567', |
|
||||
telephone='+79788328884' |
|
||||
) |
|
||||
tariff = Tariff.objects.create( |
|
||||
title='test_tariff', |
|
||||
descr='taroff descr', |
|
||||
speedIn=1.2, |
|
||||
speedOut=3.0, |
|
||||
amount=3 |
|
||||
) |
|
||||
AbonTariff.objects.create( |
|
||||
abon=abon, |
|
||||
tariff=tariff |
|
||||
) |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue