Skip to content

Commit

Permalink
Merge pull request #407 from jookies/v0.9
Browse files Browse the repository at this point in the history
0.9b2
  • Loading branch information
farirat committed Mar 19, 2016
2 parents e34d87a + a7c0b45 commit 2450634
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: python
python:
- '2.7'
env:
- ROOT_PATH=~/jasmin JASMIN_RELEASE=0.9b1
- ROOT_PATH=~/jasmin JASMIN_RELEASE=0.9b2
# Command to install dependencies
install:
- python setup.py sdist
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MAINTAINER Jookies LTD <jasmin@jookies.net>
# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r jasmin && useradd -r -g jasmin jasmin

ENV JASMIN_VERSION 0.9b1
ENV JASMIN_VERSION 0.9b2

# Install requirements
RUN apt-get update && apt-get install -y \
Expand Down
2 changes: 1 addition & 1 deletion jasmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

MAJOR = 0
MINOR = 9
PATCH = 1
PATCH = 2
META = 'b'

def get_version():
Expand Down
3 changes: 3 additions & 0 deletions jasmin/managers/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def delConnector(self, cid):
def perspective_version_release(self):
return jasmin.get_release()

def perspective_version(self):
return jasmin.get_version()

def perspective_persist(self, profile='jcli-prod'):
path = '%s/%s.smppccs' % (self.config.store_path, profile)
self.log.info('Persisting current configuration to [%s] profile in %s', profile, path)
Expand Down
8 changes: 4 additions & 4 deletions jasmin/managers/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ def submit_sm_resp_event(self, r, amqpMessage):
self.log.debug('There is a SMPPs mapping for msgid[%s] ...', msgid)

system_id = dlr['system_id']
source_addr = dlr['source_addr']
destination_addr = dlr['destination_addr']
source_addr = str(dlr['source_addr'])
destination_addr = str(dlr['destination_addr'])
sub_date = dlr['sub_date']
registered_delivery_receipt = dlr['rd_receipt']
smpps_map_expiry = dlr['expiry']
Expand Down Expand Up @@ -847,8 +847,8 @@ def deliver_sm_event_post_interception(self, *args, **kw):
elif submit_sm_queue_id is not None and connector_type == 'smppsapi':
if len(dlr) > 0:
system_id = dlr['system_id']
source_addr = dlr['source_addr']
destination_addr = dlr['destination_addr']
source_addr = str(dlr['source_addr'])
destination_addr = str(dlr['destination_addr'])
sub_date = dlr['sub_date']
registered_delivery_receipt = dlr['rd_receipt']

Expand Down
4 changes: 4 additions & 0 deletions jasmin/managers/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class SMPPClientManagerPBProxy(JasminPBProxy):
def version_release(self):
return self.pb.callRemote('version_release')

@ConnectedPB
def version(self):
return self.pb.callRemote('version')

@ConnectedPB
def persist(self, profile="jcli-prod"):
return self.pb.callRemote('persist', profile)
Expand Down
8 changes: 8 additions & 0 deletions jasmin/managers/test/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ def test_version_release(self):

self.assertEqual(version_release, jasmin.get_release())

@defer.inlineCallbacks
def test_version(self):
yield self.connect('127.0.0.1', self.pbPort)

version = yield self.version()

self.assertEqual(version, jasmin.get_version())

class ConfigurationPersistenceTestCases(SMPPClientPBProxyTestCase):
@defer.inlineCallbacks
def tearDown(self):
Expand Down
19 changes: 19 additions & 0 deletions jasmin/protocols/cli/test/test_userm.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,25 @@ def test_increase_decrease_quota_invalid_type(self):
self.update_user(r'jcli : ', 'user_1', extraCommands)
self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

def test_increase_unlimited_quota(self):
"Related to #403"
# Add user without initial quota
extraCommands = [{'command': 'uid user_1'}]
self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = 'AnyUsername')

_cred = MtMessagingCredential()
_cred.setQuota('submit_sm_count', 20)
_cred.setQuota('balance', 11.2)

# Assert User increasing/decreasing quota
extraCommands = [{'command': 'password anypassword'},
{'command': 'mt_messaging_cred quota sms_count +20'}]
self.update_user(r'jcli : ', 'user_1', extraCommands)
extraCommands = [{'command': 'password anypassword'},
{'command': 'mt_messaging_cred quota balance +11.2'}]
self.update_user(r'jcli : ', 'user_1', extraCommands)
self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

