Fix managed roles and reserved groups bugs in Discord Service and more

This commit is contained in:
Erik Kalkoken
2022-07-18 09:12:32 +00:00
committed by Ariel Rin
parent 22a270aedb
commit d7fabccddd
39 changed files with 2972 additions and 1657 deletions

View File

@@ -0,0 +1,35 @@
import socket
from django.test import TestCase
class SocketAccessError(Exception):
"""Error raised when a test script accesses the network"""
class NoSocketsTestCase(TestCase):
"""Variation of Django's TestCase class that prevents any network use.
Example:
.. code-block:: python
class TestMyStuff(NoSocketsTestCase):
def test_should_do_what_i_need(self):
...
"""
@classmethod
def setUpClass(cls):
cls.socket_original = socket.socket
socket.socket = cls.guard
return super().setUpClass()
@classmethod
def tearDownClass(cls):
socket.socket = cls.socket_original
return super().tearDownClass()
@staticmethod
def guard(*args, **kwargs):
raise SocketAccessError("Attempted to access network")

View File

@@ -0,0 +1,9 @@
import requests
from allianceauth.utils.testing import NoSocketsTestCase, SocketAccessError
class TestNoSocketsTestCase(NoSocketsTestCase):
def test_raises_exception_on_attempted_network_access(self):
with self.assertRaises(SocketAccessError):
requests.get("https://www.google.com")