def test_create_application_cache_invalidation(db, test_team): assert Application.get_by_name('bar') is None assert len(Application.get_multi_by_team(test_team.id)) == 0 assert len(Application.get_all()) == 0 Application.create('bar', test_team.id) assert Application.get_by_name('bar') is not None assert len(Application.get_multi_by_team(test_team.id)) == 1 assert len(Application.get_all()) == 1
def test_delete_application(db, test_user, test_team, test_application, test_application_auth): assert Application.get_by_name( test_application.application_name) is test_application assert Application.get_multi_by_team(test_team.id) == [test_application] assert Application.get_all() == [test_application] Application.delete(test_application.id) assert Application.get_by_name(test_application.application_name) is None assert Application.get_multi_by_team(test_team.id) == [] assert Application.get_all() == [] assert ApplicationAuth.get(test_application_auth.id) is None
def test_archive_application(db, test_user, test_team, test_application, test_application_auth): instance = Application.get_by_name(test_application.application_name) assert instance is test_application assert Application.get_multi_by_team(test_team.id) == [test_application] assert Application.get_all() == [test_application] test_application.archive() assert Application.get_by_name(test_application.application_name) is None assert Application.get_multi_by_team(test_team.id) == [] assert Application.get_all() == [] assert ApplicationAuth.find(Authority.READ, test_user.id, test_application.id) is not None
def get(self): """Gets the application list. In mimimal mode, this API returns application list from the ZooKeeper instead of MySQL. Some deleted applications will appear again. A successful response looks like a list of entities which defined in :ref:`application_item`, .. todo:: Extract the 401/404 from 401. :query with_authority: Optional. Passing ``1`` will let this API return applications which authorized by current user. Default is ``0`` (disabled). :<header Authorization: Huskar Token (See :ref:`token`) :status 401: The token are invalid or expired. :status 200: The application list is in the response: ``{"status": "SUCCESS", "data": [ {"name": "base.foo", "team_name": "Base", ...}]}`` """ with_authority = request.args.get('with_authority', type=int) with_authority = bool(with_authority) if g.auth.is_minimal_mode: result = application_schema.dump([ {'name': name, 'team_name': Team.DEFAULT_NAME, 'team_desc': Team.DEFAULT_NAME} for name in application_manifest.as_list() ], many=True) else: application_list = Application.get_all() if with_authority and not g.auth.is_admin: application_list = [ item for item in application_list if ( item.check_auth(Authority.READ, g.auth.id) or item.check_auth(Authority.WRITE, g.auth.id) ) ] result = application_schema.dump([ {'name': item.application_name, 'team_name': item.team.team_name, 'team_desc': item.team.team_desc} for item in application_list ], many=True) return api_response(result.data)
def collect_infra_config(): logger.info('Looking up application list') application_list = Application.get_all() builder = InfraDownstream.bindmany() client = huskar_client.client for application in application_list: application_name = application.application_name logger.info('Collecting %s', application_name) iterator = _collect_infra_upstream(client, application_name) iterator = _bind_infra_upstream(builder, iterator, application_name) for upstream in iterator: logger.info('Recorded %r', upstream) InfraDownstream.flush_cache_by_application( upstream.infra_application_name) builder.commit() logger.info('Committed %s', application_name) logger.info('Deleting stale records') builder.unbind_stale().commit() logger.info('Done')
def test_get_application_list(db, test_application): application_list = Application.get_all() assert application_list == [test_application]
def collect_applications(): names = set() names.update(x.application_name for x in Application.get_all()) names.update(application_manifest.as_list()) return sorted(n for n in names if n.startswith(NAME_PREFIXES))