def test_all(self):
_cred = MtMessagingCredential()
_cred.setAuthorization('http_send', False)
Expand Down
19 changes: 9 additions & 10 deletions jasmin/protocols/http/test/twisted_web_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from twisted.web.test.test_web import DummyRequest

class SmartDummyRequest(DummyRequest):
def __init__(self, method, url, args=None, headers=None):
def __init__(self, method, url, args=None):
DummyRequest.__init__(self, url.split('/'))
self.method = method
self.headers.update(headers or {})

# set args
# set args
args = args or {}
for k, v in args.items():
self.addArg(k, v)
Expand All @@ -21,16 +20,16 @@ def value(self):


class DummySite(server.Site):
def get(self, url, args=None, headers=None):
return self._request("GET", url, args, headers)
def get(self, url, args=None):
return self._request("GET", url, args)


def post(self, url, args=None, headers=None):
return self._request("POST", url, args, headers)
def post(self, url, args=None):
return self._request("POST", url, args)


def _request(self, method, url, args, headers):
request = SmartDummyRequest(method, url, args, headers)
def _request(self, method, url, args):
request = SmartDummyRequest(method, url, args)
resource = self.getResourceFor(request)
result = resource.render(request)
return self._resolveResult(request, result)
Expand All @@ -47,4 +46,4 @@ def _resolveResult(self, request, result):
else:
return request.notifyFinish().addCallback(lambda _: request)
else:
raise ValueError("Unexpected return value: %r" % (result,))
raise ValueError("Unexpected return value: %r" % (result,))
2 changes: 1 addition & 1 deletion jasmin/queues/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ def connectionMade(self):
self.factory.log.info("Connection made to %s:%s" % (self.factory.config.host, self.factory.config.port))
AMQClient.connectionMade(self)

self.factory.connectDeferred.callback(self)
self.factory.connectDeferred.callback(self)
6 changes: 4 additions & 2 deletions jasmin/routing/jasminApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ def setQuota(self, key, value):
def updateQuota(self, key, difference):
if key not in self.quotas:
raise jasminApiCredentialError('%s is not a valid Quota key' % key)
if self.quotas[key] is None:
raise jasminApiCredentialError('Cannot update a None Quota value for key %s' % key)
if not isinstance(difference, float) and not isinstance(difference, int):
raise jasminApiCredentialError(
'Incorrect type for value (%s), must be int or float' % difference)
if isinstance(self.quotas[key], int) and isinstance(difference, float):
raise jasminApiCredentialError('Type mismatch, cannot update an int with a float value')

# If quota is unlimited then initialize it to zero before update
if self.quotas[key] is None:
self.quotas[key] = 0

self.quotas[key] += difference
self.quotas_updated = True

Expand Down
4 changes: 4 additions & 0 deletions jasmin/routing/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class RouterPBProxy(JasminPBProxy):
def version_release(self):
return self.pb.callRemote('version_release')

@ConnectedPB
def version(self):
return self.pb.callRemote('version')

@ConnectedPB
def persist(self, profile="jcli-prod", scope='all'):
return self.pb.callRemote('persist', profile, scope)
Expand Down
3 changes: 3 additions & 0 deletions jasmin/routing/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ def getMTRoute(self, order):
def perspective_version_release(self):
return jasmin.get_release()

def perspective_version(self):
return jasmin.get_version()

def perspective_persist(self, profile='jcli-prod', scope='all'):
try:
if scope in ['all', 'groups']:
Expand Down
8 changes: 8 additions & 0 deletions jasmin/routing/test/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ def test_version_release(self):

self.assertEqual(version_release, jasmin.get_release())

@defer.inlineCallbacks
def test_version(self):
yield self.connect('127.0.0.1', self.pbPort)

version = yield self.version()

self.assertEqual(version, jasmin.get_version())

class InterceptionTestCases(RouterPBProxy, RouterPBTestCase):
@defer.inlineCallbacks
def test_add_list_and_flush_mt_interceptor(self):
Expand Down
41 changes: 41 additions & 0 deletions jasmin/routing/test/test_routing_submit_sm_and_dlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,47 @@ def test_receipt_for_unknown_message(self):
last_pdu = self.smpps_factory.lastProto.sendPDU.call_args_list[1][0][0]
self.assertEqual(last_pdu.id, pdu_types.CommandId.unbind_resp)

