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

unity-sds / unity-py / 7399750331

03 Jan 2024 04:21PM UTC coverage: 85.749% (+1.5%) from 84.257%
7399750331

Pull #66

github

web-flow
Merge branch 'main' into develop
Pull Request #66: Develop 0.2.2 into main

21 of 27 new or added lines in 4 files covered. (77.78%)

1 existing line in 1 file now uncovered.

355 of 414 relevant lines covered (85.75%)

5.14 hits per line

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

69.57
/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.unity_session import UnitySession
6✔
6
from unity_sds_client.unity_exception import UnityException
6✔
7
from unity_sds_client.unity_environments import UnityEnvironments
6✔
8
from unity_sds_client.unity_services import UnityServices
6✔
9

10

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

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

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

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

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

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

61
    def __str__(self):
6✔
62
        response = "UNITY CONFIGURATION"
×
63
        response = response + "\n\n" + len(response) * "-" + "\n"
×
64
        
65
        config = self._session.get_config()
×
66
        config_sections = config.sections()
×
67
        for section in config_sections:
×
68
            response = response + "\n{}\n".format(section)
×
69
            for setting in dict(config[section]):
×
70
                response = response + "{}: {}\n".format(setting, dict(config[section])[setting])
×
71

72
        return response
×
73

74

75
def _read_config(config_files):
6✔
76
    config = ConfigParser(interpolation=ExtendedInterpolation())
6✔
77

78
    for config_file in config_files:
6✔
79
        if config_file is not None:
6✔
80
            with open(config_file) as source:
6✔
81
                config.read_file(source)
6✔
82

83
    return config
6✔
84

85

86
def _get_config(config, section, setting):
6✔
87
    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