Coverage for suhteita/source_server_actions.py: 0.00%

23 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 22:42:46 +00:00

1"""Actions on source server instances.""" 

2 

3import copy 

4import datetime as dti 

5from typing import Dict, List, Tuple 

6 

7from atlassian import Bitbucket # type: ignore 

8 

9from suhteita import IS_CLOUD, TOKEN, TS_FORMAT_PAYLOADS, Clocking 

10 

11 

12def login(target_url: str, user: str, password: str = TOKEN, is_cloud: bool = IS_CLOUD) -> Tuple[Clocking, Bitbucket]: 

13 """DRY.""" 

14 start_time = dti.datetime.now(tz=dti.timezone.utc) 

15 service = Bitbucket(url=target_url, username=user, password=password, cloud=is_cloud) 

16 end_time = dti.datetime.now(tz=dti.timezone.utc) 

17 clocking: Clocking = ( 

18 start_time.strftime(TS_FORMAT_PAYLOADS), 

19 (end_time - start_time).microseconds, 

20 end_time.strftime(TS_FORMAT_PAYLOADS), 

21 ) 

22 return clocking, service 

23 

24 

25def get_server_info(service: Bitbucket) -> Tuple[Clocking, object]: 

26 """DRY.""" 

27 start_time = dti.datetime.now(tz=dti.timezone.utc) 

28 data = copy.deepcopy(service.get_server_info(True)) 

29 end_time = dti.datetime.now(tz=dti.timezone.utc) 

30 clocking: Clocking = ( 

31 start_time.strftime(TS_FORMAT_PAYLOADS), 

32 (end_time - start_time).microseconds, 

33 end_time.strftime(TS_FORMAT_PAYLOADS), 

34 ) 

35 return clocking, data 

36 

37 

38def get_all_projects(service: Bitbucket) -> Tuple[Clocking, List[Dict[str, str]]]: 

39 """DRY.""" 

40 start_time = dti.datetime.now(tz=dti.timezone.utc) 

41 projects = copy.deepcopy(service.get_all_projects(included_archived=None)) 

42 end_time = dti.datetime.now(tz=dti.timezone.utc) 

43 clocking: Clocking = ( 

44 start_time.strftime(TS_FORMAT_PAYLOADS), 

45 (end_time - start_time).microseconds, 

46 end_time.strftime(TS_FORMAT_PAYLOADS), 

47 ) 

48 return clocking, projects