diff options
author | Alois Mahdal <amahdal@redhat.com> | 2014-06-24 17:41:33 +0200 |
---|---|---|
committer | Alois Mahdal <amahdal@redhat.com> | 2014-06-26 10:06:48 +0200 |
commit | c54f67f2c51ad24e288c3b44960add2d45f89c79 (patch) | |
tree | 2c356c15bee713e5953511206a3a749cadc9142e /src | |
parent | 755e44de4cfa5d8b1a4533525270d5efb161b7d3 (diff) | |
download | openlmi-providers-c54f67f2c51ad24e288c3b44960add2d45f89c79.tar.gz openlmi-providers-c54f67f2c51ad24e288c3b44960add2d45f89c79.tar.xz openlmi-providers-c54f67f2c51ad24e288c3b44960add2d45f89c79.zip |
PEP8 and PyFlakes cleanup: src/account/test
Diffstat (limited to 'src')
-rw-r--r-- | src/account/test/TestAccount.py | 30 | ||||
-rw-r--r-- | src/account/test/TestAccountInvalidEtc.py | 20 | ||||
-rw-r--r-- | src/account/test/TestAccountRaceConditions.py | 20 | ||||
-rw-r--r-- | src/account/test/TestGroup.py | 16 | ||||
-rw-r--r-- | src/account/test/TestIndicationEventStream.py | 1 | ||||
-rw-r--r-- | src/account/test/TestIndications.py | 50 | ||||
-rw-r--r-- | src/account/test/TestMemberOfGroup.py | 22 | ||||
-rw-r--r-- | src/account/test/TestService.py | 17 | ||||
-rw-r--r-- | src/account/test/methods.py | 7 |
9 files changed, 111 insertions, 72 deletions
diff --git a/src/account/test/TestAccount.py b/src/account/test/TestAccount.py index 05d0071..a40c86a 100644 --- a/src/account/test/TestAccount.py +++ b/src/account/test/TestAccount.py @@ -13,15 +13,15 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Authors: Roman Rakus <rrakus@redhat.com> # import common -from methods import * +import methods from lmi.shell import LMIInstance -import subprocess + class TestAccount(common.AccountBase): """ @@ -56,8 +56,10 @@ class TestAccount(common.AccountBase): common.UserOps.clean_account(self.user_name) lams = self.ns.LMI_AccountManagementService.first_instance() self.assertIsInstance(lams, LMIInstance) - (retval, rparam, errorstr) = lams.CreateAccount({'Name': self.user_name, - 'System': self.system_iname}) + (retval, rparam, errorstr) = lams.CreateAccount({ + 'Name': self.user_name, + 'System': self.system_iname + }) self.assertEqual(retval, 0) # The user now should be created, check it self.assertTrue(common.UserOps.is_user(self.user_name)) @@ -86,15 +88,23 @@ class TestAccount(common.AccountBase): inst.ElementName = "GECOS" (retval, rparam, errorstr) = inst.push() self.assertEqual(retval, 0) - self.assertEqual(field_in_passwd(self.user_name, 4), "GECOS") + self.assertEqual(methods.field_in_passwd(self.user_name, 4), + "GECOS") # login shell inst.LoginShell = "/modified" (retval, rparam, errorstr) = inst.push() self.assertEqual(retval, 0) - self.assertEqual(field_in_passwd(self.user_name, 6), "/modified") + self.assertEqual(methods.field_in_passwd(self.user_name, 6), + "/modified") # password - inst.UserPassword = ['$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1'] + inst.UserPassword = [ + '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Ez' + 'e.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1' + ] (retval, rparam, errorstr) = inst.push() self.assertEqual(retval, 0) - self.assertEqual(field_in_shadow(self.user_name, 1), - '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1') + shad = ( + '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Ez' + 'e.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1' + ) + self.assertEqual(methods.field_in_shadow(self.user_name, 1), shad) diff --git a/src/account/test/TestAccountInvalidEtc.py b/src/account/test/TestAccountInvalidEtc.py index 01c7ec9..df8730e 100644 --- a/src/account/test/TestAccountInvalidEtc.py +++ b/src/account/test/TestAccountInvalidEtc.py @@ -25,9 +25,9 @@ from common import AccountBase from lmi.shell import LMIInstance -## ......................................................................... ## -## Helper functions -## ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ## +# ......................................................................... # +# Helper functions +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # def gen_cripple(*args): """ @@ -46,9 +46,9 @@ def gen_cripple(*args): setattr(TestAccountInvalidEtc, meth_name, _new_cripple_test) -## ......................................................................... ## -## Test data (later "converted" to test methods) -## ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ## +# ......................................................................... # +# Test data (later "converted" to test methods) +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # class PasswdCrippler(lmi.test.util.BaseCrippler): """ @@ -410,9 +410,9 @@ class PasswdCrippler(lmi.test.util.BaseCrippler): return cases -## ......................................................................... ## -## Actual test -## ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ## +# ......................................................................... # +# Actual test +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # @mark_dangerous class TestAccountInvalidEtc(AccountBase): @@ -444,7 +444,7 @@ class TestAccountInvalidEtc(AccountBase): self.assertIsNotNone(self.inst.properties_dict()[attr]) ## -## Here test methods are generated from data in PasswdCrippler instance, +# Here test methods are generated from data in PasswdCrippler instance, # crippler = PasswdCrippler() diff --git a/src/account/test/TestAccountRaceConditions.py b/src/account/test/TestAccountRaceConditions.py index 3523b96..69a8912 100644 --- a/src/account/test/TestAccountRaceConditions.py +++ b/src/account/test/TestAccountRaceConditions.py @@ -25,9 +25,9 @@ from pywbem import CIMError import threading -## ......................................................................... ## -## Helper methods -## ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ## +# ......................................................................... # +# Helper methods +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # def perform_attempts(tcls, names, args): """ @@ -53,9 +53,9 @@ def perform_attempts(tcls, names, args): return [t.result for t in threads] -## ......................................................................... ## -## Threading helper classes -## ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ## +# ......................................................................... # +# Threading helper classes +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # class AccountActionAttempt(threading.Thread): """ @@ -72,7 +72,7 @@ class AccountActionAttempt(threading.Thread): def _chkargs(self, keys): """Check keys in args; raise sensible message""" for key in keys: - if not key in self.args: + if key not in self.args: raise ValueError("%s needs %s passed in args" % (self.__class__.__name__, key)) @@ -115,9 +115,9 @@ class DeletionAttempt(AccountActionAttempt): account.DeleteUser() -## ......................................................................... ## -## Actual test -## ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ## +# ......................................................................... # +# Actual test +# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' # class TestAccountRaceConditions(common.AccountBase): diff --git a/src/account/test/TestGroup.py b/src/account/test/TestGroup.py index 50450c0..1ef3392 100644 --- a/src/account/test/TestGroup.py +++ b/src/account/test/TestGroup.py @@ -13,15 +13,16 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Authors: Roman Rakus <rrakus@redhat.com> # import common -from methods import * +import methods from lmi.shell import LMIInstance + class TestGroup(common.AccountBase): """ Class for testing LMI_Group class @@ -54,11 +55,14 @@ class TestGroup(common.AccountBase): common.UserOps.clean_group(self.group_name) lams = self.ns.LMI_AccountManagementService.first_instance() self.assertIsInstance(lams, LMIInstance) - (retval, rparam, errorstr) = lams.CreateGroup({'Name': self.group_name, - 'System': self.system_iname}) + (retval, rparam, errorstr) = lams.CreateGroup({ + 'Name': self.group_name, + 'System': self.system_iname + }) self.assertEqual(retval, 0) # The group now should be created, check it - self.assertEqual(field_in_group(self.group_name, 0), self.group_name) + self.assertEqual(methods.field_in_group(self.group_name, 0), + self.group_name) def test_delete_group(self): """ @@ -71,4 +75,4 @@ class TestGroup(common.AccountBase): r = inst.delete() self.assertTrue(r) # check if it was really deleted - self.assertIsNone(field_in_group(self.group_name, 0)) + self.assertIsNone(methods.field_in_group(self.group_name, 0)) diff --git a/src/account/test/TestIndicationEventStream.py b/src/account/test/TestIndicationEventStream.py index e5928fe..4281995 100644 --- a/src/account/test/TestIndicationEventStream.py +++ b/src/account/test/TestIndicationEventStream.py @@ -168,4 +168,3 @@ class TestIndicationEventStream(IndicationStreamTestCase): (2, 2, 2, 4), ] self.check_numbased(variations, items) - diff --git a/src/account/test/TestIndications.py b/src/account/test/TestIndications.py index 00f4dd0..0a14405 100644 --- a/src/account/test/TestIndications.py +++ b/src/account/test/TestIndications.py @@ -12,15 +12,16 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Authors: Roman Rakus <rrakus@redhat.com> # -import common -from methods import * import time +import common + + class TestIndications(common.AccountBase): """ Class for testing LMI_Account indications @@ -32,9 +33,11 @@ class TestIndications(common.AccountBase): Account: Test good indication filter """ filter_name = "test_good_filter_%d" % (time.time() * 1000000) - sub = self.subscribe(filter_name, "select * from LMI_AccountInstanceCreationIndication where SourceInstance isa LMI_Account") + q = ("select * from LMI_AccountInstanceCreationIndication" + " where SourceInstance isa LMI_Account") + sub = self.subscribe(filter_name, q) self.assertIsNotNone(sub) - self.unsubscribe(sub); + self.unsubscribe(sub) def test_check_bad_filter(self): """ @@ -48,14 +51,17 @@ class TestIndications(common.AccountBase): """ common.UserOps.create_group(self.group_name) filter_name = "test_delete_group_%d" % (time.time() * 1000000) - sub = self.subscribe(filter_name, "select * from LMI_AccountInstanceDeletionIndication where SourceInstance isa LMI_Group") + q = ("select * from LMI_AccountInstanceDeletionIndication" + " where SourceInstance isa LMI_Group") + sub = self.subscribe(filter_name, q) common.UserOps.clean_group(self.group_name) indication = self.get_indication(10) - self.assertEqual(indication.classname, "LMI_AccountInstanceDeletionIndication") + self.assertEqual(indication.classname, + "LMI_AccountInstanceDeletionIndication") self.assertIn("SourceInstance", indication.keys()) self.assertTrue(indication["SourceInstance"] is not None) self.assertEqual(indication["SourceInstance"]["Name"], self.group_name) - self.unsubscribe(sub); + self.unsubscribe(sub) def test_group_creation_indication(self): """ @@ -63,15 +69,18 @@ class TestIndications(common.AccountBase): """ common.UserOps.clean_group(self.group_name) filter_name = "test_create_group_%d" % (time.time() * 1000000) - sub = self.subscribe(filter_name, "select * from LMI_AccountInstanceCreationIndication where SourceInstance isa LMI_Group") + q = ("select * from LMI_AccountInstanceCreationIndication" + " where SourceInstance isa LMI_Group") + sub = self.subscribe(filter_name, q) common.UserOps.create_group(self.group_name) indication = self.get_indication(10) - self.assertEqual(indication.classname, "LMI_AccountInstanceCreationIndication") + self.assertEqual(indication.classname, + "LMI_AccountInstanceCreationIndication") self.assertIn("SourceInstance", indication.keys()) self.assertTrue(indication["SourceInstance"] is not None) self.assertEqual(indication["SourceInstance"]["Name"], self.group_name) common.UserOps.clean_group(self.group_name) - self.unsubscribe(sub); + self.unsubscribe(sub) def test_account_deletion_indication(self): """ @@ -79,14 +88,17 @@ class TestIndications(common.AccountBase): """ common.UserOps.create_account(self.user_name) filter_name = "test_delete_account_%d" % (time.time() * 1000000) - sub = self.subscribe(filter_name, "select * from LMI_AccountInstanceDeletionIndication where SourceInstance isa LMI_Account") + q = ("select * from LMI_AccountInstanceDeletionIndication" + " where SourceInstance isa LMI_Account") + sub = self.subscribe(filter_name, q) common.UserOps.clean_account(self.user_name) indication = self.get_indication(10) - self.assertEqual(indication.classname, "LMI_AccountInstanceDeletionIndication") + self.assertEqual(indication.classname, + "LMI_AccountInstanceDeletionIndication") self.assertIn("SourceInstance", indication.keys()) self.assertTrue(indication["SourceInstance"] is not None) self.assertEqual(indication["SourceInstance"]["Name"], self.user_name) - self.unsubscribe(sub); + self.unsubscribe(sub) def test_account_creation_indication(self): """ @@ -94,13 +106,15 @@ class TestIndications(common.AccountBase): """ common.UserOps.clean_account(self.user_name) filter_name = "test_create_account_%d" % (time.time() * 1000000) - sub = self.subscribe(filter_name, "select * from LMI_AccountInstanceCreationIndication where SourceInstance isa LMI_Account") + q = ("select * from LMI_AccountInstanceCreationIndication" + " where SourceInstance isa LMI_Account") + sub = self.subscribe(filter_name, q) common.UserOps.create_account(self.user_name) indication = self.get_indication(10) - self.assertEqual(indication.classname, "LMI_AccountInstanceCreationIndication") + self.assertEqual(indication.classname, + "LMI_AccountInstanceCreationIndication") self.assertIn("SourceInstance", indication.keys()) self.assertTrue(indication["SourceInstance"] is not None) self.assertEqual(indication["SourceInstance"]["Name"], self.user_name) common.UserOps.clean_account(self.user_name) - self.unsubscribe(sub); - + self.unsubscribe(sub) diff --git a/src/account/test/TestMemberOfGroup.py b/src/account/test/TestMemberOfGroup.py index 40ff33c..fa5d8c3 100644 --- a/src/account/test/TestMemberOfGroup.py +++ b/src/account/test/TestMemberOfGroup.py @@ -13,16 +13,16 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Authors: Roman Rakus <rrakus@redhat.com> # import common -from methods import * from lmi.shell import LMIInstance from lmi.shell import LMIInstanceName + class TestMemberOfGroup(common.AccountBase): """ Class for testing LMI_MemberOfGroup class @@ -39,14 +39,16 @@ class TestMemberOfGroup(common.AccountBase): common.UserOps.create_account(self.user_name) common.UserOps.create_group(self.group_name) user = self.ns.LMI_Account.first_instance({"Name": self.user_name}) - group = self.ns.LMI_Group.first_instance_name({"Name": self.group_name}) + group = self.ns.LMI_Group.first_instance_name({ + "Name": self.group_name}) self.assertIsInstance(user, LMIInstance) self.assertIsInstance(group, LMIInstanceName) - identity = user.first_associator_name(ResultClass = 'LMI_Identity') + identity = user.first_associator_name(ResultClass='LMI_Identity') self.assertIsInstance(identity, LMIInstanceName) - tocreate = self.ns.LMI_MemberOfGroup.create_instance( - { 'Collection' : group, - 'Member' : identity }) + tocreate = self.ns.LMI_MemberOfGroup.create_instance({ + 'Collection': group, + 'Member': identity + }) self.assertIsInstance(tocreate, LMIInstance) def test_remove_user_from_group(self): @@ -71,9 +73,11 @@ class TestMemberOfGroup(common.AccountBase): common.UserOps.add_user_to_group(self.user_name, self.group_name) user = self.ns.LMI_Account.first_instance({"Name": self.user_name}) self.assertIsInstance(user, LMIInstance) - ident = self.ns.LMI_Identity.first_instance({"InstanceID": "LMI:UID:%s" % user.UserID}) + ident = self.ns.LMI_Identity.first_instance({ + "InstanceID": "LMI:UID:%s" % user.UserID + }) self.assertIsInstance(ident, LMIInstance) - insts = ident.associators(AssocClass = 'LMI_MemberOfGroup') + insts = ident.associators(AssocClass='LMI_MemberOfGroup') self.assertEqual(len(insts), 2) found_user = False found_group = False diff --git a/src/account/test/TestService.py b/src/account/test/TestService.py index 69a5054..136cb6f 100644 --- a/src/account/test/TestService.py +++ b/src/account/test/TestService.py @@ -13,15 +13,17 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Authors: Roman Rakus <rrakus@redhat.com> # import common -from methods import * +from methods import field_in_group +from methods import field_in_passwd +from methods import field_in_shadow from lmi.shell import LMIInstance -from lmi.shell import LMIInstanceName + class TestService(common.AccountBase): """ @@ -47,7 +49,8 @@ class TestService(common.AccountBase): gid = 0 gecos = "test create account gecos" home_dir = "/test/home" - password = '$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Eze.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1' + password = ('$6$9Ky8vI6f$ipRcdc7rgMrtDh.sWOaRSoBck2cLz4eUom8Ez' + 'e.NaY2DoMmNimuFBrXpJjlPCjMoeFTYC.FdZwj488JZcohyw1') uid = 777 (rc, out, errorstr) = lams.CreateAccount({ 'Name': self.user_name, @@ -72,10 +75,10 @@ class TestService(common.AccountBase): for identity in idents: if identity.InstanceID.find("UID") != -1: # user identity - self.assertEqual(identity.InstanceID, "LMI:UID:%d" %uid) + self.assertEqual(identity.InstanceID, "LMI:UID:%d" % uid) else: # group identity - self.assertEqual(identity.InstanceID, "LMI:GID:%d" %gid) + self.assertEqual(identity.InstanceID, "LMI:GID:%d" % gid) # check with system info self.assertEqual(field_in_passwd(self.user_name, 2), str(uid)) @@ -106,7 +109,7 @@ class TestService(common.AccountBase): self.assertEqual(rc, 0) self.assertEqual(group.Name, self.group_name) for identity in idents: - self.assertEqual(identity.InstanceID, "LMI:GID:%d" %gid) + self.assertEqual(identity.InstanceID, "LMI:GID:%d" % gid) self.assertEqual(field_in_group(self.group_name, 2), str(gid)) common.UserOps.clean_group(self.group_name) diff --git a/src/account/test/methods.py b/src/account/test/methods.py index ce05e7e..733c003 100644 --- a/src/account/test/methods.py +++ b/src/account/test/methods.py @@ -13,13 +13,14 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Authors: Roman Rakus <rrakus@redhat.com> # import random + def field_in_passwd(username, number): """ Return numberth field in /etc/passwd for given username @@ -28,6 +29,7 @@ def field_in_passwd(username, number): if line.startswith(username): return line.split(":")[number].strip() + def field_in_shadow(username, number): """ Return numberth field in /etc/shadow for given username @@ -36,6 +38,7 @@ def field_in_shadow(username, number): if line.startswith(username): return line.split(":")[number].strip() + def field_in_group(groupname, number): """ Return numberth field in /etc/group for given groupname @@ -44,6 +47,7 @@ def field_in_group(groupname, number): if line.startswith(groupname): return line.split(":")[number].strip() + def random_shell(): """ Make up a funny shell @@ -61,6 +65,7 @@ def random_shell(): "/bin/wash", ]) + def field_is_unique(fname, records): """ True if the field in `records` has unique values. |