mirror of
https://github.com/VinylDNS/vinyldns
synced 2025-08-29 05:18:08 +00:00
add tests
This commit is contained in:
parent
3fe6b91942
commit
55e093d25d
@ -3803,7 +3803,7 @@ def test_create_batch_delete_record_that_does_not_exists_completes(shared_zone_t
|
|||||||
ok_zone_name = shared_zone_test_context.ok_zone["name"]
|
ok_zone_name = shared_zone_test_context.ok_zone["name"]
|
||||||
|
|
||||||
batch_change_input = {
|
batch_change_input = {
|
||||||
"comments": "test delete record failures",
|
"comments": "test delete record",
|
||||||
"changes": [
|
"changes": [
|
||||||
get_change_A_AAAA_json(f"delete-non-existent-record.{ok_zone_name}", change_type="DeleteRecordSet")
|
get_change_A_AAAA_json(f"delete-non-existent-record.{ok_zone_name}", change_type="DeleteRecordSet")
|
||||||
]
|
]
|
||||||
@ -3818,6 +3818,40 @@ def test_create_batch_delete_record_that_does_not_exists_completes(shared_zone_t
|
|||||||
assert_successful_change_in_error_response(response["changes"][0], input_name=f"delete-non-existent-record.{ok_zone_name}", record_data="1.1.1.1", change_type="DeleteRecordSet")
|
assert_successful_change_in_error_response(response["changes"][0], input_name=f"delete-non-existent-record.{ok_zone_name}", record_data="1.1.1.1", change_type="DeleteRecordSet")
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_batch_delete_record_data_that_does_not_exists_completes(shared_zone_test_context):
|
||||||
|
"""
|
||||||
|
Test delete record set completes for non-existent record data
|
||||||
|
"""
|
||||||
|
client = shared_zone_test_context.ok_vinyldns_client
|
||||||
|
ok_zone_name = shared_zone_test_context.ok_zone["name"]
|
||||||
|
batch_change_input = {
|
||||||
|
"comments": "this is optional",
|
||||||
|
"changes": [
|
||||||
|
get_change_A_AAAA_json(f"delete-non-existent-record-data.{ok_zone_name}", address="4.5.6.7"),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
batch_change_delete_input = {
|
||||||
|
"comments": "test delete record",
|
||||||
|
"changes": [
|
||||||
|
get_change_A_AAAA_json(f"delete-non-existent-record-data.{ok_zone_name}", address="1.1.1.1", change_type="DeleteRecordSet")
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
to_delete = []
|
||||||
|
try:
|
||||||
|
result = client.create_batch_change(batch_change_input, status=202)
|
||||||
|
completed_batch = client.wait_until_batch_change_completed(result)
|
||||||
|
record_set_list = [(change["zoneId"], change["recordSetId"]) for change in completed_batch["changes"]]
|
||||||
|
to_delete = set(record_set_list)
|
||||||
|
response = client.create_batch_change(batch_change_delete_input, status=202)
|
||||||
|
get_batch = client.get_batch_change(response["id"])
|
||||||
|
assert_that(get_batch["changes"][0]["systemMessage"], is_("Record data entered does not exist. " +
|
||||||
|
"No further action is required."))
|
||||||
|
assert_successful_change_in_error_response(response["changes"][0], input_name=f"delete-non-existent-record-data.{ok_zone_name}", record_data="1.1.1.1", change_type="DeleteRecordSet")
|
||||||
|
finally:
|
||||||
|
clear_zoneid_rsid_tuple_list(to_delete, client)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.serial
|
@pytest.mark.serial
|
||||||
def test_create_batch_delete_record_access_checks(shared_zone_test_context):
|
def test_create_batch_delete_record_access_checks(shared_zone_test_context):
|
||||||
"""
|
"""
|
||||||
|
@ -26,7 +26,7 @@ import vinyldns.api.domain.batch.BatchTransformations._
|
|||||||
import vinyldns.api.domain.batch.BatchTransformations.LogicalChangeType._
|
import vinyldns.api.domain.batch.BatchTransformations.LogicalChangeType._
|
||||||
import vinyldns.api.engine.TestMessageQueue
|
import vinyldns.api.engine.TestMessageQueue
|
||||||
import vinyldns.api.repository._
|
import vinyldns.api.repository._
|
||||||
import vinyldns.core.Messages.nonExistentRecordDeleteMessage
|
import vinyldns.core.Messages.{nonExistentRecordDataDeleteMessage, nonExistentRecordDeleteMessage}
|
||||||
import vinyldns.core.TestMembershipData.okUser
|
import vinyldns.core.TestMembershipData.okUser
|
||||||
import vinyldns.core.TestRecordSetData._
|
import vinyldns.core.TestRecordSetData._
|
||||||
import vinyldns.core.TestZoneData.{okZone, _}
|
import vinyldns.core.TestZoneData.{okZone, _}
|
||||||
@ -170,6 +170,14 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers {
|
|||||||
makeDeleteRRSetChangeForValidation("DoesNotExistToDelete", A, Some(nonExistentRecordDeleteMessage))
|
makeDeleteRRSetChangeForValidation("DoesNotExistToDelete", A, Some(nonExistentRecordDeleteMessage))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val singleChangesOneDataDelete = List(
|
||||||
|
makeSingleDeleteRRSetChange("DataDoesNotExistToDelete", A, okZone, Some(nonExistentRecordDataDeleteMessage))
|
||||||
|
)
|
||||||
|
|
||||||
|
private val changeForValidationOneDataDelete = List(
|
||||||
|
makeDeleteRRSetChangeForValidation("DataDoesNotExistToDelete", A, Some(nonExistentRecordDataDeleteMessage))
|
||||||
|
)
|
||||||
|
|
||||||
private val singleChangesOneBad = List(
|
private val singleChangesOneBad = List(
|
||||||
makeSingleAddChange("one", AData("1.1.1.1")),
|
makeSingleAddChange("one", AData("1.1.1.1")),
|
||||||
makeSingleAddChange("two", AData("1.1.1.2")),
|
makeSingleAddChange("two", AData("1.1.1.2")),
|
||||||
@ -580,6 +588,41 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers {
|
|||||||
savedBatch shouldBe Some(returnedBatch)
|
savedBatch shouldBe Some(returnedBatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"set status to pending when deleting a record data that does not exist" in {
|
||||||
|
val batchWithBadChange =
|
||||||
|
BatchChange(
|
||||||
|
okUser.id,
|
||||||
|
okUser.userName,
|
||||||
|
None,
|
||||||
|
Instant.now.truncatedTo(ChronoUnit.MILLIS),
|
||||||
|
singleChangesOneDataDelete,
|
||||||
|
approvalStatus = BatchChangeApprovalStatus.AutoApproved
|
||||||
|
)
|
||||||
|
val result =
|
||||||
|
underTest
|
||||||
|
.sendBatchForProcessing(
|
||||||
|
batchWithBadChange,
|
||||||
|
existingZones,
|
||||||
|
ChangeForValidationMap(changeForValidationOneDataDelete.map(_.validNel), existingRecordSets),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
.value.unsafeRunSync().toOption.get
|
||||||
|
|
||||||
|
val returnedBatch = result.batchChange
|
||||||
|
|
||||||
|
// validate completed status returned
|
||||||
|
val receivedChange = returnedBatch.changes(0)
|
||||||
|
receivedChange.status shouldBe SingleChangeStatus.Pending
|
||||||
|
receivedChange.recordChangeId shouldBe None
|
||||||
|
receivedChange.systemMessage shouldBe Some(nonExistentRecordDataDeleteMessage)
|
||||||
|
returnedBatch.changes(0) shouldBe singleChangesOneDataDelete(0).copy(systemMessage = Some(nonExistentRecordDataDeleteMessage), status = SingleChangeStatus.Pending)
|
||||||
|
|
||||||
|
// check the update has been made in the DB
|
||||||
|
val savedBatch: Option[BatchChange] =
|
||||||
|
batchChangeRepo.getBatchChange(batchWithBadChange.id).unsafeRunSync()
|
||||||
|
savedBatch shouldBe Some(returnedBatch)
|
||||||
|
}
|
||||||
|
|
||||||
"return error if an unsupported record is received" in {
|
"return error if an unsupported record is received" in {
|
||||||
val batchChangeUnsupported =
|
val batchChangeUnsupported =
|
||||||
BatchChange(
|
BatchChange(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user