Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_compare(self):
self.assertEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
self.assertNotEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 3))
self.assertLess(Build(15, 0, 1, 2), Build(15, 0, 1, 3))
self.assertLess(Build(15, 0, 1, 2), Build(15, 0, 2, 2))
self.assertLess(Build(15, 0, 1, 2), Build(15, 1, 1, 2))
self.assertLess(Build(15, 0, 1, 2), Build(16, 0, 1, 2))
self.assertLessEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
self.assertGreater(Build(15, 0, 1, 2), Build(15, 0, 1, 1))
self.assertGreater(Build(15, 0, 1, 2), Build(15, 0, 0, 2))
self.assertGreater(Build(15, 1, 1, 2), Build(15, 0, 1, 2))
self.assertGreater(Build(15, 0, 1, 2), Build(14, 0, 1, 2))
self.assertGreaterEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
def test_compare(self):
self.assertEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
self.assertNotEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 3))
self.assertLess(Build(15, 0, 1, 2), Build(15, 0, 1, 3))
self.assertLess(Build(15, 0, 1, 2), Build(15, 0, 2, 2))
self.assertLess(Build(15, 0, 1, 2), Build(15, 1, 1, 2))
self.assertLess(Build(15, 0, 1, 2), Build(16, 0, 1, 2))
self.assertLessEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
self.assertGreater(Build(15, 0, 1, 2), Build(15, 0, 1, 1))
self.assertGreater(Build(15, 0, 1, 2), Build(15, 0, 0, 2))
self.assertGreater(Build(15, 1, 1, 2), Build(15, 0, 1, 2))
self.assertGreater(Build(15, 0, 1, 2), Build(14, 0, 1, 2))
self.assertGreaterEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
def test_compare(self):
self.assertEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
self.assertNotEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 3))
self.assertLess(Build(15, 0, 1, 2), Build(15, 0, 1, 3))
self.assertLess(Build(15, 0, 1, 2), Build(15, 0, 2, 2))
self.assertLess(Build(15, 0, 1, 2), Build(15, 1, 1, 2))
self.assertLess(Build(15, 0, 1, 2), Build(16, 0, 1, 2))
self.assertLessEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
self.assertGreater(Build(15, 0, 1, 2), Build(15, 0, 1, 1))
self.assertGreater(Build(15, 0, 1, 2), Build(15, 0, 0, 2))
self.assertGreater(Build(15, 1, 1, 2), Build(15, 0, 1, 2))
self.assertGreater(Build(15, 0, 1, 2), Build(14, 0, 1, 2))
self.assertGreaterEqual(Build(15, 0, 1, 2), Build(15, 0, 1, 2))
def test_magic(self):
with self.assertRaises(ValueError):
Build(7, 0)
self.assertEqual(str(Build(9, 8, 7, 6)), '9.8.7.6')
def test_close(self):
proc = psutil.Process()
ip_addresses = {info[4][0] for info in socket.getaddrinfo(
'example.com', 80, socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP
)}
self.assertGreater(len(ip_addresses), 0)
protocol = Protocol(config=Configuration(
service_endpoint='http://example.com', credentials=Credentials('A', 'B'),
auth_type=NOAUTH, version=Version(Build(15, 1)), retry_policy=FailFast()
))
session = protocol.get_session()
session.get('http://example.com')
self.assertEqual(len({p.raddr[0] for p in proc.connections() if p.raddr[0] in ip_addresses}), 1)
protocol.release_session(session)
protocol.close()
self.assertEqual(len({p.raddr[0] for p in proc.connections() if p.raddr[0] in ip_addresses}), 0)
def test_from_response(self, m):
# Test fallback to suggested api_version value when there is a version mismatch and response version is fishy
version = Version.from_soap_header(
'Exchange2007',
to_xml(b'''\
''')
)
self.assertEqual(version.api_version, EXCHANGE_2007.api_version())
self.assertEqual(version.api_version, 'Exchange2007')
self.assertEqual(version.build, Build(15, 1, 845, 22))
# Test that override the suggested version if the response version is not fishy
version = Version.from_soap_header(
'Exchange2013',
to_xml(b'''\
''')
)
self.assertEqual(version.api_version, 'HELLO_FROM_EXCHANGELIB')
# Test that we override the suggested version with the version deduced from the build number if a version is not
# present in the response
version = Version.from_soap_header(
return self.__cmp__(other) > 0
def __ge__(self, other):
return self.__cmp__(other) >= 0
def __str__(self):
return '%s.%s.%s.%s' % (self.major_version, self.minor_version, self.major_build, self.minor_build)
def __repr__(self):
return self.__class__.__name__ \
+ repr((self.major_version, self.minor_version, self.major_build, self.minor_build))
# Helpers for comparison operations elsewhere in this package
EXCHANGE_2007 = Build(8, 0)
EXCHANGE_2007_SP1 = Build(8, 1)
EXCHANGE_2010 = Build(14, 0)
EXCHANGE_2010_SP1 = Build(14, 1)
EXCHANGE_2010_SP2 = Build(14, 2)
EXCHANGE_2013 = Build(15, 0)
EXCHANGE_2013_SP1 = Build(15, 0, 847)
EXCHANGE_2016 = Build(15, 1)
EXCHANGE_2019 = Build(15, 2)
EXCHANGE_O365 = Build(15, 20)
@python_2_unicode_compatible
class Version(PickleMixIn):
"""
Holds information about the server version
"""
__slots__ = ('build', 'api_version')
def __str__(self):
return '%s.%s.%s.%s' % (self.major_version, self.minor_version, self.major_build, self.minor_build)
def __repr__(self):
return self.__class__.__name__ \
+ repr((self.major_version, self.minor_version, self.major_build, self.minor_build))
# Helpers for comparison operations elsewhere in this package
EXCHANGE_2007 = Build(8, 0)
EXCHANGE_2007_SP1 = Build(8, 1)
EXCHANGE_2010 = Build(14, 0)
EXCHANGE_2010_SP1 = Build(14, 1)
EXCHANGE_2010_SP2 = Build(14, 2)
EXCHANGE_2013 = Build(15, 0)
EXCHANGE_2013_SP1 = Build(15, 0, 847)
EXCHANGE_2016 = Build(15, 1)
EXCHANGE_2019 = Build(15, 2)
EXCHANGE_O365 = Build(15, 20)
@python_2_unicode_compatible
class Version(PickleMixIn):
"""
Holds information about the server version
"""
__slots__ = ('build', 'api_version')
def __init__(self, build, api_version=None):
if not isinstance(build, (Build, type(None))):
raise ValueError("'build' must be a Build instance")
self.build = build
def __gt__(self, other):
return self.__cmp__(other) > 0
def __ge__(self, other):
return self.__cmp__(other) >= 0
def __str__(self):
return '%s.%s.%s.%s' % (self.major_version, self.minor_version, self.major_build, self.minor_build)
def __repr__(self):
return self.__class__.__name__ \
+ repr((self.major_version, self.minor_version, self.major_build, self.minor_build))
# Helpers for comparison operations elsewhere in this package
EXCHANGE_2007 = Build(8, 0)
EXCHANGE_2007_SP1 = Build(8, 1)
EXCHANGE_2010 = Build(14, 0)
EXCHANGE_2010_SP1 = Build(14, 1)
EXCHANGE_2010_SP2 = Build(14, 2)
EXCHANGE_2013 = Build(15, 0)
EXCHANGE_2013_SP1 = Build(15, 0, 847)
EXCHANGE_2016 = Build(15, 1)
EXCHANGE_2019 = Build(15, 2)
EXCHANGE_O365 = Build(15, 20)
@python_2_unicode_compatible
class Version(PickleMixIn):
"""
Holds information about the server version
"""