Ejemplo n.º 1
0
    def test_nonadmins_cannot_create_powertypes(self):
        """Users missing admin privileges should not be allowed to create
        powertypes."""
        user_password = '******'
        with session.begin():
            user = data_setup.create_user(password=user_password)
            powertypes_amount = session.query(PowerType).count()
        login(self.s, user, user_password)

        response = post_json(get_server_base() + 'powertypes/',
                             session=self.s,
                             data=dict(name='ignored'))
        self.assertEqual(403, response.status_code)
        with session.begin():
            self.assertEqual(powertypes_amount, session.query(PowerType).count())
Ejemplo n.º 2
0
    def test_nonadmins_cannot_create_powertypes(self):
        """Users missing admin privileges should not be allowed to create
        powertypes."""
        user_password = '******'
        with session.begin():
            user = data_setup.create_user(password=user_password)
            powertypes_amount = session.query(PowerType).count()
        login(self.s, user, user_password)

        response = post_json(get_server_base() + 'powertypes/',
                             session=self.s,
                             data=dict(name='ignored'))
        self.assertEqual(403, response.status_code)
        with session.begin():
            self.assertEqual(powertypes_amount,
                             session.query(PowerType).count())
Ejemplo n.º 3
0
    def test_empty_pool_name_triggers_validation(self):
        """Adding a pool with an empty name triggers a validation error."""
        with session.begin():
            system_pools_count = session.query(SystemPool).count()

        b = self.browser
        login(b)
        b.get(get_server_base() + 'pools/')
        b.find_element_by_xpath('//button[normalize-space(string(.))="Create"]')\
            .click()
        modal = b.find_element_by_class_name('modal')
        modal.find_element_by_tag_name('form').submit()

        self.assertTrue(modal.find_element_by_css_selector('input[name="name"]:required:invalid'))
        with session.begin():
            self.assertEqual(system_pools_count, session.query(SystemPool).count())
Ejemplo n.º 4
0
    def test_empty_pool_name_triggers_validation(self):
        """Adding a pool with an empty name triggers a validation error."""
        with session.begin():
            system_pools_count = session.query(SystemPool).count()

        b = self.browser
        login(b)
        b.get(get_server_base() + 'pools/')
        b.find_element_by_xpath('//button[normalize-space(string(.))="Create"]')\
            .click()
        modal = b.find_element_by_class_name('modal')
        modal.find_element_by_tag_name('form').submit()

        self.assertTrue(
            modal.find_element_by_css_selector(
                'input[name="name"]:required:invalid'))
        with session.begin():
            self.assertEqual(system_pools_count,
                             session.query(SystemPool).count())
Ejemplo n.º 5
0
    def test_creates_powertype_successfully(self):
        b = self.browser
        b.get(get_server_base() + 'powertypes/')

        expected = 'newtype'
        b.find_element_by_css_selector('form input[name=power_type_name]').send_keys(expected)
        b.find_element_by_name('btn_add_power_type').click()

        b.find_element_by_xpath('//li[contains(., "%s")]' % expected)
        with session.begin():
            self.assertTrue(session.query(PowerType).filter_by(name=expected).count())
Ejemplo n.º 6
0
    def test_error_when_deleting_referenced_power_type(self):
        with session.begin():
            system = data_setup.create_system()
            power_type = system.power.power_type

        response = self.s.delete(get_server_base() + 'powertypes/%s' % power_type.id)
        self.assertEqual(400, response.status_code)
        with session.begin():
            session.expire_all()
            self.assertTrue(session.query(PowerType).filter_by(
                name=power_type.name).count())
Ejemplo n.º 7
0
    def test_list_powertypes(self):
        with session.begin():
            powertype_names = [x[0] for x in session.query(PowerType.name).all()]

        response = self.s.get(
            get_server_base() + 'powertypes',
            headers={'Accept': 'application/json'},
        )
        response.raise_for_status()

        actual_names = [x['name'] for x in response.json()['power_types']]
        self.assertItemsEqual(powertype_names, actual_names)
Ejemplo n.º 8
0
    def test_creates_powertype_successfully(self):
        b = self.browser
        b.get(get_server_base() + 'powertypes/')

        expected = 'newtype'
        b.find_element_by_css_selector(
            'form input[name=power_type_name]').send_keys(expected)
        b.find_element_by_name('btn_add_power_type').click()

        b.find_element_by_xpath('//li[contains(., "%s")]' % expected)
        with session.begin():
            self.assertTrue(
                session.query(PowerType).filter_by(name=expected).count())
Ejemplo n.º 9
0
    def test_error_when_deleting_referenced_power_type(self):
        with session.begin():
            system = data_setup.create_system()
            power_type = system.power.power_type

        response = self.s.delete(get_server_base() +
                                 'powertypes/%s' % power_type.id)
        self.assertEqual(400, response.status_code)
        with session.begin():
            session.expire_all()
            self.assertTrue(
                session.query(PowerType).filter_by(
                    name=power_type.name).count())
Ejemplo n.º 10
0
    def test_list_powertypes(self):
        with session.begin():
            powertype_names = [
                x[0] for x in session.query(PowerType.name).all()
            ]

        response = self.s.get(
            get_server_base() + 'powertypes',
            headers={'Accept': 'application/json'},
        )
        response.raise_for_status()

        actual_names = [x['name'] for x in response.json()['power_types']]
        self.assertItemsEqual(powertype_names, actual_names)
Ejemplo n.º 11
0
    def test_deletes_power_type_successfully(self):
        powertype_name = unique_name('beerpowered%s')
        with session.begin():
            pt = PowerType(name=powertype_name)
            session.add(pt)
            activity_count = Activity.query.count()

        b = self.browser
        b.get(get_server_base() + 'powertypes/')
        b.find_element_by_xpath('//li[contains(., "%s")]/button' % pt.name).click()
        b.find_element_by_xpath('//ul[contains(@class, "power-types-list") and '
                'not(./li[contains(., "%s")])]' % pt.name)

        with session.begin():
            session.expire_all()
            self.assertEqual(0, session.query(PowerType).filter_by(name=powertype_name).count())
            self.assertEqual(activity_count + 1, Activity.query.count())
Ejemplo n.º 12
0
    def test_deletes_power_type_successfully(self):
        powertype_name = unique_name('beerpowered%s')
        with session.begin():
            pt = PowerType(name=powertype_name)
            session.add(pt)
            activity_count = Activity.query.count()

        b = self.browser
        b.get(get_server_base() + 'powertypes/')
        b.find_element_by_xpath('//li[contains(., "%s")]/button' %
                                pt.name).click()
        b.find_element_by_xpath(
            '//ul[contains(@class, "power-types-list") and '
            'not(./li[contains(., "%s")])]' % pt.name)

        with session.begin():
            session.expire_all()
            self.assertEqual(
                0,
                session.query(PowerType).filter_by(
                    name=powertype_name).count())
            self.assertEqual(activity_count + 1, Activity.query.count())