Add functional and unit tests

Updated existing tests to support the
ReceptorAddress model

- cannot peer to self
- cannot peer to node that is already peered to me
- cannot peer to node more than once (via 2+ addresses)
- cannot set is_internal True

Other changes:
Change post save signal to only call
schedule_write_receptor_config() when an actual change is detected.

Make functional tests more robust by
checking for specific validation error in the
response.

I.e. instead of just checking for 400, just for 400
and that the error message corresponds to the
validation we are testing for.

Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
Seth Foster
2023-11-14 13:39:24 -05:00
committed by Seth Foster
parent 5385eb0fb3
commit d1cacf64de
5 changed files with 199 additions and 119 deletions

View File

@@ -5652,13 +5652,19 @@ class InstanceSerializer(BaseSerializer):
if self.instance and self.instance.receptor_addresses.filter(id__in=peers_ids).exists():
raise serializers.ValidationError(_("Instance cannot peer to its own address."))
# cannot peer to an instance that is already peered to this instance
if self.instance and self.instance.receptor_addresses.all().exists():
instance_addresses = set(self.instance.receptor_addresses.all())
# cannot peer to an instance that is already peered to this instance
for p in attrs.get('peers', []):
if set(p.instance.peers.all()) & instance_addresses:
raise serializers.ValidationError(_(f"Instance {p.instance.hostname} is already peered to this instance."))
# cannot peer to instance more than once
# compare length of set to original list to check for duplicates
peers_instances = [p.instance for p in attrs.get('peers', [])]
if len(set(peers_instances)) != len(peers_instances):
raise serializers.ValidationError(_("Cannot peer to the same instance more than once."))
return super().validate(attrs)
def validate_node_type(self, value):