def test_get_object_offset_marker(self, mock_get): with open(self.objects_json_file) as j: object_json = json.load(j) # Create mock response object, with the json function that returns object_json mock_response = Mock() mock_response.json.return_value = object_json # Assign our mock response as the return_value of our patched function mock_get.return_value = mock_response mock_get.return_value.status_code = requests.codes.ok swift = Swift("1234567890", "http://fake.com", "container", 100) self.assertEqual(swift.get_object_offset_marker(100), "0055.txt")
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
def test_get_objects(self, mock_get): with open(self.objects_json_file) as j: object_json = json.load(j) # Create mock response object, with the json function that returns object_json mock_response = Mock() mock_response.json.return_value = object_json # Assign our mock response as the return_value of our patched function mock_get.return_value = mock_response mock_get.return_value.status_code = requests.codes.ok swift = Swift("1234567890", "http://fake.com", "container", 100) swift.get_objects() object_list = "" for count in range(1, 56): if count is not 15 and count is not 30 and count is not 45: object_list += "container/00%02d.txt\n" % count self.assertEqual(swift.object_list, object_list)