def test_badge_with_category(self) -> None: self.app.config['WHITELIST_BADGES'] = [ Badge(badge_name='alpha', category='table_status') ] response = self.app.test_client().put( f'/table/{TABLE_NAME}/badge/{BADGE_NAME}?category=table_status') self.assertEqual(response.status_code, HTTPStatus.OK)
def test_block_badge_missing_category(self) -> None: self.app.config['WHITELIST_BADGES'] = [ Badge(badge_name='alpha', category='table_status') ] response = self.app.test_client().put( f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}') self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
def test_block_badge_missing_category_or_badge_type(self) -> None: self.app.config['WHITELIST_BADGES'] = [ Badge(badge_name='alpha', category='table_status', badge_type='neutral') ] response = self.app.test_client().put( f'/table/{TABLE_NAME}/badge/{BADGE_NAME}') self.assertEqual(response.status_code, HTTPStatus.BAD_REQUEST)
def test_badge_with_category_and_badge_type(self) -> None: self.app.config['WHITELIST_BADGES'] = [ Badge(badge_name='alpha', category='table_status', badge_type='neutral') ] response = self.app.test_client().put( f'/dashboard/{DASHBOARD_NAME}/badge/{BADGE_NAME}?category=table_status&' 'badge_type=neutral') self.assertEqual(response.status_code, HTTPStatus.OK)
def test_badge_on_reserved_badge_value(self) -> None: self.app.config['WHITELIST_BADGES'] = [ Badge(badge_name=BADGE_NAME, category='table_status') ] mock_proxy = MagicMock() tag_common = TagCommon(client=mock_proxy) response = tag_common.put(id='', resource_type=ResourceType.Dashboard, tag=BADGE_NAME, tag_type='badge') self.assertEqual(response[1], HTTPStatus.NOT_ACCEPTABLE)
def test_badge_on_reserved_badge_name(self) -> None: self.app.config['WHITELIST_BADGES'] = [ Badge(badge_name='alpha', category='table_status') ] mock_proxy = MagicMock() badge_common = BadgeCommon(client=mock_proxy) response = badge_common.put(id='', resource_type=ResourceType.Dashboard, badge_name=BADGE_NAME, category=CATEGORY) self.assertEqual(response[1], HTTPStatus.OK)
def put(self, id: str, resource_type: ResourceType, badge_name: str, category: str = '', badge_type: str = '') -> Tuple[Any, HTTPStatus]: if badge_type == '' or category == '': return \ {'message': f'The badge {badge_name} for resource id {id} is not added successfully because ' f'category `{category}` and badge_type `{badge_type}` parameters are required ' 'for badges'}, \ HTTPStatus.NOT_FOUND # TODO check resource type is column when adding a badge of category column after # implementing column level badges whitelist_badges = app.config.get('WHITELIST_BADGES', []) incomimg_badge = Badge(badge_name=badge_name, category=category, badge_type=badge_type) # need to check whether the badge combination is part of the whitelist: in_whitelist = False for badge in whitelist_badges: if incomimg_badge.badge_name == badge.badge_name and incomimg_badge.category == badge.category \ and incomimg_badge.badge_type == badge.badge_type: in_whitelist = True if not in_whitelist: return \ {'message': f'The badge {badge_name} with category {category} badge_type {badge_type} for resource ' f'id {id} and resource_type {resource_type.name} is not added successfully because ' 'this combination of values is not part of the whitelist'}, \ HTTPStatus.NOT_FOUND try: self.client.add_badge(id=id, badge_name=badge_name, category=category, badge_type=badge_type, resource_type=resource_type) return { 'message': f'The badge {badge_name} with category {category} and type {badge_type} was ' f'added successfully to resurce with id {id}' }, HTTPStatus.OK except Exception as e: return {'message': f'The badge {badge_name} with category {category}, badge type {badge_type} ' f'for resource id {id} and resource_type {resource_type.name} failed to ' 'be added'}, \ HTTPStatus.NOT_FOUND
def test_badge_with_category(self) -> None: self.app.config['WHITELIST_BADGES'] = [Badge(badge_name='pii', category='data')] response = self.app.test_client().put(f'/feature/{FEATURE_NAME}/badge/{BADGE_NAME}?category=data') self.assertEqual(response.status_code, HTTPStatus.OK)