@defer.inlineCallbacks
def test_receipt_for_long_destination_addr(self):
"""It's been reported that long destination_addr will lead to an error taking Jasmin down.
Related to #405
"""
yield self.connect('127.0.0.1', self.pbPort)
yield self.prepareRoutingsAndStartConnector()

# Bind
yield self.smppc_factory.connectAndBind()

# Install mocks
self.smpps_factory.lastProto.sendPDU = mock.Mock(wraps=self.smpps_factory.lastProto.sendPDU)

# Send a SMS MT through smpps interface
SubmitSmPDU = copy.deepcopy(self.SubmitSmPDU)
SubmitSmPDU.params['destination_addr'] = '905325932042'
SubmitSmPDU.params['registered_delivery'] = RegisteredDelivery(RegisteredDeliveryReceipt.SMSC_DELIVERY_RECEIPT_REQUESTED)
yield self.smppc_factory.lastProto.sendDataRequest(SubmitSmPDU)

# Wait 3 seconds for submit_sm_resp
yield waitFor(3)

# Trigger DLR
yield self.SMSCPort.factory.lastClient.trigger_DLR(stat = 'DELIVRD')

# Wait some time before testing
yield waitFor(0.5)

# Asserts
self.assertEqual(self.smpps_factory.lastProto.sendPDU.call_count, 2)

# Unbind & Disconnect
yield self.smppc_factory.smpp.unbindAndDisconnect()
yield self.stopSmppClientConnectors()

# Run tests
# smpps last response was a unbind_resp
last_pdu = self.smpps_factory.lastProto.sendPDU.call_args_list[2][0][0]
self.assertEqual(last_pdu.id, pdu_types.CommandId.unbind_resp)

class SmppsMessagingTestCases(RouterPBProxy, SMPPClientTestCases, SubmitSmTestCaseTools):

@defer.inlineCallbacks
Expand Down
2 changes: 1 addition & 1 deletion misc/doc/sources/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# The short X.Y version.
version = "0.9"
# The full version, including alpha/beta/rc tags.
release = "0.9.1-beta"
release = "0.9.2-beta"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion misc/doc/sources/faq/consume_MT_messages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gist from https://gist.github.com/zoufou/5701d71bf6e404d17cb4
# Gist from https://gist.github.com/farirat/5701d71bf6e404d17cb4
import cPickle as pickle
from twisted.internet.defer import inlineCallbacks
from twisted.internet import reactor
Expand Down
4 changes: 2 additions & 2 deletions misc/doc/sources/faq/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here's an example:

Thanks to Pedro_'s contribution::

Here is the PySQLPool mod to @zoufou ´s gist
Here is the PySQLPool mod to @farirat ´s gist
https://gist.github.com/pguillem/5750e8db352f001138f2

Here is the code to launch the consumer as a system Daemon in Debian/Ubuntu
Expand Down Expand Up @@ -135,4 +135,4 @@ Second, create a MT Route::

And you're done ! test your filter by sending a SMS through Jasmin's APIs.

.. _all: :ref:`Route_Routable`
.. _all: :ref:`Route_Routable`
5 changes: 3 additions & 2 deletions misc/doc/sources/faq/using_pb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gist from https://gist.github.com/zoufou/922e1cb2c4782660c257
# Gist from https://gist.github.com/farirat/922e1cb2c4782660c257
"""
An example of scenario with the following actions:
1. Add and start a SMPP Client connector
Expand All @@ -16,8 +16,9 @@
from jasmin.managers.proxies import SMPPClientManagerPBProxy
from jasmin.routing.proxies import RouterPBProxy
from jasmin.routing.Routes import DefaultRoute
from jasmin.routing.jasminApi import SmppClientConnector, User, Group
from jasmin.routing.jasminApi import User, Group
from jasmin.protocols.smpp.configs import SMPPClientConfig
from jasmin.protocols.cli.smppccm import JCliSMPPClientConfig as SmppClientConnector
from twisted.web.client import getPage

@defer.inlineCallbacks
Expand Down

0 comments on commit 2450634

Please sign in to comment.