Skip to content

Commit

Permalink
Merge pull request #119 from ARGOeu/devel
Browse files Browse the repository at this point in the history
Version 0.5.3
  • Loading branch information
themiszamani authored Sep 8, 2020
2 parents 70d2fdc + 637f5bb commit 510c2a0
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 50 deletions.
91 changes: 60 additions & 31 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,86 @@
# Changelog

## [0.5.3] - 2020-09-08

### FIXED

* ARGO-2530 bytes handling in Py3

## [0.5.2] - 2020-07-08

### FIXED

* ARGO-2479 Modify subscription offset method fails
* ARGO-2360 Fix ack_sub retry loop

## [0.5.1] - 2020-02-12

### Fixed
- ARGO-2182 ams-lib does not retry on topic publish
- fixed RPM autodependencies so py2 RPM is no longer requiring py3 ABI
- replaced include in MANIFEST.in with graft

* ARGO-2182 ams-lib does not retry on topic publish
* fixed RPM autodependencies so py2 RPM is no longer requiring py3 ABI
* replaced include in MANIFEST.in with graft

## [0.5.0] - 2019-12-19

### Added
- ARGO-1481 Connection retry logic in ams-library

* ARGO-1481 Connection retry logic in ams-library

## [0.4.3] - 2019-11-08

### Added
- ARGO-1862 Make argo-ams-library Python 3 ready
- ARGO-1841 Update the ams library to include the new timeToOffset functionality

* ARGO-1862 Make argo-ams-library Python 3 ready
* ARGO-1841 Update the ams library to include the new timeToOffset functionality

## [0.4.2-1] - 2018-06-26

### Added
- ARGO-1120 Extend AMS client to support X509 method via the authentication

* ARGO-1120 Extend AMS client to support X509 method via the authentication

### Fixed
- Updated error handling
- Error handling bug during list_topic route and upgrade to v0.4.2

* Updated error handling
* Error handling bug during list_topic route and upgrade to v0.4.2

## [0.4.0-1] - 2018-05-09

### Added
- Extend ams library to support offset manipulation
- Introduce AmsHttpRequests class
- Common methods for PUT, GET, POST requests
- Tests for backend error messages that could be plaintext or JSON encoded
- Failed TopicPublish and CreateSubscription tests
- Separated error mocks
- Extend ams library to support offset manipulation
- Grab methods from class namespace
- Tests for bogus offset specified
- Added missed 'all' value for offset argument
- Handle 404 for topic and subscription calls
- Handle JSON error message propagated through AMS

* Extend ams library to support offset manipulation
* Introduce AmsHttpRequests class
* Common methods for PUT, GET, POST requests
* Tests for backend error messages that could be plaintext or JSON encoded
* Failed TopicPublish and CreateSubscription tests
* Separated error mocks
* Extend ams library to support offset manipulation
* Grab methods from class namespace
* Tests for bogus offset specified
* Added missed 'all' value for offset argument
* Handle 404 for topic and subscription calls
* Handle JSON error message propagated through AMS

### Fixed
- set for error codes and pass request args for iters
- Status msg attach to AmsServiceException if exist
- Topic ALREADY_EXIST error test
- Fix returnImmediately parameter in sub pull request
- Remove not raised TypeError exception handles
- Refactored error handling with error routes
- Offsets method with combined logic of get and move offsets

* set for error codes and pass request args for iters
* Status msg attach to AmsServiceException if exist
* Topic ALREADY_EXIST error test
* Fix returnImmediately parameter in sub pull request
* Remove not raised TypeError exception handles
* Refactored error handling with error routes
* Offsets method with combined logic of get and move offsets

## [0.3.0-1] - 2017-07-27

### Added
- Sphinx documentation to ams library
- Add dockerfile that builds documentation

* Sphinx documentation to ams library
* Add dockerfile that builds documentation

## [0.2.0-1] - 2017-06-08

### Added
- A simple library for interacting with the ARGO Messaging Service

* A simple library for interacting with the ARGO Messaging Service
4 changes: 3 additions & 1 deletion argo-ams-library.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Name: argo-ams-library
Summary: %{sum}
Version: 0.5.2
Version: 0.5.3
Release: 1%{?dist}

Group: Development/Libraries
Expand Down Expand Up @@ -95,6 +95,8 @@ rm -rf %{buildroot}


