Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import sys 

2import os 

3import json 

4 

5sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../../../") 

6from sdc_etl_libs.api_helpers.apis.Ultipro.UltiproRESTAPIs import UltiproRESTAPIs 

7 

8 

9def test_no_data(mocker): 

10 mocker.patch('sdc_etl_libs.api_helpers.API.API.get_credentials', 

11 return_value={"username": "foo", "password": "bar", 

12 "api_key": "baz"}) 

13 

14 class ReqMock(): 

15 status_code = 200 

16 content = "[]" 

17 

18 mocker.patch('requests.get', return_value=ReqMock) 

19 

20 ultipro = UltiproRESTAPIs() 

21 

22 df = ultipro.get_employment_details() 

23 assert (df == None) 

24 

25 

26def test_paginate_data(mocker): 

27 mocker.patch('sdc_etl_libs.api_helpers.API.API.get_credentials', 

28 return_value={"username": "foo", "password": "bar", 

29 "api_key": "baz"}) 

30 

31 class ReqMock(): 

32 def __init__(self, status_, data_): 

33 self.status_code = status_ 

34 self.content = data_ 

35 

36 def get_mock(url_, **kwargs): 

37 print(url_) 

38 

39 page_1 = [ 

40 { 

41 "companyID": "string", 

42 "companyCode": "string", 

43 "companyName": "string", 

44 "employeeID": "string", 

45 "jobDescription": "string", 

46 "payGroupDescription": "string", 

47 "primaryJobCode": "string", 

48 "orgLevel1Code": "string", 

49 "orgLevel2Code": "string", 

50 "orgLevel3Code": "string", 

51 "orgLevel4Code": "string", 

52 "originalHireDate": "2019-06-13T15:06:18.337Z", 

53 "lastHireDate": "2019-06-13T15:06:18.337Z", 

54 "fullTimeOrPartTimeCode": "string", 

55 "primaryWorkLocationCode": "string", 

56 "languageCode": "string", 

57 "primaryProjectCode": "string", 

58 "workPhoneNumber": "string", 

59 "workPhoneExtension": "string", 

60 "workPhoneCountry": "string", 

61 "dateInJob": "2019-06-13T15:06:18.337Z", 

62 "dateLastWorked": "2019-06-13T15:06:18.337Z", 

63 "dateOfBenefitSeniority": "2019-06-13T15:06:18.337Z", 

64 "dateOfSeniority": "2019-06-13T15:06:18.337Z", 

65 "deductionGroupCode": "string", 

66 "earningGroupCode": "string", 

67 "employeeTypeCode": "string", 

68 "employeeStatusCode": "string", 

69 "employeeNumber": "string", 

70 "jobChangeReasonCode": "string", 

71 "jobTitle": "string", 

72 "leaveReasonCode": "string", 

73 "supervisorID": "string", 

74 "supervisorFirstName": "string", 

75 "supervisorLastName": "string", 

76 "autoAllocate": "string", 

77 "clockCode": "string", 

78 "dateLastPayDatePaid": "2019-06-13T15:06:18.337Z", 

79 "dateOfEarlyRetirement": "2019-06-13T15:06:18.337Z", 

80 "dateOfLocalUnion": "2019-06-13T15:06:18.337Z", 

81 "dateOfNationalUnion": "2019-06-13T15:06:18.337Z", 

82 "dateOfRetirement": "2019-06-13T15:06:18.337Z", 

83 "dateOfSuspension": "2019-06-13T15:06:18.337Z", 

84 "dateOfTermination": "2019-06-13T15:06:18.337Z", 

85 "datePaidThru": "2019-06-13T15:06:18.337Z", 

86 "statusStartDate": "2019-06-13T15:06:18.337Z", 

87 "hireSource": "string", 

88 "isAutoAllocated": "string", 

89 "isAutopaid": "string", 

90 "isMultipleJob": "string", 

91 "jobGroupCode": "string", 

92 "mailstop": "string", 

93 "okToRehire": "string", 

94 "payGroup": "string", 

95 "payPeriod": "string", 

96 "plannedLeaveReason": "string", 

97 "positionCode": "string", 

98 "salaryOrHourly": "string", 

99 "scheduledAnnualHrs": 0, 

100 "scheduledFTE": 0, 

101 "scheduledWorkHrs": 0, 

102 "shift": "string", 

103 "shiftGroup": "string", 

104 "termReason": "string", 

105 "terminationReasonDescription": "string", 

106 "termType": "string", 

107 "timeclockID": "string", 

108 "unionLocal": "string", 

109 "unionNational": "string", 

110 "weeklyHours": 0, 

111 "dateTimeCreated": "2019-06-13T15:06:18.337Z", 

112 "dateTimeChanged": "2019-06-13T15:06:18.337Z" 

113 } 

114 ] 

