Re: [Freeipa-devel] [PATCHES] 0661-0672 Switch the test suite to pytest

2014-10-29 Thread Petr Viktorin

Please ignore the previous mail, I hit Send my mistake.

--
PetrĀ³

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


Re: [Freeipa-devel] [PATCHES] 0661-0672 Switch the test suite to pytest

2014-10-29 Thread Petr Viktorin

On 10/29/2014 01:22 PM, Tomas Babej wrote:


On 10/27/2014 04:38 PM, Petr Viktorin wrote:

On 10/15/2014 02:58 PM, Petr Viktorin wrote:

This almost completes the switch to pytest. There are two missing
things:
- the details of test results (--with-xunit) are not read correctly by
Jenkins. I have a theory I'm investigating here.
- the beakerlib integration is still not ready


I'll not be available for the rest of the week so I'm sending this
early, in case someone wants to take a look.


I've updated (and rearranged) the patches after some more testing.
Both points above are fixed. Individual plugins are broken out; some
would be nice to even release independently of IPA. (There is some
demand for the BeakerLib plugin; for that I'd only need to break the
dependency on ipa_log_manager.)


These depend on my patches 0656-0660.




Thanks for this effort!

 Patch 0656: tests: Use PEP8-compliant setup/teardown method names

There are some references to the old names in the test_ipapython and
test_install:

 [tbabej@thinkpad7 ipatests]$ git grep setUpClass
 [tbabej@thinkpad7 ipatests]$ git grep tearDownClass
 [tbabej@thinkpad7 ipatests]$ git grep setUp
 test_install/test_updates.py:def setUp(self):
 test_ipapython/test_cookie.py:def setUp(self):
 test_ipapython/test_cookie.py:def setUp(self):
 test_ipapython/test_cookie.py:def setUp(self):
 test_ipapython/test_dn.py:def setUp(self):
 test_ipapython/test_dn.py:def setUp(self):
 test_ipapython/test_dn.py:def setUp(self):
 test_ipapython/test_dn.py:def setUp(self):
 test_ipapython/test_dn.py:def setUp(self):
 [tbabej@thinkpad7 ipatests]$ git grep tearDown
 test_install/test_updates.py:def tearDown(self):


These are in unittest.testCase. It would be nice to convert those as 
well, but that's for a larger cleanup.



 Patch 0657: tests: Add configuration for pytest

Shouldn't we rather change the class names?


Ideally yes, but I don't think renaming most of our test classes would 
be worth the benefit.



 Patch 0658: ipatests.util.ClassChecker: Raise AttributeError in
get_subcls

ACK.

 Patch 0659: test_automount_plugin: Fix test ordering

ACK.

 PATCH 0660: Use setup_class/teardown_class in Declarative tests

 --- a/ipatests/test_ipaserver/test_changepw.py
 +++ b/ipatests/test_ipaserver/test_changepw.py
 @@ -33,8 +33,7 @@
  class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
  app_uri = '/ipa/session/change_password'

 -def setup(self):
 -super(test_changepw, self).setup()
 +def setup(cls):
  try:
  api.Command['user_add'](uid=testuser,
givenname=u'Test', sn=u'User')
  api.Command['passwd'](testuser, password=u'old_password')
 @@ -43,12 +42,11 @@ def setup(self):
  'Cannot set up test user: %s' % e
  )

 -def teardown(self):
 +def teardown(cls):
  try:
  api.Command['user_del']([testuser])
  except errors.NotFound:
  pass
 -super(test_changepw, self).teardown()

The setup/teardown methods are not classmethods, so the name of the
first argument should remain "self".


Oops, thanks for the catch!


 PATCH 0661: dogtag plugin: Don't use doctest syntax for non-doctest
examples

ACK.

 PATCH 0662: test_webui: Don't use __init__ for test classes

