4
4
from __future__ import absolute_import
5
5
6
6
import os
7
+ import sys
7
8
import logging
8
9
import unittest
9
10
10
11
from mock import MagicMock , patch
11
12
13
+ import pytest
12
14
import requests
13
15
14
16
from instana .agent .host import HostAgent
@@ -98,9 +100,9 @@ def test_announce_is_successful(self, mock_requests_session_put):
98
100
mock_response .status_code = 200
99
101
mock_response .content = (
100
102
'{'
101
- f ' "pid": { test_pid } , '
102
- f ' "agentUuid": "{ test_agent_uuid } "'
103
- '}' )
103
+ ' "pid": %d , '
104
+ ' "agentUuid": "%s "'
105
+ '}' % ( test_pid , test_agent_uuid ) )
104
106
105
107
# This mocks the call to self.agent.client.put
106
108
mock_requests_session_put .return_value = mock_response
@@ -117,6 +119,8 @@ def test_announce_is_successful(self, mock_requests_session_put):
117
119
self .assertEqual (test_agent_uuid , payload ['agentUuid' ])
118
120
119
121
122
+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
123
+ reason = "assertLogs is not available in Python 2" )
120
124
@patch .object (requests .Session , "put" )
121
125
def test_announce_fails_with_non_200 (self , mock_requests_session_put ):
122
126
test_pid = 4242
@@ -141,6 +145,8 @@ def test_announce_fails_with_non_200(self, mock_requests_session_put):
141
145
self .assertIn ('is NOT 200' , log .output [0 ])
142
146
143
147
148
+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
149
+ reason = "assertLogs is not available in Python 2" )
144
150
@patch .object (requests .Session , "put" )
145
151
def test_announce_fails_with_non_json (self , mock_requests_session_put ):
146
152
test_pid = 4242
@@ -164,6 +170,8 @@ def test_announce_fails_with_non_json(self, mock_requests_session_put):
164
170
self .assertIn ('response is not JSON' , log .output [0 ])
165
171
166
172
173
+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
174
+ reason = "assertLogs is not available in Python 2" )
167
175
@patch .object (requests .Session , "put" )
168
176
def test_announce_fails_with_missing_pid (self , mock_requests_session_put ):
169
177
test_pid = 4242
@@ -175,8 +183,8 @@ def test_announce_fails_with_missing_pid(self, mock_requests_session_put):
175
183
mock_response .status_code = 200
176
184
mock_response .content = (
177
185
'{'
178
- f ' "agentUuid": "{ test_agent_uuid } "'
179
- '}' )
186
+ ' "agentUuid": "%s "'
187
+ '}' % ( test_agent_uuid ) )
180
188
mock_requests_session_put .return_value = mock_response
181
189
182
190
self .create_agent_and_setup_tracer ()
@@ -190,6 +198,8 @@ def test_announce_fails_with_missing_pid(self, mock_requests_session_put):
190
198
self .assertIn ('response payload has no pid' , log .output [0 ])
191
199
192
200
201
+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
202
+ reason = "assertLogs is not available in Python 2" )
193
203
@patch .object (requests .Session , "put" )
194
204
def test_announce_fails_with_missing_uuid (self , mock_requests_session_put ):
195
205
test_pid = 4242
@@ -201,8 +211,8 @@ def test_announce_fails_with_missing_uuid(self, mock_requests_session_put):
201
211
mock_response .status_code = 200
202
212
mock_response .content = (
203
213
'{'
204
- f ' "pid": { test_pid } '
205
- '}' )
214
+ ' "pid": "%d" '
215
+ '}' % ( test_pid ) )
206
216
mock_requests_session_put .return_value = mock_response
207
217
208
218
self .create_agent_and_setup_tracer ()
0 commit comments