diff --git a/test/old_tests/counter26.py b/test/counter26.py similarity index 100% rename from test/old_tests/counter26.py rename to test/counter26.py diff --git a/test/new_tests/conftest.py b/test/new_tests/conftest.py index 6fe1b4497..88f3d3c35 100644 --- a/test/new_tests/conftest.py +++ b/test/new_tests/conftest.py @@ -1,5 +1,5 @@ import pytest -from test_base_class import TestBaseClass +from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike") diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index 85c253765..eafd9d4ab 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -1,17 +1,11 @@ # -*- coding: utf-8 -*- import pytest -import time import sys -try: - import cPickle as pickle -except: - import pickle -from aerospike.exception import * -from .test_base_class import TestBaseClass +from aerospike import exception as e aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike except: print("Please install aerospike python client.") sys.exit(1) @@ -24,7 +18,7 @@ def setup(self, request, as_connection): """ Setup Method """ - for i in xrange(5): + for i in range(5): key = ('test', 'demo', i) rec = {'name': 'name%s' % (str(i)), 'age': i} as_connection.put(key, rec) @@ -37,7 +31,7 @@ def teardown(): """ Teardown Method """ - for i in xrange(5): + for i in range(5): key = ('test', 'demo', i) as_connection.remove(key) @@ -53,7 +47,7 @@ def test_pos_append_with_correct_paramters(self): key = ('test', 'demo', 1) self.as_connection.append(key, "name", "str") - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1str'} @@ -62,12 +56,12 @@ def test_pos_append_with_correct_policies(self): Invoke append() with correct policies """ key = ('test', 'demo', 1) - policy = {'timeout': 1000, + policy = {'timeout': 1000, 'retry': aerospike.POLICY_RETRY_ONCE, 'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER } self.as_connection.append(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1str'} @@ -84,7 +78,7 @@ def test_pos_append_with_policy_key_send(self): } self.as_connection.append(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1str'} assert key == ('test', 'demo', None, bytearray( @@ -107,7 +101,7 @@ def test_pos_append_with_policy_key_digest(self): } self.as_connection.append(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1str', 'nolist': [1, 2, 3]} assert key == ('test', 'demo', None, @@ -162,7 +156,6 @@ def test_pos_append_with_policy_key_gen_EQ_positive(self): b'\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8') ) - def test_pos_append_with_policy_key_gen_GT_positive(self): """ Invoke append() with gen GT positive @@ -194,7 +187,7 @@ def test_pos_append_with_nonexistent_key(self): key = ('test', 'demo', 1000) status = self.as_connection.append(key, "name", "str") - assert status == 0L + assert status == 0 self.as_connection.remove(key) def test_pos_append_with_nonexistent_bin(self): @@ -204,17 +197,16 @@ def test_pos_append_with_nonexistent_bin(self): key = ('test', 'demo', 1) status = self.as_connection.append(key, "name1", "str") - assert status == 0L + assert status == 0 - def test_pos_append_unicode_value(self): """ Invoke append() with unicode string """ key = ('test', 'demo', 1) - res = self.as_connection.append(key, "name", u"address") + self.as_connection.append(key, "name", u"address") - key, meta, bins = self.as_connection.get(key) + key, _, bins = self.as_connection.get(key) assert bins['name'] == 'name1address' def test_pos_append_unicode_bin_name(self): @@ -222,25 +214,24 @@ def test_pos_append_unicode_bin_name(self): Invoke append() with unicode string """ key = ('test', 'demo', 1) - res = self.as_connection.append(key, u"add", u"address") + self.as_connection.append(key, u"add", u"address") - key, meta, bins = self.as_connection.get(key) + key, _, bins = self.as_connection.get(key) assert bins['add'] == 'address' - def test_pos_append_with_correct_timeout_policy(self): """ Invoke append() with correct policy """ key = ('test', 'demo', 1) policy = {'gen': 5, - 'timeout': 300, - 'retry': aerospike.POLICY_RETRY_ONCE, - 'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER - } + 'timeout': 300, + 'retry': aerospike.POLICY_RETRY_ONCE, + 'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER + } self.as_connection.append(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1str'} @@ -270,14 +261,14 @@ def test_pos_append_with_bytearray_new_key(self): self.as_connection.remove(key) - #Negative append tests + # Negative append tests def test_neg_append_with_no_parameters(self): """ Invoke append() without any mandatory parameters. """ with pytest.raises(TypeError) as typeError: self.as_connection.append() - assert "Required argument 'key' (pos 1) not found" in typeError.value + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) def test_neg_append_with_policy_key_gen_GT_lesser(self): """ @@ -300,10 +291,10 @@ def test_neg_append_with_policy_key_gen_GT_lesser(self): } try: self.as_connection.append(key, "name", "str", meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.bin == "name" - (key , meta, bins) = self.as_connection.get(key) + (key, meta, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1'} assert key == ('test', 'demo', None, bytearray( b'\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8') @@ -330,11 +321,11 @@ def test_neg_append_with_policy_key_gen_EQ_not_equal(self): try: self.as_connection.append(key, "name", "str", meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.bin == "name" - (key , meta, bins) = self.as_connection.get(key) + (key, meta, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'name1'} assert key == ('test', 'demo', None, bytearray( @@ -347,7 +338,7 @@ def test_neg_append_with_policy_key_gen_EQ_not_equal(self): (('test', 'demo', 1), 3, "str", {}, {'gen': 5, 'timeout': 3000, 'retry': aerospike.POLICY_RETRY_ONCE, 'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER}, -2, 'Bin name should be of type string'), - (('test', 'name'), "name", "str", {}, {"gen": 5}, -2, + (('test', 'name'), "name", "str", {}, {"gen": 5}, -2, 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)'), (('test', 'demo', 1), "name", "str", {}, {'timeout': 0.5}, -2, "timeout is invalid") ]) @@ -359,7 +350,7 @@ def test_neg_append_parameters_of_incorrect_types(self, key, bin, value, try: self.as_connection.append(key, bin, value, meta, policy) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -372,7 +363,7 @@ def test_neg_append_with_extra_parameter(self): with pytest.raises(TypeError) as typeError: self.as_connection.append(key, "name", "str", {}, policy, "") - assert "append() takes at most 5 arguments (6 given)" in typeError.value + assert "append() takes at most 5 arguments (6 given)" in str(typeError.value) @pytest.mark.parametrize("key, bin, ex_code, ex_msg", [ (None, "name", -2, "key is invalid"), @@ -385,7 +376,7 @@ def test_neg_append_parameters_as_none(self, key, bin, ex_code, ex_msg): try: self.as_connection.append(key, bin, "str") - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -400,8 +391,8 @@ def test_neg_append_with_correct_parameters_without_connection(self): try: client1.append(key, "name", "str") - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 def test_neg_append_with_low_timeout(self): @@ -410,14 +401,14 @@ def test_neg_append_with_low_timeout(self): """ key = ('test', 'demo', 1) policy = {'gen': 5, - 'timeout': 1, - #'retry': aerospike.POLICY_RETRY_ONCE, - 'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER - } + 'timeout': 1, + # 'retry': aerospike.POLICY_RETRY_ONCE, + 'commit_level': aerospike.POLICY_COMMIT_LEVEL_MASTER + } try: self.as_connection.append(key, "name", "str", {}, policy) - except TimeoutError as exception: - assert exception.code == 9L + except e.TimeoutError as exception: + assert exception.code == 9 def test_neg_append_with_non_existent_ns(self): """ @@ -425,10 +416,9 @@ def test_neg_append_with_non_existent_ns(self): """ key = ('test1', 'demo', 'name') policy = {'gen': 5, - 'timeout': 300, - } + 'timeout': 300, + } try: self.as_connection.append(key, "name", "str", {}, policy) - except NamespaceNotFound as exception: - assert exception.code == 20L - + except e.NamespaceNotFound as exception: + assert exception.code == 20 diff --git a/test/new_tests/test_base_class.py b/test/new_tests/test_base_class.py index 2200ff7ee..2be09cb1f 100644 --- a/test/new_tests/test_base_class.py +++ b/test/new_tests/test_base_class.py @@ -1,6 +1,8 @@ import pytest -import ConfigParser - +try: + import ConfigParser as configparser +except: + import configparser class TestBaseClass(object): hostlist = [] @@ -11,7 +13,7 @@ class TestBaseClass(object): @staticmethod def get_hosts(): - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read("config.conf") if config.has_option('enterprise-edition', 'hosts'): hosts_str = config.get('enterprise-edition','hosts') diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index 3722c5f3d..b91aa7b49 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -2,15 +2,12 @@ import pytest import sys -try: - import cPickle as pickle -except: - import pickle from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -24,13 +21,13 @@ def test_pos_close(self): Invoke close() after positive connect """ config = {'hosts': TestBaseClass.hostlist} - if TestClose.user == None and TestClose.password == None: + if TestClose.user is None and TestClose.password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect(TestClose.user, TestClose.password) self.closeobject = self.client.close() - assert self.closeobject == None + assert self.closeobject is None def test_pos_close_without_connection(self): """ @@ -42,8 +39,8 @@ def test_pos_close_without_connection(self): try: self.closeobject = self.client.close() - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 def test_neg_close(self): """ @@ -51,10 +48,10 @@ def test_neg_close(self): """ config = {'hosts': [('127.0.0.1', 2000)]} - with pytest.raises(Exception) as exception: + with pytest.raises(Exception): self.client = aerospike.client(config).connect() with pytest.raises(AttributeError) as attributeError: self.closeobject = self.client.close() - assert "TestClose instance has no attribute 'client'" in attributeError.value + assert "has no attribute" in str(attributeError.value) diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index 89c522272..4110027b7 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -7,11 +7,12 @@ except: import pickle from .test_base_class import TestBaseClass -import time; +import time aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -36,7 +37,7 @@ def test_pos_exists_with_key_and_policy(self, put_data): put_data(self.as_connection, key, record) - key, meta =self.as_connection.exists(key, policy) + key, meta = self.as_connection.exists(key, policy) assert meta['gen'] != None assert meta['ttl'] != None @@ -62,7 +63,7 @@ def test_pos_exists_with_diff_datatype(self, key, record, put_data): Invoke exists() for diffrent record data. """ put_data(self.as_connection, key, record) - key, meta =self.as_connection.exists(key) + key, meta = self.as_connection.exists(key) assert meta['gen'] != None assert meta['ttl'] != None @@ -83,7 +84,7 @@ def test_pos_exists_with_key_and_policy(self, key, record, policy, put_data): Invoke exists() with key and policy. """ put_data(self.as_connection, key, record, _policy=policy) - key, meta =self.as_connection.exists(key, policy) + key, meta = self.as_connection.exists(key, policy) assert meta['gen'] != None assert meta['ttl'] != None @@ -97,23 +98,23 @@ def test_neg_exists_with_record_expiry(self, put_data): policy = {'timeout': 1000} put_data(self.as_connection, key, rec, meta, policy) time.sleep(2) - key, meta =self.as_connection.exists(key) - assert meta == None + key, meta = self.as_connection.exists(key) + assert meta is None @pytest.mark.parametrize("key, ex, ex_code", [ # reason for xfail CLIENT-533 - pytest.mark.xfail((('test', 'demo', 'non-existent'), RecordNotFound, 2)), # non-existent key - pytest.mark.xfail((('test', 'set', 1), RecordNotFound, 2)), # non-existent set - (('namespace', 'demo', 1), NamespaceNotFound, 20L), # non-existent Namespace - pytest.mark.xfail((('test', None, 2), RecordNotFound, 2)), #None set in key tuple. - pytest.mark.xfail((('test', 'demo', 'Non_existing_key'), RecordNotFound, 2)), # Non_existing_key + pytest.mark.xfail((('test', 'demo', 'non-existent'), e.RecordNotFound, 2)), # non-existent key + pytest.mark.xfail((('test', 'set', 1), e.RecordNotFound, 2)), # non-existent set + (('namespace', 'demo', 1), e.NamespaceNotFound, 20), # non-existent Namespace + pytest.mark.xfail((('test', None, 2), e.RecordNotFound, 2)), #None set in key tuple. + pytest.mark.xfail((('test', 'demo', 'Non_existing_key'), e.RecordNotFound, 2)), # Non_existing_key ]) def test_neg_exists_with_non_existent_data(self, key, ex, ex_code): """ Invoke exists() for non-existent data. """ try: - key, meta =self.as_connection.exists( key ) + key, _ = self.as_connection.exists(key) """ We are making the api backward compatible. In case of RecordNotFound an @@ -132,30 +133,30 @@ def test_neg_exists_with_only_key_without_connection(self): client1 = aerospike.client(config) try: - key, meta = client1.exists( key ) + key, _ = client1.exists(key) - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 @pytest.mark.parametrize("key, record, meta, policy", [ (('test', 'demo', 20), {"name": "John"}, {'gen': 3, 'ttl': 1}, {'timeout': 2}), ]) def test_neg_exists_with_low_timeout(self, key, record, meta, policy, put_data): try: - put_data(self.as_connection, key, record, meta, policy) - except TimeoutError as exception: - assert exception.code == 9L - key,meta =self.as_connection.exists(key) - assert meta['gen'] !=None + put_data(self.as_connection, key, record, meta, policy) + except e.TimeoutError as exception: + assert exception.code == 9 + key, meta = self.as_connection.exists(key) + assert meta['gen'] is not None def test_neg_exists_with_no_paramters(self): """ Invoke self() without any mandatory parameters. """ with pytest.raises(TypeError) as typeError: - self.as_connection.exists() + self.as_connection.exists() - assert "Required argument 'key' (pos 1) not found" in typeError.value + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) @pytest.mark.parametrize("key, record, policy, ex_code, ex_msg",[ # timeout_is_string @@ -172,9 +173,9 @@ def test_neg_exists_with_invalid_meta(self, key, record, policy, ex_code, ex_msg put_data(self.as_connection, key, record) try: - key, meta =self.as_connection.exists( key, policy) + key, _ = self.as_connection.exists(key, policy) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -189,7 +190,7 @@ def test_neg_exists_key_invalid_data(self, key, ex_code, ex_msg): Invoke exists() with invalid key """ try: - key, meta =self.as_connection.exists(key) - except ParamError as exception: + key, _ = self.as_connection.exists(key) + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index f61b0acdc..0ec86408c 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -4,6 +4,7 @@ import time import sys from .test_base_class import TestBaseClass + try: from collections import Counter except ImportError: @@ -11,19 +12,19 @@ aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) - @pytest.mark.usefixtures("as_connection") class TestExistsMany(): def test_pos_exists_many_without_policy(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) @@ -35,7 +36,7 @@ def test_pos_exists_many_without_policy(self, put_data): def test_pos_exists_many_with_proper_parameters_without_connection(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) @@ -50,7 +51,7 @@ def test_pos_exists_many_with_proper_parameters_without_connection(self, put_dat def test_pos_exists_many_with_none_policy(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) @@ -66,7 +67,7 @@ def test_pos_exists_many_with_none_policy(self, put_data): def test_pos_exists_many_with_non_existent_keys(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) @@ -90,7 +91,6 @@ def test_pos_exists_many_with_all_non_existent_keys(self): records = self.as_connection.exists_many(keys) - assert len(records) == 1 for x in records: if x[0][2] == 'key': @@ -99,12 +99,12 @@ def test_pos_exists_many_with_all_non_existent_keys(self): def test_pos_exists_many_with_initkey_as_digest(self, put_data): keys = [] - key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl")) + key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8")) rec = {'name': 'name1', 'age': 1} self.as_connection.put(key, rec) keys.append(key) - key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl")) + key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl", "utf-8")) rec = {'name': 'name2', 'age': 2} put_data(self.as_connection, key, rec) keys.append(key) @@ -124,7 +124,7 @@ def test_pos_exists_many_with_initkey_as_digest(self, put_data): def test_pos_exists_many_with_non_existent_keys_in_middle(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) @@ -132,7 +132,7 @@ def test_pos_exists_many_with_non_existent_keys_in_middle(self, put_data): self.keys.append(('test', 'demo', 'some_key')) - for i in xrange(15, 20): + for i in range(15, 20): key = ('test', 'demo', i) rec = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, rec) @@ -168,41 +168,41 @@ def test_pos_exists_many_with_record_expiry(self, put_data): def test_neg_exists_many_with_none_keys(self): try: - self.as_connection.exists_many( None, {} ) + self.as_connection.exists_many(None, {}) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Keys should be specified as a list or tuple." def test_neg_exists_many_with_invalid_key(self): try: - records = self.as_connection.exists_many( "key" ) + self.as_connection.exists_many("key") - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Keys should be specified as a list or tuple." def test_neg_exists_many_with_invalid_timeout(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) self.keys.append(key) - policies = { 'timeout' : 0.2 } + policies = {'timeout': 0.2} try: - records = self.as_connection.exists_many(self.keys, policies) + self.as_connection.exists_many(self.keys, policies) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "timeout is invalid" def test_neg_exists_many_with_proper_parameters_without_connection(self, put_data): self.keys = [] rec_length = 5 - for i in xrange(rec_length): + for i in range(rec_length): key = ('test', 'demo', i) record = {'name': 'name%s' % (str(i)), 'age': i} put_data(self.as_connection, key, record) @@ -212,37 +212,37 @@ def test_neg_exists_many_with_proper_parameters_without_connection(self, put_dat client1 = aerospike.client(config) try: - records = client1.exists_many(self.keys, { 'timeout': 20 } ) - - except ClusterError as exception: - assert exception.code == 11L + client1.exists_many(self.keys, {'timeout': 20}) + + except e.ClusterError as exception: + assert exception.code == 11 def test_neg_exists_many_with_extra_parameter_in_key(self, put_data): keys = [] - key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl")) + key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8")) rec = {'name': 'name1', 'age': 1} put_data(self.as_connection, key, rec) keys.append(key) - key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl")) + key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl", "utf-8")) rec = {'name': 'name2', 'age': 2} put_data(self.as_connection, key, rec) keys.append(key) - keys_get =[] - key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl"),None) + keys_get = [] + key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8"), None) keys_get.append(key) - key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl"),None) + key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl", "utf-8"), None) keys_get.append(key) try: - self.as_connection.exists_many( keys_get ) + self.as_connection.exists_many(keys_get) - except ParamError as exception: - assert exception.code == -2L + except e.ParamError as exception: + assert exception.code == -2 assert exception.msg == "key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)" - + for key in keys: self.as_connection.remove(key) @@ -252,34 +252,31 @@ def test_neg_exists_many_with_low_timeout(self, put_data): rec = {"name": "John"} meta = {'gen': 3, 'ttl': 1} policy = {'timeout': 2} - + try: put_data(self.as_connection, key, rec, meta, policy) - except TimeoutError as exception: - assert exception.code == 9L - + except e.TimeoutError as exception: + assert exception.code == 9 + keys.append(key) records = self.as_connection.exists_many(keys) assert type(records) == list assert len(records) == 1 def test_neg_exists_many_with_invalid_ns(self): - #ToDo: not sure about put operation + # ToDo: not sure about put operation keys = [] key = ('test2', 'demo', 20) - rec = {"name": "John"} - meta = {'gen': 3, 'ttl': 300} - policy = {'timeout': 1000} - #self.as_connection.put(key, rec, meta, policy) + # self.as_connection.put(key, rec, meta, policy) keys.append(key) try: - records = self.as_connection.exists_many(keys) - except NamespaceNotFound as exception: - assert exception.code == 20L + self.as_connection.exists_many(keys) + except e.NamespaceNotFound as exception: + assert exception.code == 20 def test_neg_exists_many_without_any_parameter(self): with pytest.raises(TypeError) as typeError: self.as_connection.exists_many() - assert "Required argument 'keys' (pos 1) not found" in typeError.value + assert "Required argument 'keys' (pos 1) not found" in str(typeError.value) diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index 1af12d5b3..fe5a620ae 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -10,7 +10,8 @@ aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -20,7 +21,7 @@ class TestGetMany(): @pytest.fixture(autouse=True) def setup(self, request, as_connection): self.keys = [] - for i in xrange(5): + for i in range(5): key = ('test', 'demo', i) rec = {'name': 'name%s' % (str(i)), 'age': i} as_connection.put(key, rec) @@ -33,7 +34,7 @@ def teardown(): """ Teardown method. """ - for i in xrange(5): + for i in range(5): key = ('test', 'demo', i) as_connection.remove(key) key = ('test', 'demo', 'float_value') @@ -57,12 +58,12 @@ def test_pos_get_many_with_proper_parameters(self): assert Counter([x[0][2] for x in records]) == Counter([0, 1, 2, 3, 4, 'float_value']) assert records[5][2] == {'float_value': 4.3} - + def test_pos_get_many_with_none_policy(self): records = self.as_connection.get_many(self.keys, None) for x in records: - print x + print (x) assert type(records) == list assert len(records) == 6 assert Counter([x[0][2] for x in records]) == Counter([0, 1, 2, 3, @@ -96,13 +97,13 @@ def test_pos_get_many_with_all_non_existent_keys(self): def test_pos_get_many_with_initkey_as_digest(self): keys = [] - key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl")) + key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8")) rec = {'name': 'name1', 'age': 1} self.as_connection.put(key, rec) keys.append(key) - key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl")) + key = ("test", "demo", None, bytearray("ase;as[d'as;djk;uyfl", "utf-8")) rec = {'name': 'name2', 'age': 2} self.as_connection.put(key, rec) @@ -122,12 +123,12 @@ def test_pos_get_many_with_initkey_as_digest(self): else: assert x[0][3] == bytearray(b"asd;as[d'as;djk;uyfl") i = i+1 - + def test_pos_get_many_with_non_existent_keys_in_middle(self): self.keys.append(('test', 'demo', 'some_key')) - for i in xrange(15, 20): + for i in range(15, 20): key = ('test', 'demo', i) rec = {'name': 'name%s' % (str(i)), 'age': i} self.as_connection.put(key, rec) @@ -135,7 +136,7 @@ def test_pos_get_many_with_non_existent_keys_in_middle(self): records = self.as_connection.get_many(self.keys) - for i in xrange(15, 20): + for i in range(15, 20): key = ('test', 'demo', i) self.as_connection.remove(key) @@ -173,53 +174,51 @@ def test_neg_get_many_Invalid_Key_without_primary_key(self): Invoke get_many() without primary key """ key = ('test', 'set') - policy = {'timeout': 1000} try: - key, meta, bins = self.as_connection.get(key) + key, _, _ = self.as_connection.get(key) - except ParamError as exception: - assert exception.code == -2L + except e.ParamError as exception: + assert exception.code == -2 assert exception.msg == 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)' - + def test_neg_get_many_with_proper_parameters_without_connection(self): config = {'hosts': [('127.0.0.1', 3000)]} client1 = aerospike.client(config) try: - records = client1.get_many( self.keys, { 'timeout': 20 } ) + client1.get_many(self.keys, {'timeout': 20}) - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 def test_neg_prepend_Invalid_Key_without_set_name(self): """ Invoke prepend() without set name """ key = ('test', 1) - policy = {'timeout': 1000} try: - # TestGet.client.prepend(key, "name", "ABC", {}, policy) - key, meta, bins = self.as_connection.get(key) + # TestGet.client.prepend(key, "name", "ABC", {}, policy) + key, _, _ = self.as_connection.get(key) - except ParamError as exception: - assert exception.code == -2L + except e.ParamError as exception: + assert exception.code == -2 assert exception.msg == 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)' def test_neg_get_many_with_invalid_key(self): try: - records = self.as_connection.get_many( "key" ) + self.as_connection.get_many("key") - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Keys should be specified as a list or tuple." def test_neg_get_many_with_invalid_timeout(self): - policies = { 'timeout' : 0.2 } + policies = {'timeout': 0.2} try: - records = self.as_connection.get_many(self.keys, policies) + self.as_connection.get_many(self.keys, policies) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "timeout is invalid" @@ -228,14 +227,14 @@ def test_neg_get_many_without_any_parameter(self): with pytest.raises(TypeError) as typeError: self.as_connection.get_many() - assert "Required argument 'keys' (pos 1) not found" in typeError.value + assert "Required argument 'keys' (pos 1) not found" in str(typeError.value) def test_neg_get_many_with_none_keys(self): try: - self.as_connection.get_many( None, {} ) + self.as_connection.get_many(None, {}) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Keys should be specified as a list or tuple." @@ -244,9 +243,8 @@ def test_neg_prepend_Invalid_Key_Invalid_ns(self): Invoke prepend() invalid namespace """ key = ('test1', 'demo', 1) - policy = {'timeout': 1000} try: - key, meta, bins = self.as_connection.get(key) + key, _, _ = self.as_connection.get(key) - except NamespaceNotFound as exception: + except e.NamespaceNotFound as exception: assert exception.code == 20 diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index aa130b3b0..302d2cc45 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -6,17 +6,18 @@ import cPickle as pickle except: import pickle -from collections import OrderedDict -from .test_base_class import TestBaseClass -import time +# from collections import OrderedDict +from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) + class SomeClass(object): pass @@ -43,14 +44,14 @@ class TestGetPut(): (('test', 'demo', 'list_key'), {'names': ['John', 'Marlen', 1024]}), (('test', 'demo', 'list_key_unicode'), {'a': [u'aa', u'bb', 1, u'bb', u'aa']}), (('test', 'demo', 'objects'), {'objects': [pickle.dumps(SomeClass()), pickle.dumps(SomeClass())]}), - + # Map Data (('test', 'demo', 'map_key'), {'names': {'name': 'John', 'age': 24}}), (('test', 'demo', 'map_key_float'), {"double_map": {"1": 3.141,"2": 4.123,"3": 6.285}}), (('test', 'demo', 'map_key_unicode'), {'a': {u'aa': u'11'}, 'b': {u'bb': u'22'}}), - (('test', 'demo', 1), - {'odict': OrderedDict(sorted({'banana': 3, 'apple': 4, 'pear': 1, 'orange': 2}.items(), - key=lambda t: t[0]))}), + # (('test', 'demo', 1), + # {'odict': OrderedDict(sorted({'banana': 3, 'apple': 4, 'pear': 1, 'orange': 2}.items(), + # key=lambda t: t[0]))}), # Tuple Data (('test', 'demo', 'tuple_key'), {'tuple_seq': tuple('abc')}), @@ -80,24 +81,24 @@ def test_pos_get_put_with_key(self, _input, _expected, put_data): """ Invoke get() with a key and not policy's dict. """ - put_data(self.as_connection,_input, _expected) - key, meta, bins = self.as_connection.get(_input) + put_data(self.as_connection, _input, _expected) + _, _, bins = self.as_connection.get(_input) assert bins == _expected @pytest.mark.parametrize("_input, _expected", [ (('test', 'demo', '1'), None), (('test', None, 2), None), # None is valid entry for set (('test', 'some_random_set', 1), None), - (('test', 'demo', 'non-existent'), None), + (('test', 'demo', 'non-existent'), None), ]) def test_pos_get_with_data_missing(self, _input, _expected): """ Invoke get() with different combinations of None in key """ - key, meta, bins = self.as_connection.get( _input ) + _, meta, bins = self.as_connection.get(_input) assert bins == _expected assert meta == _expected - + def test_pos_get_initkey_with_digest(self, put_data): """ Invoke get() for a record having bytestring data. @@ -110,20 +111,19 @@ def test_pos_get_initkey_with_digest(self, put_data): put_data(self.as_connection, key, rec, policy) - key, meta, bins = self.as_connection.get(key, policy) + key, _, bins = self.as_connection.get(key, policy) assert bins == {'name': 'john'} assert key == ('test', 'demo', None, bytearray(b"asd;as[d\'as;djk;uyfl")) - @pytest.mark.parametrize("_input, _record, _policy, _expected", [ - (('test', 'demo', 3), - {'name': 'name%s' % (str(3)), 'age': 3}, + (('test', 'demo', 3), + {'name': 'name%s' % (str(3)), 'age': 3}, aerospike.POLICY_KEY_DIGEST, None), - (('test', 'demo', 3), - {'name': 'name%s' % (str(3)), 'age': 3}, + (('test', 'demo', 3), + {'name': 'name%s' % (str(3)), 'age': 3}, aerospike.POLICY_KEY_SEND, 3), ]) @@ -155,7 +155,7 @@ def test_pos_get_initkey_with_policy_send(self, put_data): put_data(self.as_connection, key, rec, policy) - key, meta, bins = self.as_connection.get(key, policy) + key, _, bins = self.as_connection.get(key, policy) assert bins == {'name': 'john', 'age': 1} assert key == ('test', 'demo', 1, bytearray( @@ -170,7 +170,7 @@ def test_neg_get_with_no_parameter(self): with pytest.raises(TypeError) as typeError: self.as_connection.get() - assert "Required argument 'key' (pos 1) not found" in typeError.value + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) def test_neg_get_with_extra_parameter_in_key(self, put_data): """ @@ -184,7 +184,7 @@ def test_neg_get_with_extra_parameter_in_key(self, put_data): try: put_data(self.as_connection, key, rec, policy) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)' @@ -193,23 +193,23 @@ def test_neg_get_with_key_digest(self): Invoke get() with a key digest. """ key = ('test', 'demo', 1) - key, meta = self.as_connection.exists(key) + key, _ = self.as_connection.exists(key) try: - key, meta, bins = self.as_connection.get((key[0], key[1], None, key[2])) - except ParamError as exception: + key, _, _ = self.as_connection.get((key[0], key[1], None, key[2])) + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == 'digest is invalid. expected a bytearray' @pytest.mark.parametrize("_input, _expected", [ - ((None, 'demo', 2), + ((None, 'demo', 2), (-2, 'namespace must be a string')), - (('test', 'demo', None), + (('test', 'demo', None), (-2, 'either key or digest is required')), - (None , + (None, (-2, 'key is invalid')), - (('test', 'demo'), + (('test', 'demo'), (-2, 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)')), - (('test', 'demo','',''), + (('test', 'demo', '', ''), (-2, 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)')), ]) def test_neg_get_with_none(self, _input, _expected): @@ -217,9 +217,9 @@ def test_neg_get_with_none(self, _input, _expected): Invoke get() with None namespace/key in key tuple. """ try: - key, meta, bins = self.as_connection.get(_input) + self.as_connection.get(_input) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == _expected[0] assert exception.msg == _expected[1] @@ -230,9 +230,9 @@ def test_neg_get_with_non_existent_namespace(self): key = ('namespace', 'demo', 1) try: - key, meta, bins = self.as_connection.get(key) + key, _, _ = self.as_connection.get(key) - except NamespaceNotFound as exception: + except e.NamespaceNotFound as exception: assert exception.code == 20 @pytest.mark.parametrize("_input, _expected", [ @@ -244,9 +244,9 @@ def test_neg_get_remove_key_and_check_get(self, _input, _expected, put_data): """ put_data(self.as_connection, _input, _expected) self.as_connection.remove(_input) - key, meta, bins = self.as_connection.get(_input) - assert bins == None - + _, _, bins = self.as_connection.get(_input) + assert bins is None + def test_neg_get_with_only_key_no_connection(self): """ Invoke get() with a key and not policy's dict no connection @@ -256,10 +256,10 @@ def test_neg_get_with_only_key_no_connection(self): client1 = aerospike.client(config) try: - key, meta, bins = client1.get( key ) + key, _, _ = client1.get(key) - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 # Put Tests def test_pos_put_with_policy_exists_create_or_replace(self): @@ -283,7 +283,6 @@ def test_pos_put_with_policy_exists_create_or_replace(self): (key, meta, bins) = self.as_connection.get(key) assert rec == bins - rec = {"name": "John"} meta = {'gen': 2, 'ttl': 25000} policy = { @@ -341,7 +340,6 @@ def test_pos_put_with_policy_exists_ignore_update(self): (key, meta, bins) = self.as_connection.get(key) assert rec == bins - key = ('test', 'demo', 1) rec = {"name": "John"} @@ -470,12 +468,12 @@ def test_pos_put_with_policy_gen_ignore(self): assert rec == bins self.as_connection.remove(key) - @pytest.mark.parametrize("key, record, meta, policy",[ - (('test', 'demo', 1), {'name': 'john'}, + @pytest.mark.parametrize("key, record, meta, policy", [ + (('test', 'demo', 1), {'name': 'john'}, {'gen': True, 'ttl': 25000}, {'timeout': 1000}), - (('test', 'demo', 1), {'name': 'john'}, + (('test', 'demo', 1), {'name': 'john'}, {'gen': 3, 'ttl': True}, {'timeout': 1000}), - (('test', 'demo', 1), {'name': 'john'}, + (('test', 'demo', 1), {'name': 'john'}, {'gen': True, 'ttl': True}, {'timeout': 1000}), ]) def test_pos_put_with_metadata_bool(self, key, record, meta, policy, put_data): @@ -501,7 +499,7 @@ def test_pos_put_user_serializer_no_deserializer(self): def serialize_function(val): return pickle.dumps(val) - response = aerospike.set_serializer(serialize_function) + aerospike.set_serializer(serialize_function) res = self.as_connection.put(key, rec, {}, {}, aerospike.SERIALIZER_USER) @@ -509,7 +507,7 @@ def serialize_function(val): _, _, bins = self.as_connection.get(key) - if self.skip_old_server == False: + if self.skip_old_server is False: assert bins == {'pi': 3.14} else: assert bins == {'pi': bytearray(b'F3.1400000000000001\n.')} @@ -522,9 +520,9 @@ def test_neg_put_with_no_parameters(self): Invoke put() without any parameters. """ with pytest.raises(TypeError) as typeError: - res = self.as_connection.put() + self.as_connection.put() - assert "Required argument 'key' (pos 1) not found" in typeError.value + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) def test_neg_put_without_record(self): """ @@ -533,12 +531,12 @@ def test_neg_put_without_record(self): key = ('test', 'demo', 1) with pytest.raises(TypeError) as typeError: - res = self.as_connection.put(key) + self.as_connection.put(key) - assert "Required argument 'bins' (pos 2) not found" in typeError.value + assert "Required argument 'bins' (pos 2) not found" in str(typeError.value) @pytest.mark.parametrize("key, record, ex_code, ex_msg", [ - (None, {"name": "John"}, -2, 'key is invalid'), + (None, {"name": "John"}, -2, 'key is invalid'), # Invalid Namespace ((None, "demo", 1), {"name": "Steve"}, -2, "namespace must be a string" ), # Invalid Key @@ -548,7 +546,7 @@ def test_neg_put_without_record(self): # Invalid set name (('test', 123, 1), {'a': ['!@#!#$%#', bytearray('ASD@#$AR#$@#ERQ#', 'utf-8')]}, -2, 'set must be a string'), # Invalid Namespace - ((123, 'demo', 1), { 'i': 'asdadasd' }, -2, 'namespace must be a string') + ((123, 'demo', 1), {'i': 'asdadasd'}, -2, 'namespace must be a string') ]) def test_neg_put_with_none_key(self, key, record, ex_code, ex_msg): @@ -557,16 +555,16 @@ def test_neg_put_with_none_key(self, key, record, ex_code, ex_msg): """ try: - res = self.as_connection.put(key, record) + self.as_connection.put(key, record) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @pytest.mark.parametrize("key, record, exception_code", [ # Non-existing NS & Set (('demo', 'test', 1), {'a': ['!@#!#$%#', bytearray('ASD@#$AR#$@#ERQ#', 'utf-8')]}, 20), - (('test1', 'demo', 1), { 'i': 'asdadasd' }, 20), # Non-existing Namespace + (('test1', 'demo', 1), {'i': 'asdadasd'}, 20), # Non-existing Namespace ]) def test_neg_put_with_wrong_ns_and_set(self, key, record, exception_code): @@ -574,9 +572,9 @@ def test_neg_put_with_wrong_ns_and_set(self, key, record, exception_code): Invoke put() with non-existent data """ try: - res = self.as_connection.put( key, record) + self.as_connection.put(key, record) - except NamespaceNotFound as exception: + except e.NamespaceNotFound as exception: assert exception.code == exception_code def test_neg_put_with_policy_gen_EQ_less(self): @@ -593,19 +591,18 @@ def test_neg_put_with_policy_gen_EQ_less(self): (key, meta, bins) = self.as_connection.get(key) assert {"name": "John"} == bins - gen = meta['gen'] rec = {"name": "Smith"} policy = {'timeout': 1000, 'gen': aerospike.POLICY_GEN_EQ} meta = {'gen': 10} try: - self.as_connection.put( key, rec, meta, policy ) + self.as_connection.put(key, rec, meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.msg == 'AEROSPIKE_ERR_RECORD_GENERATION' - - ( key, meta, bins) = self.as_connection.get(key) + + (key, meta, bins) = self.as_connection.get(key) assert {"name": "John"} == bins self.as_connection.remove(key) @@ -624,19 +621,18 @@ def test_neg_put_with_policy_gen_EQ_more(self): (key, meta, bins) = self.as_connection.get(key) assert {"name": "John"} == bins - gen = meta['gen'] rec = {"name": "Smith"} policy = {'timeout': 1000, 'gen': aerospike.POLICY_GEN_EQ} meta = {'gen': 4} try: - self.as_connection.put( key, rec, meta, policy ) + self.as_connection.put(key, rec, meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.msg == 'AEROSPIKE_ERR_RECORD_GENERATION' - - ( key, meta, bins) = self.as_connection.get(key) + + (key, meta, bins) = self.as_connection.get(key) assert {"name": "John"} == bins self.as_connection.remove(key) @@ -666,9 +662,9 @@ def test_neg_put_with_policy_exists_create(self): meta = {'gen': 2} try: - self.as_connection.put( key, rec, meta, policy ) + self.as_connection.put(key, rec, meta, policy) - except RecordExistsError as exception: + except e.RecordExistsError as exception: assert exception.code == 5 assert exception.msg == 'AEROSPIKE_ERR_RECORD_EXISTS' assert exception.bin == {'name': 'Smith'} @@ -694,9 +690,9 @@ def test_neg_put_with_policy_exists_replace_negative(self): 'key': aerospike.POLICY_KEY_SEND } try: - assert 0 == self.as_connection.put( key, rec, meta, policy ) + assert 0 == self.as_connection.put(key, rec, meta, policy) - except RecordNotFound as exception: + except e.RecordNotFound as exception: assert exception.code == 2 assert exception.msg == 'AEROSPIKE_ERR_RECORD_NOT_FOUND' @@ -712,10 +708,10 @@ def test_neg_put_with_policy_replace(self): try: self.as_connection.put(key, rec, meta, policy) - except RecordNotFound as exception: + except e.RecordNotFound as exception: assert exception.code == 2 assert exception.msg == 'AEROSPIKE_ERR_RECORD_NOT_FOUND' - + def test_neg_put_with_policy_exists_update_negative(self): """ Invoke put() for a record with update policy negative. @@ -732,9 +728,9 @@ def test_neg_put_with_policy_exists_update_negative(self): 'key': aerospike.POLICY_KEY_SEND } try: - assert 0 == self.as_connection.put( key, rec, meta, policy ) + assert 0 == self.as_connection.put(key, rec, meta, policy) - except RecordNotFound as exception: + except e.RecordNotFound as exception: assert exception.code == 2 assert exception.msg == 'AEROSPIKE_ERR_RECORD_NOT_FOUND' @@ -758,9 +754,9 @@ def test_neg_put_with_policy_gen_GT_lesser(self): meta = {'gen': gen} try: - self.as_connection.put( key, rec, meta, policy ) + self.as_connection.put(key, rec, meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.msg == 'AEROSPIKE_ERR_RECORD_GENERATION' @@ -780,18 +776,18 @@ def test_neg_put_with_string_record_without_connection(self): bins = {"name": "John"} try: - client1.put( key, bins ) - except ClusterError as exception: - assert exception.code == 11L + client1.put(key, bins) + except e.ClusterError as exception: + assert exception.code == 11 @pytest.mark.parametrize("key, record, meta, policy, ex_code, ex_msg", [ - (('test', 'demo', 1), {'name': 'john'}, + (('test', 'demo', 1), {'name': 'john'}, {'gen': "wrong", 'ttl': 25000}, {'timeout': 1000}, #Gen as string -2, "Generation should be an int or long"), - (('test', 'demo', 1), {'name': 'john'}, + (('test', 'demo', 1), {'name': 'john'}, {'gen': 3, 'ttl': "25000"}, {'timeout': 1000}, # ttl as string -2, "TTL should be an int or long"), - (('test', 'demo', 1), {'name': 'john'}, + (('test', 'demo', 1), {'name': 'john'}, {'gen': 3, 'ttl': 25000}, {'timeout': "1000"}, # Timeout as string -2, "timeout is invalid"), (('test', 'demo', 1), {'name': 'john'}, #Policy as string @@ -811,7 +807,7 @@ def test_neg_put_with_invalid_metadata(self, key, record, meta, policy, ex_code, try: put_data(self.as_connection, key, record, meta, policy) # self.as_connection.remove(key) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -836,10 +832,10 @@ def test_edge_put_record_with_bin_name_exceeding_max_limit(self): } try: - self.as_connection.put( key, put_record) + self.as_connection.put(key, put_record) - except BinNameError as exception: - assert exception.code == 21L + except e.BinNameError as exception: + assert exception.code == 21 def test_edge_put_with_integer_greater_than_maxisze(self): """ @@ -852,9 +848,11 @@ def test_edge_put_with_integer_greater_than_maxisze(self): try: assert 0 == self.as_connection.put(key, bins) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == 'integer value exceeds sys.maxsize' + except SystemError as exception: + pass def test_edge_put_with_key_as_an_integer_greater_than_maxsize(self): """ @@ -867,6 +865,8 @@ def test_edge_put_with_key_as_an_integer_greater_than_maxsize(self): try: assert 0 == self.as_connection.put(key, bins) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == 'integer value for KEY exceeds sys.maxsize' + except SystemError as exception: + pass diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index d8d37fb3d..3b6aa8e61 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -2,11 +2,11 @@ import pytest import sys from .test_base_class import TestBaseClass -from aerospike import exception as e aerospike = pytest.importorskip("aerospike") try: import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -85,7 +85,7 @@ def teardown(): request.addfinalizer(teardown) @pytest.mark.parametrize("key, llist, expected", [ - (('test', 'demo', 1), + (('test', 'demo', 1), [{"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": u"ram"}, @@ -258,7 +258,7 @@ def test_pos_operate_with_policy_gen_ignore(self, key, policy, meta, llist): assert key == ('test', 'demo', 1, bytearray( b'\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8') ) - + def test_pos_operate_with_policy_gen_EQ(self): """ Invoke operate() with gen EQ positive. @@ -314,7 +314,7 @@ def test_pos_operate_touch_operation_with_bin_and_value_combination(self, key, l (key, meta) = self.as_connection.exists(key) assert meta['ttl'] != None - + def test_pos_operate_with_policy_gen_EQ_not_equal(self): """ Invoke operate() with gen not equal. @@ -447,9 +447,8 @@ def test_pos_operate_with_nonexistent_bin(self): llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "addr", - "val": "pune"}, - {"op": aerospike.OPERATOR_READ, - "bin": "addr"} + "val": "pune"}, + {"op": aerospike.OPERATOR_READ, "bin": "addr"} ] key, _, bins = self.as_connection.operate(key, llist) @@ -544,7 +543,7 @@ def test_pos_operate_write_set_to_aerospike_null(self): "op": aerospike.OPERATOR_PREPEND, "bin": "age", "val": 4}, - { + { "op": aerospike.OPERATOR_READ, "bin": "age" }], @@ -554,17 +553,17 @@ def test_pos_operate_write_set_to_aerospike_null(self): "op": aerospike.OPERATOR_APPEND, "bin": "dict", "val": {"a": 1, "b": 2}}, - { + { "op": aerospike.OPERATOR_READ, "bin": "dict" }], {'dict': {"a": 1, "b": 2}}), (('test', 'demo', 'incr_string'), # incr_with_string - [{ + [{ "op": aerospike.OPERATOR_INCR, "bin": "name", "val": "aerospike"}, - { + { "op": aerospike.OPERATOR_READ, "bin": "name" }], @@ -584,16 +583,16 @@ def test_pos_operate_new_record(self, key, llist, expected): "op": aerospike.OPERATOR_PREPEND, "bin": "age", "val": 4}, - { + { "op": aerospike.OPERATOR_READ, "bin": "age" - }]), + }]), (('test', 'demo', 'existing_key'), # Existing list [{ "op": aerospike.OPERATOR_PREPEND, "bin": "list", "val": ['c']}, - { + { "op": aerospike.OPERATOR_READ, "bin": "list" }]), @@ -602,7 +601,7 @@ def test_pos_operate_new_record(self, key, llist, expected): "op": aerospike.OPERATOR_APPEND, "bin": "dict", "val": {"c": 2}}, - { + { "op": aerospike.OPERATOR_READ, "bin": "dict" }]), @@ -611,7 +610,7 @@ def test_pos_operate_new_record(self, key, llist, expected): "op": aerospike.OPERATOR_APPEND, "bin": "float", "val": 3.4}, - { + { "op": aerospike.OPERATOR_READ, "bin": "float" }]), @@ -620,7 +619,7 @@ def test_pos_operate_new_record(self, key, llist, expected): "op": aerospike.OPERATOR_INCR, "bin": "name", "val": "aerospike"}, - { + { "op": aerospike.OPERATOR_READ, "bin": "name" }]), @@ -629,7 +628,7 @@ def test_pos_operate_new_record(self, key, llist, expected): "op": aerospike.OPERATOR_INCR, "bin": "bytearray", "val": bytearray("abc", "utf-8")}, - { + { "op": aerospike.OPERATOR_READ, "bin": "bytearray" }]), @@ -806,7 +805,7 @@ def test_pos_operate_prepend_set_to_aerospike_null(self): ], {'int_bin': 10}, "int_bin", [1, 2, 3, 4, None, None, 10]) ]) def test_pos_operate_with_list_addition_operations(self, list, result, bin, - expected): + expected): """ Invoke operate() with list addition operations """ @@ -815,7 +814,7 @@ def test_pos_operate_with_list_addition_operations(self, list, result, bin, key, _, bins = self.as_connection.operate(key, list) assert bins == result - + key, _, bins = self.as_connection.get(key) assert bins[bin] == expected @@ -844,7 +843,7 @@ def test_pos_operate_with_list_addition_operations(self, list, result, bin, ], "int_bin", []) ]) def test_pos_operate_with_list_remove_operations(self, list, bin, - expected): + expected): """ Invoke operate() with list remove operations """ @@ -895,7 +894,7 @@ def test_pos_operate_with_list_trim_val_with_negative_value(self): "val": -9}] (key, meta, bins) = self.as_connection.operate(key, list) - + (key, meta, bins) = self.as_connection.get(key) assert bins['int_bin'] == [2, 3, 4] @@ -948,7 +947,7 @@ def test_pos_operate_with_list_insert_index_negative(self): ([ {"op": aerospike.OP_LIST_INSERT_ITEMS, "bin": "string_bin", - "val": [bytearray("abc"), u"xyz"], + "val": [bytearray("abc","utf-8"), u"xyz"], "index": 2}, {"op": aerospike.OP_LIST_POP_RANGE, "bin": "string_bin", @@ -967,7 +966,7 @@ def test_pos_operate_with_list_operations_different_datatypes(self, list, result key, _, bins = self.as_connection.operate(key, list) assert bins == result - + key, _, bins = self.as_connection.get(key) assert bins[bin] == expected @@ -988,12 +987,12 @@ def test_neg_operate_list_operation_bin_notlist(self): """ key = ('test', 'demo', 1) list = [{"op": aerospike.OP_LIST_INSERT, - "bin": "age", - "index": 2, - "val": 9}] + "bin": "age", + "index": 2, + "val": 9}] try: - (key, meta, bins) = self.as_connection.operate(key, list) + (key, _, _) = self.as_connection.operate(key, list) except e.BinIncompatibleType as exception: assert exception.code == 12 @@ -1037,7 +1036,7 @@ def test_neg_operate_list_invalid_requests(self, list): """ key = ('test', 'demo', 'list_key') try: - key, _, bins = self.as_connection.operate(key, list) + key, _, _ = self.as_connection.operate(key, list) except e.InvalidRequest as exception: assert exception.code == 4 @@ -1162,8 +1161,8 @@ def test_neg_operate_key_is_none(self): assert exception.msg == "key is invalid" @pytest.mark.parametrize("key, policy, llist, ex_code, ex_msg", [ - ( ('test', 'demo', 1), - {'timeout': 1000}, + ( ('test', 'demo', 1), + {'timeout': 1000}, [ {"op": aerospike.OPERATOR_APPEND, "bin": "name"}, {"op": aerospike.OPERATOR_INCR, @@ -1187,7 +1186,7 @@ def test_neg_operate_key_is_none(self): "bin": "age", "val": "3"}, {"op": aerospike.OPERATOR_READ, "bin": "age"}], - -2, + -2, "Unsupported operand type(s) for +: only 'int' allowed"), ]) def test_neg_operate_append_without_value_parameter(self, key, policy, llist, ex_code, ex_msg): diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index d7eff0668..3947d9942 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -1,16 +1,12 @@ # -*- coding: utf-8 -*- import pytest -import time import sys -try: - import cPickle as pickle -except: - import pickle from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -21,7 +17,7 @@ def setup(self, request, as_connection): """ Setup Method """ - for i in xrange(5): + for i in range(5): key = ('test', 'demo', i) rec = {'name': 'name%s' % (str(i)), 'age': i, 'nolist': [1, 2, 3]} as_connection.put(key, rec) @@ -33,7 +29,7 @@ def teardown(): """ Teardown Method """ - for i in xrange(5): + for i in range(5): key = ('test', 'demo', i) as_connection.remove(key) @@ -49,7 +45,7 @@ def test_pos_prepend_with_correct_parameters(self): key = ('test', 'demo', 1) self.as_connection.prepend(key, "name", "str") - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'strname1', 'nolist': [1, 2, 3]} @@ -66,7 +62,7 @@ def test_pos_prepend_with_correct_policy(self): self.as_connection.prepend(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'strname1', 'nolist': [1, 2, 3]} @@ -83,7 +79,7 @@ def test_pos_prepend_with_policy_key_send(self): } self.as_connection.prepend(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'strname1', 'nolist': [1, 2, 3]} assert key == ('test', 'demo', None, bytearray( @@ -176,7 +172,7 @@ def test_pos_prepend_with_policy_key_digest(self): } self.as_connection.prepend(key, "name", "str", {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) assert bins == {'age': 1, 'name': 'strname1', 'nolist': [1, 2, 3]} assert key == ('test', 'demo', None, @@ -192,9 +188,9 @@ def test_pos_prepend_unicode_parameters(self, key, bin, value, expected): """ Invoke prepend() with unicode parameters """ - res = self.as_connection.prepend(key, bin, value) + self.as_connection.prepend(key, bin, value) - key, meta, bins = self.as_connection.get(key) + key, _, bins = self.as_connection.get(key) assert bins[bin] == expected def test_pos_prepend_key_with_none_set_name(self): @@ -204,7 +200,7 @@ def test_pos_prepend_key_with_none_set_name(self): key = ('test', None, 1) policy = {'timeout': 1000} self.as_connection.prepend(key, "name", "ABC", {}, policy) - key, meta, bins = self.as_connection.get(key) + key, _, bins = self.as_connection.get(key) assert bins == {'name': 'ABC'} self.as_connection.remove(key) @@ -215,8 +211,8 @@ def test_pos_prepend_with_nonexistent_key(self): key = ('test', 'demo', 1000) status = self.as_connection.prepend(key, "name", "str") - assert status == 0L - key, meta, bins = self.as_connection.get(key) + assert status == 0 + key, _, bins = self.as_connection.get(key) assert bins['name'] == 'str' self.as_connection.remove(key) @@ -228,8 +224,8 @@ def test_pos_prepend_with_nonexistent_bin(self): key = ('test', 'demo', 1) status = self.as_connection.prepend(key, "name1", "str") - assert status == 0L - key, meta, bins = self.as_connection.get(key) + assert status == 0 + key, _, bins = self.as_connection.get(key) assert bins['name1'] == 'str' def test_pos_prepend_with_bytearray(self): @@ -266,7 +262,7 @@ def test_neg_prepend_with_no_parameters(self): """ with pytest.raises(TypeError) as typeError: self.as_connection.prepend() - assert "Required argument 'key' (pos 1) not found" in typeError.value + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) def test_neg_prepend_with_policy_key_gen_EQ_not_equal(self): """ @@ -281,7 +277,7 @@ def test_neg_prepend_with_policy_key_gen_EQ_not_equal(self): } (key, meta) = self.as_connection.exists(key) gen = meta['gen'] - + meta = { 'gen': gen + 5, 'ttl': 1200 @@ -289,7 +285,7 @@ def test_neg_prepend_with_policy_key_gen_EQ_not_equal(self): try: self.as_connection.prepend(key, "name", "str", meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.bin == 'name' @@ -321,7 +317,7 @@ def test_neg_prepend_with_policy_key_gen_GT_lesser(self): try: self.as_connection.prepend(key, "name", "str", meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 assert exception.bin == "name" @@ -343,7 +339,7 @@ def test_neg_prepend_with_incorrect_policy(self): try: self.as_connection.prepend(key, "name", "str", {}, policy) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "timeout is invalid" @@ -360,7 +356,7 @@ def test_neg_prepend_parameters_incorrect_datatypes(self, key, bin, value, try: self.as_connection.prepend(key, bin, value, meta, policy) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -373,7 +369,7 @@ def test_neg_prepend_with_extra_parameter(self): with pytest.raises(TypeError) as typeError: self.as_connection.prepend(key, "name", "str", {}, policy, "") - assert "prepend() takes at most 5 arguments (6 given)" in typeError.value + assert "prepend() takes at most 5 arguments (6 given)" in str(typeError.value) @pytest.mark.parametrize("key, bin, value, ex_code, ex_msg", [ (None, "name", "str", -2, "key is invalid"), @@ -386,7 +382,7 @@ def test_neg_prepend_parameters_as_none(self, key, bin, value, ex_code, ex_msg): try: self.as_connection.prepend(key, bin, value) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -398,9 +394,9 @@ def test_neg_prepend_invalid_key_invalid_ns(self): policy = {'timeout': 1000} try: self.as_connection.prepend(key, "name", "ABC", {}, policy) - key, meta, bins = self.as_connection.get(key) + key, _, _ = self.as_connection.get(key) - except NamespaceNotFound as exception: + except e.NamespaceNotFound as exception: assert exception.code == 20 @pytest.mark.parametrize("key, bin, value, meta, policy, ex_code, ex_msg", [ @@ -409,15 +405,15 @@ def test_neg_prepend_invalid_key_invalid_ns(self): (('test', 'demo', 1, 1, 1), "name", "ABC", {}, {'timeout': 1000}, -2, 'key tuple must be (Namespace, Set, Key) or (Namespace, Set, None, Digest)') ]) def test_neg_prepend_invalid_key_combinations(self, key, bin, value, - meta, policy, ex_code, ex_msg): + meta, policy, ex_code, ex_msg): """ Invoke prepend() with invalid key combinations """ try: self.as_connection.prepend(key, bin, value, meta, policy) - key, meta, bins = self.as_connection.get(key) + key, meta, _ = self.as_connection.get(key) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -429,11 +425,11 @@ def test_neg_prepend_without_bin_name(self): policy = {'timeout': 1000} try: self.as_connection.prepend(key, "ABC", {}, policy) - key, meta, bins = self.as_connection.get(key) - except ParamError as exception: + key, _, _ = self.as_connection.get(key) + except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Cannot concatenate 'str' and 'non-str' objects" - + def test_neg_prepend_with_correct_parameters_without_connection(self): """ Invoke prepend() with correct parameters without connection @@ -445,5 +441,5 @@ def test_neg_prepend_with_correct_parameters_without_connection(self): try: client1.prepend(key, "name", "str") - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index 7bae7717e..63212df78 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -2,15 +2,12 @@ import pytest import sys -try: - import cPickle as pickle -except: - import pickle from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -18,7 +15,7 @@ @pytest.mark.usefixtures("as_connection") class TestRemove(): - @pytest.mark.xfail (reason="open bug #client-533") + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_existing_record(self): """ Invoke remove() when records are present @@ -26,16 +23,16 @@ def test_pos_remove_with_existing_record(self): key = ('test', 'demo', 1) retobj = self.as_connection.remove(key) - assert retobj == 0L + assert retobj == 0 - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) - - (code,msg,_, _) = exception.value + with pytest.raises(e.RecordNotFound) as exception: + (key, _, _) = self.as_connection.get(key) + + (code, msg, _, _) = exception.value assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" assert code == 2 - @pytest.mark.xfail (reason="open bug #client-533") + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_policy(self): """ Invoke remove() with policy @@ -46,15 +43,15 @@ def test_pos_remove_with_policy(self): retobj = self.as_connection.remove(key, meta, policy) - assert retobj == 0L - - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) + assert retobj == 0 + + with pytest.raises(e.RecordNotFound) as exception: + (key, meta, _) = self.as_connection.get(key) - (code,msg,_, _) = exception.value + (code, msg, _, _) = exception.value assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" assert code == 2 - + key = ('test', 'demo', 1) rec = { 'name': 'name%s' % (str(1)), @@ -63,8 +60,8 @@ def test_pos_remove_with_policy(self): 'no': 1 } self.as_connection.put(key, rec) - - @pytest.mark.xfail (reason="open bug #client-533") + + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_policy_all(self): """ Invoke remove() with policy @@ -79,12 +76,12 @@ def test_pos_remove_with_policy_all(self): } retobj = self.as_connection.remove(key, meta, policy) - assert retobj == 0L + assert retobj == 0 - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) + with pytest.raises(e.RecordNotFound) as exception: + (key, meta, _) = self.as_connection.get(key) - (code,msg,_, _) = exception.value + (code, msg, _, _) = exception.value assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" assert code == 2 @@ -96,8 +93,8 @@ def test_pos_remove_with_policy_all(self): 'no': 1 } self.as_connection.put(key, rec) - - @pytest.mark.xfail (reason="open bug #client-533") + + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_policy_key_digest(self): """ Invoke remove() with policy_key_digest @@ -113,20 +110,20 @@ def test_pos_remove_with_policy_key_digest(self): } retobj = self.as_connection.put(key, policy) - assert retobj == 0L + assert retobj == 0 retobj = self.as_connection.remove(key, meta, policy) - assert retobj == 0L + assert retobj == 0 - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) + with pytest.raises(e.RecordNotFound) as exception: + (key, meta, _) = self.as_connection.get(key) - (code,msg,_, _) = exception.value + (code, msg, _, _) = exception.value assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" assert code == 2 - - @pytest.mark.xfail (reason="open bug #client-533") + + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_policy_gen_ignore(self): """ Invoke remove() with policy gen ignore @@ -142,16 +139,15 @@ def test_pos_remove_with_policy_gen_ignore(self): retobj = self.as_connection.remove(key, meta, policy) - assert retobj == 0L + assert retobj == 0 - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) + with pytest.raises(e.RecordNotFound) as exception: + (key, meta, _) = self.as_connection.get(key) - (code,msg,_, _) = exception.value + (code, msg, _, _) = exception.value assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" assert code == 2 - key = ('test', 'demo', 1) rec = { 'name': 'name%s' % (str(1)), @@ -161,7 +157,7 @@ def test_pos_remove_with_policy_gen_ignore(self): } self.as_connection.put(key, rec) - @pytest.mark.xfail (reason="Issue1 : open bug #client-533") + @pytest.mark.xfail(reason="Issue1 : open bug #client-533") def test_pos_remove_with_policy_gen_eq_positive(self): """ Invoke remove() with policy gen positive @@ -179,11 +175,11 @@ def test_pos_remove_with_policy_gen_eq_positive(self): meta = {'gen': gen} retobj = self.as_connection.remove(key, meta, policy) - assert retobj == 0L + assert retobj == 0 - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) - (code,msg,_, _) = exception.value + with pytest.raises(e.RecordNotFound) as exception: + (key, meta, _) = self.as_connection.get(key) + (code, msg, _, _) = exception.value assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" assert code == 2 @@ -196,7 +192,7 @@ def test_pos_remove_with_policy_gen_eq_positive(self): } self.as_connection.put(key, rec) - @pytest.mark.xfail (reason="open bug #client-533") + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_policy_gen_GT_positive(self): """ Invoke remove() with policy gen GT positive @@ -215,22 +211,22 @@ def test_pos_remove_with_policy_gen_GT_positive(self): retobj = self.as_connection.remove(key, metadata, policy) - assert retobj == 0L + assert retobj == 0 - with pytest.raises(RecordNotFound) as exception: - (key, meta, bins) = self.as_connection.get(key) - (code,msg,_, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" - assert code == 2 + with pytest.raises(e.RecordNotFound) as exception: + (key, meta, _) = self.as_connection.get(key) + (code, msg, _, _) = exception.value + assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + assert code == 2 - key = ('test', 'demo', 1) - rec = { - 'name': 'name%s' % (str(1)), - 'addr': 'name%s' % (str(1)), - 'age': 1, - 'no': 1 - } - self.as_connection.put(key, rec) + key = ('test', 'demo', 1) + rec = { + 'name': 'name%s' % (str(1)), + 'addr': 'name%s' % (str(1)), + 'age': 1, + 'no': 1 + } + self.as_connection.put(key, rec) # Negative Tests def test_neg_remove_with_policy_gen_eq_not_equal(self, put_data): @@ -243,7 +239,6 @@ def test_neg_remove_with_policy_gen_eq_not_equal(self, put_data): (key, meta) = self.as_connection.exists(key) gen = meta['gen'] + 5 - metadata = {'gen': gen} policy = { 'timeout': 1000, 'retry': aerospike.POLICY_RETRY_ONCE, @@ -253,12 +248,12 @@ def test_neg_remove_with_policy_gen_eq_not_equal(self, put_data): (key, meta) = self.as_connection.exists(key) gen = meta['gen'] + 5 #Increment Generation by 5 - - with pytest.raises(RecordGenerationError) as exception: - retobj = self.as_connection.remove(key, {"gen" : gen}, policy) - (code,msg,_, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_GENERATION" - assert code == 3 + + with pytest.raises(e.RecordGenerationError) as exception: + self.as_connection.remove(key, {"gen": gen}, policy) + (code, msg, _, _) = exception.value + assert msg == "AEROSPIKE_ERR_RECORD_GENERATION" + assert code == 3 def test_neg_remove_with_policy_gen_GT_lesser(self, put_data): """ @@ -271,22 +266,22 @@ def test_neg_remove_with_policy_gen_GT_lesser(self, put_data): 'timeout': 1000, 'retry': aerospike.POLICY_RETRY_ONCE, 'key': aerospike.POLICY_KEY_SEND, - 'gen': aerospike.POLICY_GEN_GT + 'gen': aerospike.POLICY_GEN_GT } - (key, meta) = self.as_connection.exists(key) # Record had GEN = x - lesserGen = meta['gen'] -1 #Compute GEN = x - 1 - - with pytest.raises(RecordGenerationError) as exception: - retobj = self.as_connection.remove(key, {"gen",lesserGen}, policy) - (code,msg,_, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_GENERATION" - assert code == 3 - + (key, meta) = self.as_connection.exists(key) + lesserGen = meta['gen'] - 1 + + with pytest.raises(e.RecordGenerationError) as exception: + self.as_connection.remove(key, ("gen", lesserGen), policy) + (code, msg, _, _) = exception.value + assert msg == "AEROSPIKE_ERR_RECORD_GENERATION" + assert code == 3 + (key, meta, bins) = self.as_connection.get(key) assert key == ('test', 'demo', None, bytearray(b'\xdd)Fs9\xa151\x91{\x1c\n\xc0\xac zV\x10Z+')) - assert meta != None + assert meta is not None assert bins == record def test_neg_remove_with_policy_as_string(self): @@ -295,13 +290,13 @@ def test_neg_remove_with_policy_as_string(self): """ key = ('test', 'demo', 1) meta = { - 'gen' : 0 + 'gen': 0 } - with pytest.raises(ParamError) as exception: - retobj = self.as_connection.remove(key, meta, "String_policy") - (code,msg,_, _) = exception.value - assert msg == "policy must be a dict" - assert code == -2 + with pytest.raises(e.ParamError) as exception: + self.as_connection.remove(key, meta, "String_policy") + (code, msg, _, _) = exception.value + assert msg == "policy must be a dict" + assert code == -2 def test_neg_remove_with_extra_parameter(self): """ @@ -311,8 +306,8 @@ def test_neg_remove_with_extra_parameter(self): meta = {'gen': 0} policy = {'timeout': 1000} with pytest.raises(TypeError) as typeError: - retobj = self.as_connection.remove(key, meta, policy, "Extra Param") - assert "remove() takes at most 3 arguments (4 given)" in typeError.value + self.as_connection.remove(key, meta, policy, "Extra Param") + assert "remove() takes at most 3 arguments (4 given)" in str(typeError.value) @pytest.mark.parametrize("key, ex_code, ex_msg", [ ((None, 'demo', 1), -2, "namespace must be a string"), @@ -327,16 +322,16 @@ def test_neg_remove_with_incorrect_data(self, key, ex_code, ex_msg): Invoke remove() with namespace as None """ - with pytest.raises(ParamError) as exception: - retobj = self.as_connection.remove(key) - (code,msg,_, _) = exception.value - assert msg == ex_msg - assert code == ex_code + with pytest.raises(e.ParamError) as exception: + self.as_connection.remove(key) + (code, msg, _, _) = exception.value + assert msg == ex_msg + assert code == ex_code @pytest.mark.parametrize("key, ex_name, ex_code", [ - (('test', None, 1), RecordNotFound, 2), - (('test', 'demo', "incorrect_key"), RecordNotFound, 2), - (('test', 'demo', "missing_record"), RecordNotFound, 2) + (('test', None, 1), e.RecordNotFound, 2), + (('test', 'demo', "incorrect_key"), e.RecordNotFound, 2), + (('test', 'demo', "missing_record"), e.RecordNotFound, 2) ]) def test_neg_remove_with_missing_record(self, key, ex_name, ex_code): @@ -344,9 +339,9 @@ def test_neg_remove_with_missing_record(self, key, ex_name, ex_code): Invoke remove() with set as None """ with pytest.raises(ex_name) as exception: - retobj = self.as_connection.remove(key) - (code,msg,_, _) = exception.value - assert code == ex_code + self.as_connection.remove(key) + (code, _, _, _) = exception.value + assert code == ex_code def test_neg_remove_with_correct_parameters_without_connection(self): """ @@ -356,10 +351,10 @@ def test_neg_remove_with_correct_parameters_without_connection(self): client1 = aerospike.client(config) key = ('test', 'demo', 1) - with pytest.raises(ClusterError) as exception: - retobj = client1.remove(key) - (code,msg,_, _) = exception.value - assert code == 11L + with pytest.raises(e.ClusterError) as exception: + client1.remove(key) + (code, _, _, _) = exception.value + assert code == 11 def test_neg_remove_with_no_parameters(self): """ @@ -368,5 +363,4 @@ def test_neg_remove_with_no_parameters(self): with pytest.raises(TypeError) as typeError: self.as_connection.remove() - assert "Required argument 'key' (pos 1) not found" in typeError.value - + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) diff --git a/test/new_tests/test_remove_bin.py b/test/new_tests/test_remove_bin.py index 85f9800c2..60b5606f8 100644 --- a/test/new_tests/test_remove_bin.py +++ b/test/new_tests/test_remove_bin.py @@ -1,16 +1,12 @@ # -*- coding: utf-8 -*- import pytest import sys -import time -try: - import cPickle as pickle -except: - import pickle from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike") try: - from aerospike.exception import * + import aerospike + from aerospike import exception as e except: print("Please install aerospike python client.") sys.exit(1) @@ -30,7 +26,7 @@ def test_pos_remove_bin_with_correct_parameters(self, key, record, bin_for_remov put_data(self.as_connection, key, record) self.as_connection.remove_bin(key, bin_for_removal) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) del record[''.join(bin_for_removal)] assert bins == record @@ -45,7 +41,7 @@ def test_pos_remove_bin_with_correct_policy(self, put_data): put_data(self.as_connection, key, record) self.as_connection.remove_bin(key, ["age"], {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) del record["age"] assert bins == record @@ -69,7 +65,7 @@ def test_pos_remove_bin_with_policy_send_gen_ignore(self, put_data): (key, meta, bins) = self.as_connection.get(key) del record["age"] assert bins == record - assert key == ('test', 'demo', None, + assert key == ('test', 'demo', None, bytearray(b"\xbd\x87-\x84\xae99|\x06z\x12\xf3\xef\x12\xb9\x1a\xa2\x1a;\'")) def test_pos_remove_bin_with_policy_send_gen_eq_positive(self, put_data): @@ -111,7 +107,7 @@ def test_pos_remove_bin_with_policy_key_digest(self, put_data): policy = {'timeout': 1000, 'key': aerospike.POLICY_KEY_DIGEST} self.as_connection.remove_bin(key, ["age"], {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) del record['age'] assert bins == record @@ -135,7 +131,7 @@ def test_pos_remove_bin_with_single_bin_in_a_record(self): self.as_connection.remove_bin(key, ["name"], {}, policy) _, _, bins = self.as_connection.get(key) - assert bins == None + assert bins is None def test_pos_remove_bin_no_bin(self, put_data): """ @@ -144,11 +140,12 @@ def test_pos_remove_bin_no_bin(self, put_data): key = ('test', 'demo', 1) record = {'name': "jeff", 'age': 45} put_data(self.as_connection, key, record) - self.as_connection.remove_bin(key, []) - - (key , meta, bins) = self.as_connection.get(key) - - assert bins == record + try: + self.as_connection.remove_bin(key, []) + (key, _, bins) = self.as_connection.get(key) + assert bins == record + except e.InvalidRequest: + pass @pytest.mark.parametrize("key, record, bins_for_removal", [ (('test', 'demo', 1), {'name': "Devid", 'age': 30}, ["name", "age"]), @@ -163,9 +160,9 @@ def test_pos_remove_bin_with_unicode_all(self, key, record, bins_for_removal, pu self.as_connection.remove_bin(key, bins_for_removal) try: - (key , meta, bins) = self.as_connection.get(key) + (key, _, _) = self.as_connection.get(key) - except RecordNotFound as exception: + except e.RecordNotFound as exception: assert exception.code == 2 @pytest.mark.parametrize("key, record, policy, bin_for_removal",[ @@ -219,18 +216,16 @@ def test_pos_remove_bin_with_policy_exists_create(self): Invoke remove_bin() with policy exists create to check if it creates a record """ key = ('test', 'demo', 20) - policy = { - 'exists': aerospike.POLICY_EXISTS_CREATE - } + policy = {'exists': aerospike.POLICY_EXISTS_CREATE} self.as_connection.remove_bin(key, ["age"], {}, policy) - (key, meta, bins) = self.as_connection.get(key) + (key, _, bins) = self.as_connection.get(key) - assert bins == None + assert bins is None # Negative Tests - @pytest.mark.parametrize("key, bin_for_removal, ex_code, ex_msg",[ + @pytest.mark.parametrize("key, bin_for_removal, ex_code, ex_msg", [ (None, ["age"], -2, "key is invalid"), # key_is_none (('test', 'demo', 1), None, -2, "Bins should be a list"), #bin_is_none ]) @@ -241,7 +236,7 @@ def test_neg_remove_bin_with_none(self, key, bin_for_removal, ex_code, ex_msg): try: self.as_connection.remove_bin(None, bin_for_removal) - except ParamError as exception: + except e.ParamError as exception: assert exception.code == ex_code assert exception.msg == ex_msg @@ -257,8 +252,8 @@ def test_neg_remove_bin_with_correct_parameters_without_connection(self): try: client1.remove_bin(key, ["age"]) - except ClusterError as exception: - assert exception.code == 11L + except e.ClusterError as exception: + assert exception.code == 11 def test_neg_remove_bin_with_incorrect_meta(self): """ @@ -274,7 +269,7 @@ def test_neg_remove_bin_with_incorrect_meta(self): try: self.as_connection.remove_bin(key, ["age"], policy) - except ClusterError as exception: + except e.ClusterError as exception: assert exception.code == -1 def test_neg_remove_bin_with_incorrect_policy(self): @@ -289,7 +284,7 @@ def test_neg_remove_bin_with_incorrect_policy(self): try: self.as_connection.remove_bin(key, ["age"], {}, policy) - except ClientError as exception: + except e.ClientError as exception: assert exception.code == -1 def test_neg_remove_bin_with_no_parameters(self): @@ -298,7 +293,7 @@ def test_neg_remove_bin_with_no_parameters(self): """ with pytest.raises(TypeError) as typeError: self.as_connection.remove_bin() - assert "Required argument 'key' (pos 1) not found" in typeError.value + assert "Required argument 'key' (pos 1) not found" in str(typeError.value) def test_neg_remove_bin_with_policy_send_gen_eq_not_equal(self, put_data): """ @@ -321,7 +316,7 @@ def test_neg_remove_bin_with_policy_send_gen_eq_not_equal(self, put_data): try: self.as_connection.remove_bin(key, ["age"], meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 (key, meta, bins) = self.as_connection.get(key) @@ -352,7 +347,7 @@ def test_neg_remove_bin_with_policy_send_gen_GT_lesser(self, put_data): try: self.as_connection.remove_bin(key, ["age"], meta, policy) - except RecordGenerationError as exception: + except e.RecordGenerationError as exception: assert exception.code == 3 (key, meta, bins) = self.as_connection.get(key) @@ -374,12 +369,12 @@ def test_neg_remove_bin_with_incorrect_policy_value(self): try: self.as_connection.remove_bin(key, ["age"], {}, policy) - except ClientError as exception: + except e.ClientError as exception: assert exception.code == -1 @pytest.mark.parametrize("key, bin_for_removal, ex_code", [ - (('test', 'demo', 1), ["non-existent"], 0L), # non-existent bin - (('test', 'demo', "non-existent"), ["age"], 0L), # non-existent key + (('test', 'demo', 1), ["non-existent"], 0), # non-existent bin + (('test', 'demo', "non-existent"), ["age"], 0), # non-existent key ]) def test_neg_remove_bin_with_nonexistent_data(self, key, bin_for_removal, ex_code): """ @@ -387,7 +382,7 @@ def test_neg_remove_bin_with_nonexistent_data(self, key, bin_for_removal, ex_cod """ status = self.as_connection.remove_bin(key, bin_for_removal) - assert status == 0L + assert status == 0 def test_neg_remove_bin_with_extra_parameter(self): """ @@ -398,4 +393,4 @@ def test_neg_remove_bin_with_extra_parameter(self): with pytest.raises(TypeError) as typeError: self.as_connection.remove_bin(key, ["age"], {}, policy, "") - assert "remove_bin() takes at most 4 arguments (5 given)" in typeError.value + assert "remove_bin() takes at most 4 arguments (5 given)" in str(typeError.value) diff --git a/test/old_tests/conftest.py b/test/old_tests/conftest.py index b5810a15c..8c38ee842 100644 --- a/test/old_tests/conftest.py +++ b/test/old_tests/conftest.py @@ -1,5 +1,5 @@ import pytest -from test_base_class import TestBaseClass +from .test_base_class import TestBaseClass aerospike = pytest.importorskip("aerospike")