I don't think the following change will work:

 -def __init__(self, driver=None, config=None):
 +def setup(self, driver=None, config=None):
  self.request_timeout = 30
  self.driver = driver
  self.config = config
  if not config:
  self.load_config()
 +self.get_driver().maximize_window()
 +
 +def teardown(self):
 +self.driver.quit()

  def load_config(self):
  """
 @@ -161,20 +165,6 @@ def load_config(self):
  if 'type' not in c:
  c['type'] = DEFAULT_TYPE

 -def setup(self):
 -"""
 -Test setup
 -"""
 -if not self.driver:
 -self.driver = self.get_driver()
 -self.driver.maximize_window()
 -
 -def teardown(self):
 -"""
 -Test clean up
 -"""
 -self.driver.quit()


The setup(self) method used to set the self.driver attribute on the
class instance, now nothing sets it. The setup method should do:

 def setup(self, driver=None, config=None):
 self.request_timeout = 30
 self.driver = driver
 self.config = config
 if not config:
 self.load_config()
 if not self.driver:
 self.driver = self.get_driver()
 self.driver.maximize_window()

However, I would prefer having self.driver as a cac

Re: [Freeipa-devel] [PATCHES] 0661-0672 Switch the test suite to pytest

2014-10-29 Thread Tomas Babej

On 10/27/2014 04:38 PM, Petr Viktorin wrote:
> On 10/15/2014 02:58 PM, Petr Viktorin wrote:
>> This almost completes the switch to pytest. There are two missing
>> things:
>> - the details of test results (--with-xunit) are not read correctly by
>> Jenkins. I have a theory I'm investigating here.
>> - the beakerlib integration is still not ready
>>
>>
>> I'll not be available for the rest of the week so I'm sending this
>> early, in case someone wants to take a look.
>
> I've updated (and rearranged) the patches after some more testing.
> Both points above are fixed. Individual plugins are broken out; some
> would be nice to even release independently of IPA. (There is some
> demand for the BeakerLib plugin; for that I'd only need to break the
> dependency on ipa_log_manager.)
>
>
> These depend on my patches 0656-0660.
>
>
>
> ___
> Freeipa-devel mailing list
> Freeipa-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/freeipa-devel

Thanks for this effort!

 Patch 0656: tests: Use PEP8-compliant setup/teardown method names

There are some references to the old names in the test_ipapython and
test_install:

[tbabej@thinkpad7 ipatests]$ git grep setUpClass
[tbabej@thinkpad7 ipatests]$ git grep tearDownClass
[tbabej@thinkpad7 ipatests]$ git grep setUp
test_install/test_updates.py:def setUp(self):
test_ipapython/test_cookie.py:def setUp(self):
test_ipapython/test_cookie.py:def setUp(self):
test_ipapython/test_cookie.py:def setUp(self):
test_ipapython/test_dn.py:def setUp(self):
test_ipapython/test_dn.py:def setUp(self):
test_ipapython/test_dn.py:def setUp(self):
test_ipapython/test_dn.py:def setUp(self):
test_ipapython/test_dn.py:def setUp(self):
[tbabej@thinkpad7 ipatests]$ git grep tearDown
test_install/test_updates.py:def tearDown(self):


 Patch 0657: tests: Add configuration for pytest

Shouldn't we rather change the class names?

 Patch 0658: ipatests.util.ClassChecker: Raise AttributeError in
get_subcls

ACK.

 Patch 0659: test_automount_plugin: Fix test ordering

ACK.

 PATCH 0660: Use setup_class/teardown_class in Declarative tests

--- a/ipatests/test_ipaserver/test_changepw.py
+++ b/ipatests/test_ipaserver/test_changepw.py
@@ -33,8 +33,7 @@
 class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
 app_uri = '/ipa/session/change_password'
 
-def setup(self):
-super(test_changepw, self).setup()
+def setup(cls):
 try:
 api.Command['user_add'](uid=testuser,
givenname=u'Test', sn=u'User')
 api.Command['passwd'](testuser, password=u'old_password')
@@ -43,12 +42,11 @@ def setup(self):
 'Cannot set up test user: %s' % e
 )
 
-def teardown(self):
+def teardown(cls):
 try:
 api.Command['user_del']([testuser])
 except errors.NotFound:
 pass
-super(test_changepw, self).teardown()

The setup/teardown methods are not classmethods, so the name of the
first argument should remain "self".

 PATCH 0661: dogtag plugin: Don't use doctest syntax for non-doctest
examples

ACK.

 PATCH 0662: test_webui: Don't use __init__ for test classes
 
I don't think the following change will work:

-def __init__(self, driver=None, config=None):
+def setup(self, driver=None, config=None):
 self.request_timeout = 30
 self.driver = driver
 self.config = config
 if not config:
 self.load_config()
+self.get_driver().maximize_window()
+
+def teardown(self):
+self.driver.quit()
 
 def load_config(self):
 """
@@ -161,20 +165,6 @@ def load_config(self):
 if 'type' not in c:
 c['type'] = DEFAULT_TYPE
 
-def setup(self):
-"""
-Test setup
-"""
-if not self.driver:
-self.driver = self.get_driver()
-self.driver.maximize_window()
-
-def teardown(self):
-"""
-Test clean up
-"""
-self.driver.quit()


The setup(self) method used to set the self.driver attribute on the
class instance, now nothing sets it. The setup method should do:

def setup(self, driver=None, config=None):
self.request_timeout = 30
self.driver = driver
self.config = config
if not config:
self.load_config()
if not self.driver:
self.driver = self.get_driver()
self.driver.maximize_window()

However, I would prefer having self.driver as a cached property.

 PATCH 0663: test_ipapython: Use functions instead of classes in
test generators

ACK.

 PATCH 0664: Configure 

Re: [Freeipa-devel] [PATCHES] 0661-0672 Switch the test suite to pytest

2014-10-27 Thread Petr Viktorin

On 10/15/2014 02:58 PM, Petr Viktorin wrote:

This almost completes the switch to pytest. There are two missing things:
- the details of test results (--with-xunit) are not read correctly by
Jenkins. I have a theory I'm investigating here.
- the beakerlib integration is still not ready


I'll not be available for the rest of the week so I'm sending this
early, in case someone wants to take a look.


