Repository: ionos-cloud/dim (language: python)

Issue:
tests/allocator_test.py `AllocatorTest::test_delegation_not_subnet`FAILED
>FAILED tests/allocator_test.py::AllocatorTest::test_delegation_not_subnet - sqlalchemy.exc.IntegrityError: (MySQLdb._exceptions.IntegrityError) (1062, "Duplicate entry '83076749736557242056487941267521536-64-384' for key 'address'")

`ndcli pool <pool> get delegation` currently does not catch when the user tries to get a delegation with the same size as the pool's subnet, it fails in the DB due to a unique constraint:
```
ndcli modify pool pool get delegation 64
ERROR - (MySQLdb._exceptions.IntegrityError) (1062, "Duplicate entry '83076749736557242056487941267521536-64-941' for key 'address'")
[SQL: INSERT INTO ipblock (created, created_by, modified, modified_by, version, address, prefix, priority, gateway, parent_id, status_id, ippool_id, vlan_id, layer3domain_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)]
[parameters: (datetime.datetime(2022, 2, 8, 15, 51, 40, 633610), 'admin', datetime.datetime(2022, 2, 8, 15, 51, 40, 633628), 'admin', 6, 83076749736557242056487941267521536, 64, None, None, None, 7520, None, None, 941)]
(Background on this error at: https://sqlalche.me/e/14/gkpj)
```
Test:
https://github.com/1and1/dim/blob/0e951965b65007c3ecbfcc15e6544ccfc635b9a7/dim-testsuite/tests/allocator_test.py#L150-L156


Discussion / hints:

Fix patch:
diff --git a/dim/requirements-dev.txt b/dim/requirements-dev.txt
index 853cd76a..c798bfe2 100644
--- a/dim/requirements-dev.txt
+++ b/dim/requirements-dev.txt
@@ -1,6 +1,5 @@
 nose~=1.3
 nose-ignore-docstring~=0.2
-click~=7.1
-pytest~=6.2
+pytest~=7.1
 pytest-cov~=3.0
 Sphinx~=4.4


Test patch:
diff --git a/dim-testsuite/tests/allocator_test.py b/dim-testsuite/tests/allocator_test.py
index 20a1756f..855c44f3 100644
--- a/dim-testsuite/tests/allocator_test.py
+++ b/dim-testsuite/tests/allocator_test.py
@@ -1,4 +1,6 @@
 from tests.util import RPCTest
+from sqlalchemy.exc import IntegrityError
+import pytest
 
 
 def ips(d):
@@ -147,6 +149,7 @@ def test_priorities(self):
         self.r.subnet_set_priority('192.168.1.0/24', 1)
         assert self.r.ippool_get_ip('testpool')['ip'] == '192.168.1.1'
 
+    @pytest.mark.xfail(raises=IntegrityError, reason='https://github.com/1and1/dim/issues/205')
     def test_delegation_not_subnet(self):
         self.r.ipblock_create('10::/32', status='Container')
         self.r.ippool_create('pool')