def test_get_auth_token(self, mock_get): json_data = {"storage": {"default": "local", "local": "https://fake.com:443/v1/AUTH_fake"}} # Create mock response object, with the json function that returns json_data mock_response = Mock() mock_response.json.return_value = json_data # Assign our mock response as the return_value of our patched function mock_get.return_value = mock_response mock_get.return_value.headers = {"x-auth-token": "1234567890"} mock_get.return_value.status_code = requests.codes.ok swauth = Swauth("http://fake.com", "fake_project", "fake_user", "fake_pass") swauth.get_auth_token() self.assertEqual(swauth.auth_token, "1234567890") self.assertEqual(swauth.storage_url, "https://fake.com:443/v1/AUTH_fake")
def worker(container, limit, thread_num): count = 0 try: # Keep looping until either swift returns an error or bulk delete returns a bad request # response while True: # Get a new auth token every 20 times through the loop if count % 20 is 0: # Use the Swauth class for v1.0 auth urls if "v1.0" in variables.os_auth_url: auth = Swauth( variables.os_auth_url, variables.os_tenant_name, variables.os_username, variables.os_password ) else: print "Invalid os_auth_url" return auth.get_auth_token() swift = Swift(auth.auth_token, auth.storage_url, container, limit, thread_num) response = swift.bulk_delete_objects() print "(%s) %s" % (thread_num, response) if swift.status_code != requests.codes.ok: print "(%s) (%s) Thread Exited" % (swift.status_code, thread_num) return if "400 Bad Request" in response: print "(%s) (400 Bad Request) Thread Exited" % thread_num return count += 1 except KeyboardInterrupt: return return