115 page_2 = [ 

116 { 

117 "companyID": "fpo", 

118 "companyCode": "bar", 

119 "companyName": "baz", 

120 "employeeID": "hhshw66222w2w", 

121 "jobDescription": "coolest", 

122 "payGroupDescription": "string", 

123 "primaryJobCode": "fake", 

124 "orgLevel1Code": "stuff", 

125 "orgLevel2Code": "al;ways", 

126 "orgLevel3Code": "helps", 

127 "orgLevel4Code": "with", 

128 "originalHireDate": "2019-07-13T15:06:18.337Z", 

129 "lastHireDate": "2019-07-13T15:06:18.337Z", 

130 "fullTimeOrPartTimeCode": "testing", 

131 "primaryWorkLocationCode": "string", 

132 "languageCode": "string", 

133 "primaryProjectCode": "string", 

134 "workPhoneNumber": "string", 

135 "workPhoneExtension": "string", 

136 "workPhoneCountry": "string", 

137 "dateInJob": "2019-06-13T15:06:18.337Z", 

138 "dateLastWorked": "2019-06-13T15:06:18.337Z", 

139 "dateOfBenefitSeniority": "2019-06-13T15:06:18.337Z", 

140 "dateOfSeniority": "2019-06-13T15:06:18.337Z", 

141 "deductionGroupCode": "string", 

142 "earningGroupCode": "string", 

143 "employeeTypeCode": "string", 

144 "employeeStatusCode": "string", 

145 "employeeNumber": "string", 

146 "jobChangeReasonCode": "string", 

147 "jobTitle": "string", 

148 "leaveReasonCode": "string", 

149 "supervisorID": "string", 

150 "supervisorFirstName": "string", 

151 "supervisorLastName": "string", 

152 "autoAllocate": "string", 

153 "clockCode": "string", 

154 "dateLastPayDatePaid": "2019-06-13T15:06:18.337Z", 

155 "dateOfEarlyRetirement": "2019-06-13T15:06:18.337Z", 

156 "dateOfLocalUnion": "2019-06-13T15:06:18.337Z", 

157 "dateOfNationalUnion": "2019-06-13T15:06:18.337Z", 

158 "dateOfRetirement": "2019-06-13T15:06:18.337Z", 

159 "dateOfSuspension": "2019-06-13T15:06:18.337Z", 

160 "dateOfTermination": "2019-06-13T15:06:18.337Z", 

161 "datePaidThru": "2019-06-13T15:06:18.337Z", 

162 "statusStartDate": "2019-06-13T15:06:18.337Z", 

163 "hireSource": "string", 

164 "isAutoAllocated": "string", 

165 "isAutopaid": "string", 

166 "isMultipleJob": "string", 

167 "jobGroupCode": "string", 

168 "mailstop": "string", 

169 "okToRehire": "string", 

170 "payGroup": "string", 

171 "payPeriod": "string", 

172 "plannedLeaveReason": "string", 

173 "positionCode": "string", 

174 "salaryOrHourly": "string", 

175 "scheduledAnnualHrs": 0, 

176 "scheduledFTE": 0, 

177 "scheduledWorkHrs": 0, 

178 "shift": "string", 

179 "shiftGroup": "string", 

180 "termReason": "string", 

181 "terminationReasonDescription": "string", 

182 "termType": "string", 

183 "timeclockID": "string", 

184 "unionLocal": "string", 

185 "unionNational": "string", 

186 "weeklyHours": 0, 

187 "dateTimeCreated": "2019-06-13T15:06:18.337Z", 

188 "dateTimeChanged": "2019-06-13T15:06:18.337Z" 

189 } 

190 ] 

191 if url_ == 'https://service5.ultipro.com/api/personnel/v1/employment-details?page=1&per_page=100': 

192 return ReqMock(200, json.dumps(page_1)) 

193 elif url_ == 'https://service5.ultipro.com/api/personnel/v1/employment-details?page=2&per_page=100': 

194 return ReqMock(200, json.dumps(page_2)) 

195 else: 

196 return ReqMock(200, "[]") 

197 

198 mock_get = mocker.patch('requests.get', new_callable=lambda: get_mock) 

199 

200 ultipro = UltiproRESTAPIs() 

201 

202 df = ultipro.get_employment_details() 

203 assert len(df.df) == 2