%changelog
* Tue Sep 8 2020 Daniel Vrcic <[email protected]> - 0.5.3-1%{?dist}
- ARGO-2530 bytes handling in Py3
* Wed Jul 8 2020 Daniel Vrcic <[email protected]> - 0.5.2-1%{?dist}
- ARGO-2479 Modify subscription offset method fails
- ARGO-2360 Fix ack_sub retry loop
Expand Down
19 changes: 11 additions & 8 deletions pymod/amsmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def set_data(self, data, b64enc=True):
b64enc (bool): Control whether data should be Base64 encoded
"""
if b64enc and data:
if sys.version_info < (3, ):
self._data = b64encode(data)
else:
self._data = str(b64encode(bytearray(data, 'utf-8')), 'utf-8')
try:
if sys.version_info < (3, ):
self._data = b64encode(data)
else:
if isinstance(data, bytes):
self._data = str(b64encode(data), 'utf-8')
else:
self._data = str(b64encode(bytearray(data, 'utf-8')), 'utf-8')
except Exception as e:
raise AmsMessageException('b64encode() {0}'.format(str(e)))
elif data:
self._data = data

Expand All @@ -78,10 +84,7 @@ def get_data(self):

if self._has_dataattr():
try:
if sys.version_info <(3, ):
return b64decode(self._data)
else:
return str(b64decode(self._data), 'utf-8')
return b64decode(self._data)
except Exception as e:
raise AmsMessageException('b64decode() {0}'.format(str(e)))

Expand Down
5 changes: 4 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def pull_mock(url, request):
resp_pull = self.ams.pull_sub("subscription1", 1)
ack_id, msg = resp_pull[0]
assert ack_id == "projects/TEST/subscriptions/subscription1:1221"
assert msg.get_data() == "base64encoded"
if sys.version_info < (3, ):
assert msg.get_data() == "base64encoded"
else:
assert msg.get_data() == b"base64encoded"
assert msg.get_msgid() == "1221"
# Note: Maybe ack_sub should return a boolean
resp_ack = self.ams.ack_sub("subscription1", ["1221"])
Expand Down
5 changes: 4 additions & 1 deletion tests/test_errorclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ def testPullAckSub(self, mock_requests_post):
resp_pullack = self.ams.pullack_sub("subscription1", 1)
assert isinstance(resp_pullack, list)
assert isinstance(resp_pullack[0], AmsMessage)
self.assertEqual(resp_pullack[0].get_data(), "base64encoded")
if sys.version_info < (3, ):
self.assertEqual(resp_pullack[0].get_data(), "base64encoded")
else:
self.assertEqual(resp_pullack[0].get_data(), b"base64encoded")
self.assertEqual(resp_pullack[0].get_msgid(), "1221")


Expand Down
29 changes: 22 additions & 7 deletions tests/test_message.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-

import unittest
import sys

from pymod import AmsMessage
from pymod import AmsMessageException

class TestMessage(unittest.TestCase):

def setUp(self):
m = AmsMessage()
self.message_callable = m(attributes={'foo': 'bar'}, data='baz')
Expand All @@ -17,6 +17,8 @@ def setUp(self):
self.message_send_onlyattr = AmsMessage(attributes={'foo': 'bar'})
self.message_send_onlydata = AmsMessage(data='baz')
self.message_unicode = AmsMessage(data='ùňĭćőđĕ')
if sys.version_info >= (3, ):
self.message_unicode_py3 = AmsMessage(data='ùňĭćőđĕḃẏṫєṡ'.encode('utf-8'))

self.message_recv = AmsMessage(b64enc=False, attributes={'foo': 'bar'},
data='YmF6', messageId='1',
Expand All @@ -31,20 +33,33 @@ def test_MsgReadyToSend(self):
'data': 'YmF6'})
self.assertEqual(self.message_callable, {'attributes': {'foo': 'bar'},
'data': 'YmF6'})
self.assertEqual(self.message_callable_memoization, {'attributes': {'foo1': 'bar1'},
'data': 'YmF6'})
self.assertEqual(self.message_callable_memoization, {'attributes':
{'foo1': 'bar1'},
'data': 'YmF6'})
self.assertEqual(self.message_callable_memoization_two, {'attributes': {'foo1': 'bar1'},
'data': 'YmF6MQ=='})
'data': 'YmF6MQ=='})
self.assertEqual(self.message_send_onlyattr.dict(), {'attributes': {'foo': 'bar'}})
self.assertEqual(self.message_send_onlydata.dict(), {'data': 'YmF6'})
self.assertEqual(self.message_unicode.dict(), {'data': 'w7nFiMStxIfFkcSRxJU='})
self.assertEqual(self.message_unicode.get_data(), 'ùňĭćőđĕ')
if sys.version_info < (3, ):
self.assertEqual(self.message_unicode.get_data(), 'ùňĭćőđĕ')
else:
self.assertEqual(self.message_unicode.get_data(), 'ùňĭćőđĕ'.encode('utf-8'))

if sys.version_info >= (3, ):
self.assertEqual(self.message_unicode_py3.get_data(), 'ùňĭćőđĕḃẏṫєṡ'.encode('utf-8'))

self.message_send.set_data('baz')
self.assertEqual(self.message_send.get_data(), 'baz')
if sys.version_info < (3, ):
self.assertEqual(self.message_send.get_data(), 'baz')
else:
self.assertEqual(self.message_send.get_data(), b'baz')

def test_MsgReadyToRecv(self):
self.assertEqual(self.message_recv.get_data(), 'baz')
if sys.version_info < (3, ):
self.assertEqual(self.message_recv.get_data(), 'baz')
else:
self.assertEqual(self.message_recv.get_data(), b'baz')
self.assertEqual(self.message_recv.get_msgid(), '1')
self.assertEqual(self.message_recv.get_publishtime(),
'2017-03-15T17:11:34.035345612Z')
Expand Down
6 changes: 5 additions & 1 deletion tests/test_subscription.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import json
import sys

import datetime
from httmock import urlmatch, HTTMock, response
Expand Down Expand Up @@ -98,7 +99,10 @@ def ack_mock(url, request):
ack_id, msg = resp_pull[0]

self.assertEqual(ack_id, "projects/TEST/subscriptions/subscription1:1221")
self.assertEqual(msg.get_data(), "base64encoded")
if sys.version_info < (3, ):
self.assertEqual(msg.get_data(), "base64encoded")
else:
self.assertEqual(msg.get_data(), b"base64encoded")
self.assertEqual(msg.get_msgid(), "1221")
resp_ack = sub.ack(["1221"])
self.assertEqual(resp_ack, True)
Expand Down

0 comments on commit 510c2a0

Please sign in to comment.