• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

unity-sds / unity-py / 9765852317

02 Jul 2024 06:05PM UTC coverage: 52.801% (-34.8%) from 87.575%
9765852317

Pull #90

github

web-flow
Merge d2b62759a into 44488b0de
Pull Request #90: Add health service

32 of 36 new or added lines in 3 files covered. (88.89%)

85 existing lines in 8 files now uncovered.

377 of 714 relevant lines covered (52.8%)

3.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.51
/unity_sds_client/unity.py
1
import os
6✔
2
from configparser import ConfigParser, ExtendedInterpolation
6✔
3
from unity_sds_client.services.data_service import DataService
6✔
4
from unity_sds_client.services.process_service import ProcessService
6✔
5
from unity_sds_client.services.health_service import HealthService
6✔
6
from unity_sds_client.unity_session import UnitySession
6✔
7
from unity_sds_client.unity_exception import UnityException
6✔
8
from unity_sds_client.unity_environments import UnityEnvironments
6✔
9
from unity_sds_client.unity_services import UnityServices
6✔
10

11

12
class Unity(object):
6✔
13
    """
6✔
14
    The Unity class is used to create services and resources that facilitate interacting with the Unity Platform.
15
    Basic shared configuration items are also saved here. This wraps an underlying unity_session.Session object, which
16
    is passed to different services and resources as needed.
17
    """
18

19
    def __init__(self, environment: UnityEnvironments = UnityEnvironments.TEST, config_file_override:str = None):
6✔
20
        """
21
        :param environment: the default environment for a session to work with. Defaults to 'TEST' unity environment.
22
        :param config_file_override: absolute path to a config file containing settings to override default config
23
        """
24
        env = environment
6✔
25
        config = _read_config([
6✔
26
            os.path.dirname(os.path.realpath(__file__)) + "/envs/environments.cfg".format(str(env.value).lower()),
27
            config_file_override
28
        ])
29
        self._session = UnitySession(env.value, config)
6✔
30

31
    def set_project(self, project):
6✔
32
        """
33
        :param project: the project to use when interacting with venue specific services. Used in building the restful
34
        endpoint.
35
        """
36
        self._session._project  = project
6✔
37

38
    def set_venue(self, venue):
6✔
39
        """
40
        :param venue: the venue to use when interacting with venue specific services. Used in building the restful
41
        endpoint.
42
        """
43
        self._session._venue = venue
6✔
44

45
    def set_venue_id(self, venue_id):
6✔
46
        """
47
        :param venue_id: explicitly name the venue identifier. Useful for legacy or non-hierarchical venue ids.  Used in
48
         building the restful
49
        endpoint.
50
        """
51
        self._session._venue_id = venue_id
6✔
52

53
    def client(self, service_name: UnityServices):
6✔
54
        """
55
        :param service_name - the desired service, such as UnityServices.APPLICATION_SERVICE, UnityServices.DATA_SERVICE, or UnityServices.PROCESS_SERVICE.
56
        """
57
        if service_name == UnityServices.DATA_SERVICE:
6✔
58
            return DataService(session=self._session)
6✔
59
        if service_name == UnityServices.HEALTH_SERVICE:
6✔
60
            return HealthService(session=self._session)
6✔
61
        elif service_name == UnityServices.PROCESS_SERVICE:
6✔
62
            return ProcessService(session=self._session)
6✔
63
        else:
64
            raise UnityException("Invalid service name: " + str(service_name))
×
65

66
    def __str__(self):
6✔
NEW
67
        response = "\nUNITY CONFIGURATION"
×
NEW
68
        response = response + "\n" + len(response) * "-" + "\n"
×
69
        
70
        config = self._session.get_config()
×
71
        config_sections = config.sections()
×
72
        for section in config_sections:
×
NEW
73
            response = response + "\n[{}]\n".format(section)
×
74
            for setting in dict(config[section]):
×
75
                response = response + "{}: {}\n".format(setting, dict(config[section])[setting])
×
76

NEW
77
        response = response + self.client(UnityServices.HEALTH_SERVICE).generate_health_status_report()
×
78

UNCOV
79
        return response
×
80

81

82
def _read_config(config_files):
6✔
83
    config = ConfigParser(interpolation=ExtendedInterpolation())
6✔
84

85
    for config_file in config_files:
6✔
86
        if config_file is not None:
6✔
87
            with open(config_file) as source:
6✔
88
                config.read_file(source)
6✔
89

90
    return config
6✔
91

92

93
def _get_config(config, section, setting):
6✔
94
    return config.get(section.upper(), setting)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc