*: ensure unittests wait on tasks
This commit is contained in:
parent
7154f19668
commit
3b9524cdfc
|
@ -14,5 +14,5 @@ class TestTasks(TestCase):
|
||||||
"""Test Token cleanup task"""
|
"""Test Token cleanup task"""
|
||||||
Token.objects.create(expires=now(), user=get_anonymous_user())
|
Token.objects.create(expires=now(), user=get_anonymous_user())
|
||||||
self.assertEqual(Token.objects.all().count(), 1)
|
self.assertEqual(Token.objects.all().count(), 1)
|
||||||
clean_expired_models.delay()
|
clean_expired_models.delay().get()
|
||||||
self.assertEqual(Token.objects.all().count(), 0)
|
self.assertEqual(Token.objects.all().count(), 0)
|
||||||
|
|
|
@ -18,7 +18,7 @@ LOGGER = get_logger()
|
||||||
def save_ip_reputation(self: MonitoredTask):
|
def save_ip_reputation(self: MonitoredTask):
|
||||||
"""Save currently cached reputation to database"""
|
"""Save currently cached reputation to database"""
|
||||||
objects_to_update = []
|
objects_to_update = []
|
||||||
for key, score in cache.get_many(CACHE_KEY_IP_PREFIX + "*").items():
|
for key, score in cache.get_many(cache.keys(CACHE_KEY_IP_PREFIX + "*")).items():
|
||||||
remote_ip = key.replace(CACHE_KEY_IP_PREFIX, "")
|
remote_ip = key.replace(CACHE_KEY_IP_PREFIX, "")
|
||||||
rep, _ = IPReputation.objects.get_or_create(ip=remote_ip)
|
rep, _ = IPReputation.objects.get_or_create(ip=remote_ip)
|
||||||
rep.score = score
|
rep.score = score
|
||||||
|
@ -33,7 +33,7 @@ def save_ip_reputation(self: MonitoredTask):
|
||||||
def save_user_reputation(self: MonitoredTask):
|
def save_user_reputation(self: MonitoredTask):
|
||||||
"""Save currently cached reputation to database"""
|
"""Save currently cached reputation to database"""
|
||||||
objects_to_update = []
|
objects_to_update = []
|
||||||
for key, score in cache.get_many(CACHE_KEY_USER_PREFIX + "*").items():
|
for key, score in cache.get_many(cache.keys(CACHE_KEY_USER_PREFIX + "*")).items():
|
||||||
username = key.replace(CACHE_KEY_USER_PREFIX, "")
|
username = key.replace(CACHE_KEY_USER_PREFIX, "")
|
||||||
users = User.objects.filter(username=username)
|
users = User.objects.filter(username=username)
|
||||||
if not users.exists():
|
if not users.exists():
|
||||||
|
|
|
@ -33,7 +33,7 @@ class TestReputationPolicy(TestCase):
|
||||||
# Test value in cache
|
# Test value in cache
|
||||||
self.assertEqual(cache.get(CACHE_KEY_IP_PREFIX + self.test_ip), -1)
|
self.assertEqual(cache.get(CACHE_KEY_IP_PREFIX + self.test_ip), -1)
|
||||||
# Save cache and check db values
|
# Save cache and check db values
|
||||||
save_ip_reputation.delay()
|
save_ip_reputation.delay().get()
|
||||||
self.assertEqual(IPReputation.objects.get(ip=self.test_ip).score, -1)
|
self.assertEqual(IPReputation.objects.get(ip=self.test_ip).score, -1)
|
||||||
|
|
||||||
def test_user_reputation(self):
|
def test_user_reputation(self):
|
||||||
|
@ -43,7 +43,7 @@ class TestReputationPolicy(TestCase):
|
||||||
# Test value in cache
|
# Test value in cache
|
||||||
self.assertEqual(cache.get(CACHE_KEY_USER_PREFIX + self.test_username), -1)
|
self.assertEqual(cache.get(CACHE_KEY_USER_PREFIX + self.test_username), -1)
|
||||||
# Save cache and check db values
|
# Save cache and check db values
|
||||||
save_user_reputation.delay()
|
save_user_reputation.delay().get()
|
||||||
self.assertEqual(UserReputation.objects.get(user=self.user).score, -1)
|
self.assertEqual(UserReputation.objects.get(user=self.user).score, -1)
|
||||||
|
|
||||||
def test_policy(self):
|
def test_policy(self):
|
||||||
|
|
|
@ -48,4 +48,4 @@ class LDAPSyncTests(TestCase):
|
||||||
@patch("passbook.sources.ldap.models.LDAPSource.connection", LDAP_CONNECTION_PATCH)
|
@patch("passbook.sources.ldap.models.LDAPSource.connection", LDAP_CONNECTION_PATCH)
|
||||||
def test_tasks(self):
|
def test_tasks(self):
|
||||||
"""Test Scheduled tasks"""
|
"""Test Scheduled tasks"""
|
||||||
ldap_sync_all.delay()
|
ldap_sync_all.delay().get()
|
||||||
|
|
|
@ -127,7 +127,7 @@ class TestConsentStage(TestCase):
|
||||||
).exists()
|
).exists()
|
||||||
)
|
)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
clean_expired_models.delay()
|
clean_expired_models.delay().get()
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
UserConsent.objects.filter(
|
UserConsent.objects.filter(
|
||||||
user=self.user, application=self.application
|
user=self.user, application=self.application
|
||||||
|
|
Reference in New Issue