def test_update(self, mock_api): mock_api.Session.get_if_available.return_value = 'foo_session_id' update_env_meta_data = tables.UpdateEnvMetadata() datum = mock.Mock() datum.id = 'foo_env_id' update_env_meta_data.session_id = None update_env_meta_data.update(None, datum) self.assertEqual('foo_session_id', update_env_meta_data.session_id) mock_api.Session.get_if_available.assert_called_once_with( None, 'foo_env_id')
def test_update(self, mock_api): mock_api.Session.get_if_available.return_value = 'foo_session_id' update_env_meta_data = tables.UpdateEnvMetadata() update_env_meta_data.table = mock.Mock() update_env_meta_data.table.kwargs = {'environment_id': 'foo_env_id'} update_env_meta_data.session_id = None update_env_meta_data.update(None, None) self.assertEqual('foo_session_id', update_env_meta_data.session_id) mock_api.Session.get_if_available.assert_called_once_with( None, 'foo_env_id')
def test_update_env_meta_data(self): kwargs = {'datum': 'foo_datum'} update_env_meta_data = tables.UpdateEnvMetadata(**kwargs) self.assertEqual("update_env_metadata", update_env_meta_data.name) self.assertEqual("Update Metadata", update_env_meta_data.verbose_name) self.assertFalse(update_env_meta_data.ajax) self.assertEqual("pencil", update_env_meta_data.icon) self.assertEqual( {"ng-controller": "MetadataModalHelperController as modal"}, update_env_meta_data.attrs) self.assertTrue(update_env_meta_data.preempt) self.assertEqual("foo_datum", update_env_meta_data.datum)
def test_allowed(self): update_env_meta_data = tables.UpdateEnvMetadata() allowed_statuses = (consts.STATUS_ID_READY, consts.STATUS_ID_PENDING, consts.STATUS_ID_DELETE_FAILURE, consts.STATUS_ID_DEPLOY_FAILURE, consts.STATUS_ID_NEW) disallowed_statuses = (consts.STATUS_ID_DEPLOYING, consts.STATUS_ID_DELETING) for status in allowed_statuses: env = mock.Mock(status=status) self.assertTrue(update_env_meta_data.allowed(None, env)) for status in disallowed_statuses: env = mock.Mock(status=status) self.assertFalse(update_env_meta_data.allowed(None, env))
def test_get_link_url(self): update_env_meta_data = tables.UpdateEnvMetadata() update_env_meta_data.session_id = 'foo_session_id' update_env_meta_data.attrs = {} result = update_env_meta_data.get_link_url(mock.Mock(id='foo_env_id')) self.assertEqual("javascript:void(0);", result) lindex = update_env_meta_data.attrs['ng-click'].find('{') rindex = update_env_meta_data.attrs['ng-click'].rfind('}') + 1 attrs = ast.literal_eval( update_env_meta_data.attrs['ng-click'][lindex:rindex]) expected_attrs = { 'environment': 'foo_env_id', 'session': 'foo_session_id' } update_env_meta_data.attrs['ng-click'] =\ update_env_meta_data.attrs['ng-click'][:lindex] +\ update_env_meta_data.attrs['ng-click'][rindex + 2:] self.assertEqual("modal.openMetadataModal('muranoenv', true)", update_env_meta_data.attrs['ng-click']) for key, val in expected_attrs.items(): self.assertEqual(val, attrs[key])