Exemplo n.º 1
0
    def test_get_link_url(self):
        """Test get_link_url.

        Because the dictionary part of ``attrs[ng-click]`` may have different
        key orders, extract it, convert it to an actual dict, and check that
        each value in the dict matches the expected value.
        """
        update_metadata = tables.UpdateMetadata()
        update_metadata.table = mock.Mock()
        update_metadata.table.kwargs = {'environment_id': 'foo_env_id'}
        update_metadata.session_id = 'foo_session_id'
        test_service = {'?': {'id': 'foo_service_id'}}

        result = update_metadata.get_link_url(test_service)
        self.assertEqual("javascript:void(0);", result)

        lindex = update_metadata.attrs['ng-click'].find('{')
        rindex = update_metadata.attrs['ng-click'].rfind('}') + 1
        attrs = ast.literal_eval(
            update_metadata.attrs['ng-click'][lindex:rindex])
        expected_attrs = {
            'environment': 'foo_env_id',
            'session': 'foo_session_id',
            'component': 'foo_service_id'
        }
        update_metadata.attrs['ng-click'] =\
            update_metadata.attrs['ng-click'][:lindex] +\
            update_metadata.attrs['ng-click'][rindex + 2:]

        self.assertEqual("modal.openMetadataModal('muranoapp', true)",
                         update_metadata.attrs['ng-click'])
        for key, val in expected_attrs.items():
            self.assertEqual(val, attrs[key])
Exemplo n.º 2
0
    def setUp(self):
        super(TestUpdateMetadata, self).setUp()

        update_metadata = tables.UpdateMetadata()
        self.assertEqual("update_metadata", update_metadata.name)
        self.assertEqual("Update Metadata", update_metadata.verbose_name)
        self.assertFalse(update_metadata.ajax)
        self.assertEqual("pencil", update_metadata.icon)
        self.assertIsNone(update_metadata.session_id)
Exemplo n.º 3
0
    def test_update(self, mock_api):
        mock_api.Session.get_if_available.return_value = 'foo_session_id'
        update_metadata = tables.UpdateMetadata()
        update_metadata.table = mock.Mock()
        update_metadata.table.kwargs = {'environment_id': 'foo_env_id'}
        update_metadata.session_id = None

        update_metadata.update(None, None)
        self.assertEqual('foo_session_id', update_metadata.session_id)
        mock_api.Session.get_if_available.assert_called_once_with(
            None, 'foo_env_id')
Exemplo n.º 4
0
    def test_allowed(self, mock_api):
        update_metadata = tables.UpdateMetadata()
        mock_api.environment_get.return_value = mock.Mock(
            status=consts.STATUS_ID_READY)
        mock_table = mock.Mock()
        mock_table.kwargs = {'environment_id': 'foo_env_id'}
        update_metadata.table = mock_table
        self.assertTrue(update_metadata.allowed(None))

        mock_api.environment_get.return_value = mock.Mock(
            status=consts.STATUS_ID_DEPLOYING)
        self.assertFalse(update_metadata.allowed(None))
        mock_api.environment_get.assert_called_with(None, 'foo_env_id')