Repository: ManageIQ/integration_tests

Issue:
verify mgmt system details



Discussion:

Resolving patch:
diff --git a/conftest.py b/conftest.py
--- a/conftest.py
+++ b/conftest.py
@@ -1,6 +1,13 @@
+'''
+Top-level conftest.py does a couple of things:
+
+1) Add cfme_pages repo to the sys.path automatically
+2) Load a number of plugins and fixtures automatically
+'''
 import pytest
 
 def add_cfme_pages_to_path():
+    '''Automatically add the cfme_pages repo to the sys.path'''
     try:
         import pages.page
     except ImportError:
@@ -28,5 +35,5 @@ def add_cfme_pages_to_path():
 add_cfme_pages_to_path()
 
 pytest_plugins = 'plugin.highlight', 'fixtures.cfmedata', 'fixtures.cfmedb', \
-        'fixtures.server_roles'
+        'fixtures.server_roles', 'fixtures.soap'
 


Test patch:
diff --git a/tests/common/__init__.py b/common/__init__.py
similarity index 100%
rename from tests/common/__init__.py
rename to common/__init__.py
diff --git a/tests/common/mgmt_system.py b/common/mgmt_system.py
similarity index 100%
rename from tests/common/mgmt_system.py
rename to common/mgmt_system.py
diff --git a/tests/soap_api/conftest.py b/fixtures/soap.py
similarity index 69%
rename from tests/soap_api/conftest.py
rename to fixtures/soap.py
--- a/tests/soap_api/conftest.py
+++ b/fixtures/soap.py
@@ -3,15 +3,13 @@
 
 @author: dgao
 '''
-
 import pytest
 from soap_api.soap_base import SoapClient
 
-@pytest.fixture(scope='module') # IGNORE:E1101
+@pytest.fixture(scope='module')  # IGNORE:E1101
 def soap_base(mozwebqa):
     return SoapClient(mozwebqa)
 
-@pytest.fixture(scope='module') # IGNORE:E1101
+@pytest.fixture(scope='module')  # IGNORE:E1101
 def soap_client(soap_base):
     return soap_base.client
-
diff --git a/tests/soap_api/__init__.py b/soap_api/__init__.py
similarity index 100%
rename from tests/soap_api/__init__.py
rename to soap_api/__init__.py
diff --git a/tests/soap_api/soap_base.py b/soap_api/soap_base.py
similarity index 100%
rename from tests/soap_api/soap_base.py
rename to soap_api/soap_base.py
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,6 +3,7 @@
 
 @author: bcrochet
 """
+# pylint: disable=E1101
 import logging
 import time
 
@@ -13,8 +14,16 @@
 
 logger = logging.getLogger(__name__)
 
+@pytest.fixture  # IGNORE:E1101
+def random_uuid_as_string():
+    '''Creates a random uuid and returns is as a string'''
+    import uuid
+    return str(uuid.uuid4())
+
 @pytest.fixture  # IGNORE:E1101
 def home_page_logged_in(mozwebqa):
+    '''Logs in to the application with default credentials and returns the 
+    home page'''
     from pages.login import LoginPage
     login_pg = LoginPage(mozwebqa)
     login_pg.go_to_login_page()
@@ -24,64 +33,85 @@ def home_page_logged_in(mozwebqa):
 
 @pytest.fixture  # IGNORE:E1101
 def setup_mgmt_systems(home_page_logged_in, cfme_data):
+    '''Adds all management systems listed in cfme_data.yaml'''
     # Does mgmt system exist
     for provider in cfme_data.data['management_systems']:
-        ms_pg = home_page_logged_in.header.site_navigation_menu('Infrastructure').sub_navigation_menu('Management Systems').click()
+        ms_pg = home_page_logged_in.header.site_navigation_menu(
+                'Infrastructure').sub_navigation_menu(
+                        'Management Systems').click()
         mgmt_data = cfme_data.data['management_systems'][provider]
         mgmt_cred = ms_pg.testsetup.credentials[mgmt_data['credentials']]
         mgmt_added = False
-        if (len(ms_pg.quadicon_region.quadicons) == 0) or not ms_pg.quadicon_region.does_quadicon_exist(mgmt_data['name']):
+        if (len(ms_pg.quadicon_region.quadicons) == 0) \
+                or not ms_pg.quadicon_region.does_quadicon_exist(
+                        mgmt_data['name']):
             # add it
             add_pg = ms_pg.click_on_add_new_management_system()
-            add_pg.new_management_system_fill_data(mgmt_data['name'],mgmt_data['hostname'],mgmt_data['ipaddress'], mgmt_cred['username'], mgmt_cred['password'])
+            add_pg.new_management_system_fill_data(
+                    mgmt_data['name'],
+                    mgmt_data['hostname'],
+                    mgmt_data['ipaddress'],
+                    mgmt_cred['username'],
+                    mgmt_cred['password'])
             if mgmt_data['type'] == 'virtualcenter':
                 add_pg.select_management_system_type('VMware vCenter')
             elif mgmt_data['type'] == 'rhevm':
-                add_pg.select_management_system_type('Red Hat Enterprise Virtualization Manager')
+                add_pg.select_management_system_type(
+                        'Red Hat Enterprise Virtualization Manager')
             elif mgmt_data['type'] == 'ec2':
                 add_pg.select_management_system_type('Amazon EC2')
             else:
                 add_pg.select_management_system_type(mgmt_data['type'])
             ms_pg = add_pg.click_on_add()
-            Assert.true(ms_pg.flash.message == 'Management System "%s" was saved' % mgmt_data['name'])
+            Assert.equal(ms_pg.flash.message,
+                    'Management System "%s" was saved' % mgmt_data['name'],
+                    'Flash message did not match')
             mgmt_added = True
 
             # wait for the quadicon to show up
             sleep_time = 1
-            while not ms_pg.quadicon_region.does_quadicon_exist(mgmt_data['name']):
+            while not ms_pg.quadicon_region.does_quadicon_exist(
+                    mgmt_data['name']):
                 ms_pg.selenium.refresh()
                 time.sleep(sleep_time)
                 sleep_time *= 2
                 if sleep_time > 90:
-                    raise Exception('timeout reached for mgmt_system icon to show up')
+                    raise Exception(
+                            'timeout reached for mgmt_system icon to show up')
 
         # Are the credentials valid?
-        mgmt_quadicon = ms_pg.quadicon_region.get_quadicon_by_title(mgmt_data['name'])
+        mgmt_quadicon = ms_pg.quadicon_region.get_quadicon_by_title(
+                mgmt_data['name'])
         valid_creds = mgmt_quadicon.valid_credentials
         if mgmt_added and not valid_creds:
             sleep_time = 1
             while not valid_creds:
                 ms_pg.selenium.refresh()
                 time.sleep(sleep_time)
-                mgmt_quadicon = ms_pg.quadicon_region.get_quadicon_by_title(mgmt_data['name'])
+                mgmt_quadicon = ms_pg.quadicon_region.get_quadicon_by_title(
+                        mgmt_data['name'])
                 valid_creds = mgmt_quadicon.valid_credentials
                 sleep_time *= 2
                 if sleep_time > 90:
-                    raise Exception('timeout reached for valid mgmt_system credentials')
+                    raise Exception(
+                            'timeout reached for valid mgmt_system credentials')
         elif not mgmt_quadicon.valid_credentials:
             # update them
             ms_pg.select_management_system(mgmt_data['name'])
-            Assert.true(len(ms_pg.quadicon_region.selected) == 1, 'More than one quadicon was selected')
+            Assert.equal(len(ms_pg.quadicon_region.selected), 1,
+                    'More than one quadicon was selected')
             mse_pg = ms_pg.click_on_edit_management_systems()
             mse_pg.edit_management_system(mgmt_data)
 
 @pytest.fixture
 def maximized(mozwebqa):
+    '''Maximizes the browser window'''
     mozwebqa.selenium.maximize_window()
     return True
 
 @pytest.fixture(scope='module')  # IGNORE:E1101
 def mgmt_sys_api_clients(mozwebqa, cfme_data):
+    '''Returns a list of management system api clients'''
     clients = {}
     for sys_name, mgmt_sys in cfme_data.data['management_systems'].items():
         cred = mgmt_sys['credentials'].strip()
diff --git a/tests/soap_api/test_connectivity.py b/tests/soap/test_connectivity.py
similarity index 100%
rename from tests/soap_api/test_connectivity.py
rename to tests/soap/test_connectivity.py
diff --git a/tests/soap_api/test_smoke.py b/tests/soap/test_smoke.py
similarity index 100%
rename from tests/soap_api/test_smoke.py
rename to tests/soap/test_smoke.py
diff --git a/tests/ui/infrastructure/conftest.py b/tests/ui/infrastructure/conftest.py
new file mode 100644
--- /dev/null
+++ b/tests/ui/infrastructure/conftest.py
@@ -0,0 +1,14 @@
+'''
+Created on Jun 7, 2013
+
+@author: bcrochet
+'''
+# -*- coding: utf-8 -*-
+import pytest
+
+@pytest.fixture  # IGNORE:E1101
+def mgmtsys_page(home_page_logged_in):
+    return home_page_logged_in.header.site_navigation_menu(
+            "Infrastructure").sub_navigation_menu(
+                    "Management Systems").click()
+
diff --git a/tests/ui/infrastructure/test_management_systems.py b/tests/ui/infrastructure/test_management_systems.py
--- a/tests/ui/infrastructure/test_management_systems.py
+++ b/tests/ui/infrastructure/test_management_systems.py
@@ -1,78 +1,176 @@
+'''
+@author: bcrochet
+'''
 # -*- coding: utf-8 -*-
+# pylint: disable=E1101
+# pylint: disable=W0621
 
 import pytest
 import time
 from unittestzero import Assert
 
-@pytest.fixture(scope="module",  # IGNORE:E1101
-                params=["vsphere5"])
-def management_system(request, cfme_data, mgmtsys_page):
+CURRENT_PAGE_NOT_MATCHED = 'Current page not what was expected'
+FLASH_MESSAGE_NOT_MATCHED = 'Flash message did not match expected value'
+DETAIL_NOT_MATCHED_TEMPLATE = '%s did not match'
+
+@pytest.fixture(params=['vsphere5', 'rhevm31'])  # IGNORE:E1101
+def management_system_data(request, cfme_data, mgmtsys_page):
+    '''Returns management system data from cfme_data'''
     param = request.param
-    def fin():
-        # Go back to the Management Systems list
-        ms_pg = mgmtsys_page.header.site_navigation_menu("Infrastructure").sub_navigation_menu("Management Systems").click()
-        ms_pg.select_management_system(cfme_data.data["management_systems"][param]["name"])
-        ms_pg.click_on_remove_management_system()
-    request.addfinalizer(fin)
-    return cfme_data.data["management_systems"][param]
+    return cfme_data.data['management_systems'][param]
 
-@pytest.fixture  # IGNORE:E1101
-def mgmtsys_page(home_page_logged_in):
-    return home_page_logged_in.header.site_navigation_menu("Infrastructure").sub_navigation_menu("Management Systems").click()
+@pytest.fixture
+def management_system(request, mgmtsys_page, management_system_data):
+    '''Create a management system
+
+    Creates a management system based on the data from cfme_data.
+    Ideally, this fixture would clean up after itself, but currently 
+    the only way to do that is via the UI, and we lose the selenium session
+    before the finalizer gets an opportunity to run.
+
+    This fixture will modify the db directly in the near future'''
+    ms_pg = mgmtsys_page.header.site_navigation_menu(
+            'Infrastructure').sub_navigation_menu(
+                    'Management Systems').click()
+    msadd_pg = ms_pg.click_on_add_new_management_system()
+    ms_pg = msadd_pg.add_management_system(management_system_data)
+    # TODO: Finalizer doesn't actually work. The selenium session is 
+    #       killed prior to its running.
+    # def fin():
+    #     ms_pg = mgmtsys_page.header.site_navigation_menu(
+    #             "Infrastructure").sub_navigation_menu(
+    #                     "Management Systems").click()
+    #     ms_name = management_system_data[name_property]
+    #     ms_pg.wait_for_management_system_or_timeout(ms_name)
+    #     ms_pg.select_management_system(ms_name)
+    #     ms_pg.click_on_remove_management_system()
+    # request.addfinalizer(fin)
+    return management_system_data
 
 @pytest.fixture  # IGNORE:E1101
-def has_at_least_one_management_system(home_page_logged_in):
-    ms_pg = home_page_logged_in.header.site_navigation_menu("Infrastructure").sub_navigation_menu("Management Systems").click()
-    sleep_time = 1
-    while not len(ms_pg.quadicon_region.quadicons) > 0:
-        ms_pg.selenium.refresh()
-        time.sleep(sleep_time)
-        sleep_time *= 2
+def has_no_management_systems(db_session):
+    '''Clears all management systems from an applicance
 
