44from __future__ import absolute_import
55
66import os
7+ import sys
78import logging
89import unittest
910
1011from mock import MagicMock , patch
1112
13+ import pytest
1214import requests
1315
1416from instana .agent .host import HostAgent
@@ -98,9 +100,9 @@ def test_announce_is_successful(self, mock_requests_session_put):
98100 mock_response .status_code = 200
99101 mock_response .content = (
100102 '{'
101- f ' "pid": { test_pid } , '
102- f ' "agentUuid": "{ test_agent_uuid } "'
103- '}' )
103+ ' "pid": %d , '
104+ ' "agentUuid": "%s "'
105+ '}' % ( test_pid , test_agent_uuid ) )
104106
105107 # This mocks the call to self.agent.client.put
106108 mock_requests_session_put .return_value = mock_response
@@ -117,6 +119,8 @@ def test_announce_is_successful(self, mock_requests_session_put):
117119 self .assertEqual (test_agent_uuid , payload ['agentUuid' ])
118120
119121
122+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
123+ reason = "assertLogs is not available in Python 2" )
120124 @patch .object (requests .Session , "put" )
121125 def test_announce_fails_with_non_200 (self , mock_requests_session_put ):
122126 test_pid = 4242
@@ -141,6 +145,8 @@ def test_announce_fails_with_non_200(self, mock_requests_session_put):
141145 self .assertIn ('is NOT 200' , log .output [0 ])
142146
143147
148+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
149+ reason = "assertLogs is not available in Python 2" )
144150 @patch .object (requests .Session , "put" )
145151 def test_announce_fails_with_non_json (self , mock_requests_session_put ):
146152 test_pid = 4242
@@ -164,6 +170,8 @@ def test_announce_fails_with_non_json(self, mock_requests_session_put):
164170 self .assertIn ('response is not JSON' , log .output [0 ])
165171
166172
173+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
174+ reason = "assertLogs is not available in Python 2" )
167175 @patch .object (requests .Session , "put" )
168176 def test_announce_fails_with_missing_pid (self , mock_requests_session_put ):
169177 test_pid = 4242
@@ -175,8 +183,8 @@ def test_announce_fails_with_missing_pid(self, mock_requests_session_put):
175183 mock_response .status_code = 200
176184 mock_response .content = (
177185 '{'
178- f ' "agentUuid": "{ test_agent_uuid } "'
179- '}' )
186+ ' "agentUuid": "%s "'
187+ '}' % ( test_agent_uuid ) )
180188 mock_requests_session_put .return_value = mock_response
181189
182190 self .create_agent_and_setup_tracer ()
@@ -190,6 +198,8 @@ def test_announce_fails_with_missing_pid(self, mock_requests_session_put):
190198 self .assertIn ('response payload has no pid' , log .output [0 ])
191199
192200
201+ @pytest .mark .skipif (sys .version_info [0 ] < 3 ,
202+ reason = "assertLogs is not available in Python 2" )
193203 @patch .object (requests .Session , "put" )
194204 def test_announce_fails_with_missing_uuid (self , mock_requests_session_put ):
195205 test_pid = 4242
@@ -201,8 +211,8 @@ def test_announce_fails_with_missing_uuid(self, mock_requests_session_put):
201211 mock_response .status_code = 200
202212 mock_response .content = (
203213 '{'
204- f ' "pid": { test_pid } '
205- '}' )
214+ ' "pid": "%d" '
215+ '}' % ( test_pid ) )
206216 mock_requests_session_put .return_value = mock_response
207217
208218 self .create_agent_and_setup_tracer ()
0 commit comments