I've updated (and rearranged) the patches after some more testing. Both 
points above are fixed. Individual plugins are broken out; some would be 
nice to even release independently of IPA. (There is some demand for the 
BeakerLib plugin; for that I'd only need to break the dependency on 
ipa_log_manager.)



These depend on my patches 0656-0660.

--
PetrĀ³

From 853f5379eea919bee6dea03889beb8d4cab14075 Mon Sep 17 00:00:00 2001
From: Petr Viktorin 
Date: Thu, 9 Oct 2014 17:02:25 +0200
Subject: [PATCH] dogtag plugin: Don't use doctest syntax for non-doctest
 examples

https://fedorahosted.org/freeipa/ticket/4610
---
 ipaserver/plugins/dogtag.py | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/ipaserver/plugins/dogtag.py b/ipaserver/plugins/dogtag.py
index 0e141a45c290b84d65b15b8c2c638577a3a39363..4576c9113b1501f9ab32aef16f8be761e92a9806 100644
--- a/ipaserver/plugins/dogtag.py
+++ b/ipaserver/plugins/dogtag.py
@@ -163,16 +163,16 @@
 1. Reading a serial number from CMS requires conversion from hexadecimal
by converting it into a Python int or long object, use the int constructor:
 
-   >>> serial_number = int(serial_number, 16)
+serial_number = int(serial_number, 16)
 
 2. Big integers passed to XMLRPC must be decimal unicode strings
 
-   >>> unicode(serial_number)
+   unicode(serial_number)
 
 3. Big integers received from XMLRPC must be converted back to int or long
objects from the decimal string representation.
 
-   >>> serial_number = int(serial_number)
+   serial_number = int(serial_number)
 
 Xpath pattern matching on node names:
 -
@@ -202,7 +202,7 @@
 solve the chapter problem above is by using a predicate which says if the node
 name begins with 'chapter' it's a match. Here is how you can do that.
 
->>> doc.xpath("//book/*[starts-with(name(), 'chapter')]/section[2]")
+doc.xpath("//book/*[starts-with(name(), 'chapter')]/section[2]")
 
 The built-in starts-with() returns true if its first argument starts with its
 second argument. Thus the example above says if the node name of the second
@@ -219,10 +219,10 @@
 EXSLT regular expression match() function on the node name. Here is how this is
 done:
 
->>> regexpNS = "http://exslt.org/regular-expressions";
->>> find = etree.XPath("//book/*[re:match(name(), '^chapter(_\d+)$')]/section[2]",
-...namespaces={'re':regexpNS}
->>> find(doc)
+regexpNS = "http://exslt.org/regular-expressions";
+find = etree.XPath("//book/*[re:match(name(), '^chapter(_\d+)$')]/section[2]",
+   namespaces={'re':regexpNS}
+find(doc)
 
 What is happening here is that etree.XPath() has returned us an evaluator
 function which we bind to the name 'find'. We've passed it a set of namespaces
-- 
2.1.0

From ee846826561ea598aeb5b54cd56397151fdd2473 Mon Sep 17 00:00:00 2001
From: Petr Viktorin 
Date: Fri, 10 Oct 2014 16:04:05 +0200
Subject: [PATCH] test_webui: Don't use __init__ for test classes

https://fedorahosted.org/freeipa/ticket/4610
---
 ipatests/test_webui/test_automember.py |  1 +
 ipatests/test_webui/test_cert.py   |  4 ++--
 ipatests/test_webui/test_dns.py|  4 ++--
 ipatests/test_webui/test_host.py   |  4 ++--
 ipatests/test_webui/test_hostgroup.py  |  6 --
 ipatests/test_webui/test_netgroup.py   |  3 ++-
 ipatests/test_webui/test_trust.py  |  8 
 ipatests/test_webui/ui_driver.py   | 20 +---
 8 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/ipatests/test_webui/test_automember.py b/ipatests/test_webui/test_automember.py
index 34710cb6e84ce76ea1930f4fbd17fd1331564b69..0378812ccf7cd9d4415e4ff40009eb2fd509286d 100644
--- a/ipatests/test_webui/test_automember.py
+++ b/ipatests/test_webui/test_automember.py
@@ -93,6 +93,7 @@ def test_rebuild_membership_hosts(self):
 self.init_app()
 
 host_util = host_tasks()
+host_util.setup(self.driver, self.config)
 domain = self.config.get('ipa_domain')
 host1 = 'web1.%s' % domain
 host2 = 'web2.%s' % domain
diff --git a/ipatests/test_webui/test_cert.py b/ipatests/test_webui/test_cert.py
index 979a51e84437e7c8dae8de5412095c1e719e7db4..ec704eb118e94aeda2ffcb75cb1d1814b97791c3 100644
--- a/ipatests/test_webui/test_cert.py
+++ b/ipatests/test_webui/test_cert.py
@@ -29,8 +29,8 @@
 
 class test_cert(UI_driver):
 
-def __init__(self, *args, **kwargs):
-super(test_cert, self).__init__(args, kwargs)
+def setup(self, *args, **kwargs):
+