-@pytest.mark.nondestructive  # IGNORE:E1101
-@pytest.mark.usefixtures("maximized")  # IGNORE:E1101
-class TestManagementSystems:
-    def test_discover_management_systems_starts(self, mozwebqa, mgmtsys_page, management_system):
-        ms_pg = mgmtsys_page
-        Assert.true(ms_pg.is_the_current_page)
-        msd_pg = ms_pg.click_on_discover_management_systems()
-        Assert.true(msd_pg.is_the_current_page)
-        ms_pg = msd_pg.discover_systems(management_system["type"], management_system["discovery_range"]["start"], management_system["discovery_range"]["end"])
-        Assert.true(ms_pg.is_the_current_page)
-        Assert.true(ms_pg.flash.message == "Management System: Discovery successfully initiated")
+    This is a destructive fixture. It will clear all managements systems from
+    the current appliance.
+    '''
+    import db
+    session = db_session
+    session.query(db.ExtManagementSystem).delete()
+    session.commit()
 
-    def test_that_checks_flash_with_no_management_types_checked(self, mozwebqa, mgmtsys_page):
+@pytest.mark.usefixtures('maximized')  # IGNORE:E1101
+class TestManagementSystems:
+    @pytest.mark.nondestructive  # IGNORE:E1101 
+    def test_that_checks_flash_with_no_management_types_checked(self,
+            mgmtsys_page):
+        '''Tests that the flash message is correct when no management systems
+        are selected
+        '''
         ms_pg = mgmtsys_page
         Assert.true(ms_pg.is_the_current_page)
         msd_pg = ms_pg.click_on_discover_management_systems()
         msd_pg.click_on_start()
-        Assert.true(msd_pg.flash.message == "At least 1 item must be selected for discovery")
+        Assert.equal(msd_pg.flash.message,
+                'At least 1 item must be selected for discovery',
+                FLASH_MESSAGE_NOT_MATCHED)
 
-    def test_that_checks_flash_when_discovery_canceled(self, mozwebqa, mgmtsys_page):
+    @pytest.mark.nondestructive  # IGNORE:E1101
+    def test_that_checks_flash_when_discovery_cancelled(self, mgmtsys_page):
+        '''Tests that the flash message is correct when discovery is cancelled
+        '''
         ms_pg = mgmtsys_page
-        Assert.true(ms_pg.is_the_current_page)
+        Assert.true(ms_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
         msd_pg = ms_pg.click_on_discover_management_systems()
         ms_pg = msd_pg.click_on_cancel()
-        Assert.true(ms_pg.is_the_current_page)
-        Assert.true(ms_pg.flash.message == "Management System Discovery was cancelled by the user")
-        
-    # TODO: Change to use a fixture that uses Add Management System, instead of Discover.
-    # This will allow to more easily specify the start and end states
-    @pytest.mark.usefixtures("has_at_least_one_management_system") #IGNORE:E1101
-    def test_edit_management_system(self, mozwebqa, mgmtsys_page, management_system):
+        Assert.true(ms_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
+        Assert.equal(ms_pg.flash.message,
+                'Management System Discovery was cancelled by the user',
+                FLASH_MESSAGE_NOT_MATCHED)
+
+    @pytest.mark.nondestructive
+    def test_that_checks_flash_when_add_cancelled(self, mgmtsys_page):
+        '''Tests that the flash message is correct when add is cancelled'''
         ms_pg = mgmtsys_page
-        ms_pg.select_management_system(management_system["default_name"])
-        Assert.true(len(ms_pg.quadicon_region.selected) == 1, "More than one quadicon was selected")
+        Assert.true(ms_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
+        msa_pg = ms_pg.click_on_add_new_management_system()
+        ms_pg = msa_pg.click_on_cancel()
+        Assert.true(ms_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
+        Assert.equal(ms_pg.flash.message,
+                'Add of new Management System was cancelled by the user',
+                FLASH_MESSAGE_NOT_MATCHED)
+
+    @pytest.mark.usefixtures('has_no_management_systems')
+    def test_edit_management_system(self,
+            mgmtsys_page,
+            management_system,
+            random_uuid_as_string):
+        '''Tests that editing a management system shows the proper detail
+        after an edit
+        '''
+        ms_pg = mgmtsys_page
+        edit_name = random_uuid_as_string
+        ms_pg.select_management_system(management_system['name'])
+        Assert.equal(len(ms_pg.quadicon_region.selected), 1,
+                'More than one quadicon was selected')
         mse_pg = ms_pg.click_on_edit_management_systems()
+        management_system['edit_name'] = edit_name
         msdetail_pg = mse_pg.edit_management_system(management_system)
-        Assert.true(msdetail_pg.flash.message == "Management System \"%s\" was saved" % management_system["name"])
-        Assert.true(msdetail_pg.name == management_system["name"])
-        Assert.true(msdetail_pg.hostname == management_system["hostname"])
-        Assert.true(msdetail_pg.zone == management_system["server_zone"])
-        if "host_vnc_port" in management_system:
-            Assert.true(msdetail_pg.vnc_port_range == management_system["host_vnc_port"])
-        # if msdetail_pg.credentials_validity == "None":
-            # Try reloading the page once. If we get valid then, ok. Otherwise, failure
-        #    msdetail_pg.selenium.refresh()
-        # Assert.true(msdetail_pg.credentials_validity == "Valid")
+        Assert.equal(msdetail_pg.flash.message,
+                'Management System "%s" was saved' \
+                % management_system['edit_name'], FLASH_MESSAGE_NOT_MATCHED)
+        Assert.equal(msdetail_pg.name, management_system['edit_name'],
+                DETAIL_NOT_MATCHED_TEMPLATE % 'Edited name')
+        Assert.equal(msdetail_pg.hostname, management_system['hostname'],
+                DETAIL_NOT_MATCHED_TEMPLATE % 'Hostname')
+        Assert.equal(msdetail_pg.zone, management_system['server_zone'],
+                DETAIL_NOT_MATCHED_TEMPLATE % 'Server zone')
+        if 'host_vnc_port' in management_system:
+            Assert.equal(msdetail_pg.vnc_port_range,
+                    management_system['host_vnc_port'],
+                    DETAIL_NOT_MATCHED_TEMPLATE % 'VNC port range')
+
+    @pytest.mark.usefixtures('has_no_management_systems')
+    def test_management_system_add(
+            self, mgmtsys_page, management_system_data, soap_client):
+        '''Tests adding a new management system
+        '''
+        ms_pg = mgmtsys_page
+        msadd_pg = ms_pg.click_on_add_new_management_system()
+        ms_pg = msadd_pg.add_management_system(management_system_data)
+        Assert.equal(ms_pg.flash.message,
+                'Management System "%s" was saved' \
+                 % management_system_data['name'],
+                FLASH_MESSAGE_NOT_MATCHED)
+
+    @pytest.mark.usefixtures('has_no_management_systems')    
+    def test_management_system_add_with_bad_credentials(
+            self, mgmtsys_page, management_system_data):
+        '''Tests adding a new management system with bad credentials
+        '''
+        ms_pg = mgmtsys_page
+        msadd_pg = ms_pg.click_on_add_new_management_system()
+        management_system_data['credentials'] = 'bad_credentials'
+        msadd_pg = msadd_pg.add_management_system_with_bad_credentials(
+                management_system_data)
+        Assert.equal(msadd_pg.flash.message,
+            'Cannot complete login due to an incorrect user name or password.',
+            FLASH_MESSAGE_NOT_MATCHED)
 
+    @pytest.mark.usefixtures('has_no_management_systems')
+    def test_discover_management_systems_starts(
+            self, mgmtsys_page, management_system_data):
+        '''Tests the start of a management system discovery
+        '''
+        ms_pg = mgmtsys_page
+        Assert.true(ms_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
+        msd_pg = ms_pg.click_on_discover_management_systems()
+        Assert.true(msd_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
+        ms_pg = msd_pg.discover_systems(
+                management_system_data['type'],
+                management_system_data['discovery_range']['start'],
+                management_system_data['discovery_range']['end'])
+        Assert.true(ms_pg.is_the_current_page, CURRENT_PAGE_NOT_MATCHED)
+        Assert.equal(ms_pg.flash.message,
+                'Management System: Discovery successfully initiated',
+                FLASH_MESSAGE_NOT_MATCHED)
diff --git a/tests/ui/infrastructure/test_management_systems_pages.py b/tests/ui/infrastructure/test_management_systems_pages.py
new file mode 100644
--- /dev/null
+++ b/tests/ui/infrastructure/test_management_systems_pages.py
@@ -0,0 +1,29 @@
+'''
+Created on Jun 7, 2013
+
+@author: bcrochet
+'''
+# -*- coding: utf-8 -*-
+
+import pytest
+from unittestzero import Assert
+
+@pytest.fixture(params=[('title', 'Add this Management System'),
+        ('alt', 'Add this Management System')])
+def attribute_and_value(request):
+    return request.param
+
+@pytest.fixture
+def mgmtsys_add_pg(mgmtsys_page):
+    return mgmtsys_page.click_on_add_new_management_system()
+
+
+class TestManagementSystemsPages:
+    @pytest.mark.nondestructive
+    class TestManagementSystemsAddPage:
+        def test_that_checks_add_button_attribute(self, mgmtsys_add_pg, attribute_and_value):
+            attr = attribute_and_value[0]
+            expected_value = attribute_and_value[1]
+
+            add_attr = mgmtsys_add_pg.add_button.get_attribute(attr)
+            Assert.equal(add_attr, expected_value, "Could not verify %s" % expected_value)