from unittest.mock import MagicMock, patch from app.languages import get_project, helm_set import gitlab from gitlab.v4.objects import ProjectManager as pm def test_get_project(): project_object = { 'id': 34, 'description': 'A getting started template for go-micro (https://micro.mu/docs/go-micro.html)', 'name': 'test', 'name_with_namespace': 'Administrator / test', 'path': 'test', 'path_with_namespace': 'root/test', 'created_at': '2022-05-21T20:37:54.935Z', 'default_branch': 'master', 'tag_list': [], 'topics': [], 'ssh_url_to_repo': 'git@localhost:root/test.git', 'http_url_to_repo': 'http://localhost/root/test.git', 'web_url': 'http://localhost/root/test', 'readme_url': 'http://localhost/root/test/-/blob/master/README.md', 'avatar_url': None, 'forks_count': 0, 'star_count': 0, 'last_activity_at': '2022-05-21T20:37:54.935Z', 'namespace': { 'id': 1, 'name': 'Administrator', 'path': 'root', 'kind': 'user', 'full_path': 'root', 'parent_id': None, 'avatar_url': 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', 'web_url': 'http://localhost/root'}, '_links': { 'self': 'http://localhost/api/v4/projects/34', 'issues': 'http://localhost/api/v4/projects/34/issues', 'merge_requests': 'http://localhost/api/v4/projects/34/merge_requests', 'repo_branches': 'http://localhost/api/v4/projects/34/repository/branches', 'labels': 'http://localhost/api/v4/projects/34/labels', 'events': 'http://localhost/api/v4/projects/34/events', 'members': 'http://localhost/api/v4/projects/34/members'}, 'packages_enabled': True, 'empty_repo': False, 'archived': False, 'visibility': 'public', 'owner': { 'id': 1, 'username': 'root', 'name': 'Administrator', 'state': 'active', 'avatar_url': 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon', 'web_url': 'http://localhost/root'}, 'resolve_outdated_diff_discussions': False, 'container_expiration_policy': { 'cadence': '1d', 'enabled': False, 'keep_n': 10, 'older_than': '90d', 'name_regex': '.*', 'name_regex_keep': None, 'next_run_at': '2022-05-22T20:37:55.006Z'}, 'issues_enabled': True, 'merge_requests_enabled': True, 'wiki_enabled': True, 'jobs_enabled': True, 'snippets_enabled': True, 'container_registry_enabled': True, 'service_desk_enabled': False, 'service_desk_address': None, 'can_create_merge_request_in': True, 'issues_access_level': 'enabled', 'repository_access_level': 'enabled', 'merge_requests_access_level': 'enabled', 'forking_access_level': 'enabled', 'wiki_access_level': 'enabled', 'builds_access_level': 'enabled', 'snippets_access_level': 'enabled', 'pages_access_level': 'enabled', 'operations_access_level': 'enabled', 'analytics_access_level': 'enabled', 'container_registry_access_level': 'enabled', 'security_and_compliance_access_level': 'private', 'emails_disabled': None, 'shared_runners_enabled': True, 'lfs_enabled': True, 'creator_id': 1, 'import_url': None, 'import_type': 'gitlab_project', 'import_status': 'finished', 'import_error': None, 'open_issues_count': 0, 'runners_token': 'REDACTED', 'ci_default_git_depth': 20, 'ci_forward_deployment_enabled': True, 'ci_job_token_scope_enabled': False, 'ci_separated_caches': True, 'public_jobs': True, 'build_git_strategy': 'fetch', 'build_timeout': 3600, 'auto_cancel_pending_pipelines': 'enabled', 'build_coverage_regex': None, 'ci_config_path': None, 'shared_with_groups': [], 'only_allow_merge_if_pipeline_succeeds': False, 'allow_merge_on_skipped_pipeline': None, 'restrict_user_defined_variables': False, 'request_access_enabled': False, 'only_allow_merge_if_all_discussions_are_resolved': False, 'remove_source_branch_after_merge': True, 'printing_merge_request_link_enabled': True, 'merge_method': 'merge', 'squash_option': 'default_off', 'suggestion_commit_message': None, 'merge_commit_template': None, 'squash_commit_template': None, 'auto_devops_enabled': True, 'auto_devops_deploy_strategy': 'continuous', 'autoclose_referenced_issues': True, 'repository_storage': 'default', 'keep_latest_artifact': True, 'runner_token_expiration_interval': None, 'permissions': { 'project_access': { 'access_level': 50, 'notification_level': 3}, 'group_access': None}} with patch.object(pm, 'get', return_value=project_object): gl = gitlab.Gitlab() project = get_project(gl, 'root/test') assert project['id'] == 34 def test_get_language(): get_language = MagicMock(return_value=[('Go', 100.0)]) expected = [('Go', 100.0)] actual = get_language("project") assert expected == actual def test_helm_set(): excepted = '--set global.language[0]=Go' actual = helm_set([('Go', 100.0)]) assert excepted == actual