forked from shaba/openuds
some minor test fixes
This commit is contained in:
parent
15576fdc22
commit
0cf33501b6
@ -145,7 +145,7 @@ class ActorInitializeTest(rest.test.RESTTestCase):
|
||||
Test actor initialize v3 for unmanaged actor
|
||||
"""
|
||||
user_service = self.user_service_unmanaged
|
||||
actor_token = user_service.deployed_service.service.token
|
||||
actor_token: str = (user_service.deployed_service.service.token if user_service.deployed_service.service else None) or ''
|
||||
|
||||
unique_id = user_service.getUniqueId()
|
||||
|
||||
|
@ -29,26 +29,21 @@
|
||||
|
||||
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
# We use commit/rollback
|
||||
from ...utils.test import UDSTestCase
|
||||
from uds.core.ui.user_interface import (
|
||||
gui,
|
||||
UDSB,
|
||||
UDSK
|
||||
)
|
||||
from uds.core.ui.user_interface import gui, UDSB, UDSK
|
||||
import time
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class GuiTest(UDSTestCase):
|
||||
|
||||
def test_globals(self):
|
||||
self.assertEqual(UDSK, settings.SECRET_KEY[8:24].encode())
|
||||
self.assertEqual(UDSB, b'udsprotect')
|
||||
|
||||
|
||||
def test_convert_to_choices(self) -> None:
|
||||
# Several cases
|
||||
# 1. Empty list
|
||||
@ -58,14 +53,26 @@ class GuiTest(UDSTestCase):
|
||||
# 5.- A Dictionary, Keys will be used in 'id' and values in 'text'
|
||||
self.assertEqual(gui.convertToChoices([]), [])
|
||||
self.assertEqual(gui.convertToChoices('aaaa'), [{'id': 'aaaa', 'text': 'aaaa'}])
|
||||
self.assertEqual(gui.convertToChoices(['a', 'b']), [{'id': 'a', 'text': 'a'}, {'id': 'b', 'text': 'b'}])
|
||||
self.assertEqual(gui.convertToChoices({'a': 'b', 'c': 'd'}), [{'id': 'a', 'text': 'b'}, {'id': 'c', 'text': 'd'}])
|
||||
self.assertEqual(gui.convertToChoices({'a': 'b', 'c': 'd'}), [{'id': 'a', 'text': 'b'}, {'id': 'c', 'text': 'd'}])
|
||||
self.assertEqual(
|
||||
gui.convertToChoices(['a', 'b']),
|
||||
[{'id': 'a', 'text': 'a'}, {'id': 'b', 'text': 'b'}],
|
||||
)
|
||||
self.assertEqual(
|
||||
gui.convertToChoices({'a': 'b', 'c': 'd'}),
|
||||
[{'id': 'a', 'text': 'b'}, {'id': 'c', 'text': 'd'}],
|
||||
)
|
||||
self.assertEqual(
|
||||
gui.convertToChoices({'a': 'b', 'c': 'd'}),
|
||||
[{'id': 'a', 'text': 'b'}, {'id': 'c', 'text': 'd'}],
|
||||
)
|
||||
# Expect an exception if we pass a list of dictionaries without id or text
|
||||
self.assertRaises(ValueError, gui.convertToChoices, [{'a': 'b', 'c': 'd'}])
|
||||
# Also if we pass a list of dictionaries with id and text, but not all of them
|
||||
self.assertRaises(ValueError, gui.convertToChoices, [{'id': 'a', 'text': 'b'}, {'id': 'c', 'text': 'd'}, {'id': 'e'}])
|
||||
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
gui.convertToChoices,
|
||||
[{'id': 'a', 'text': 'b'}, {'id': 'c', 'text': 'd'}, {'id': 'e'}],
|
||||
)
|
||||
|
||||
def test_convert_to_list(self) -> None:
|
||||
# Several cases
|
||||
@ -79,10 +86,15 @@ class GuiTest(UDSTestCase):
|
||||
|
||||
def test_choice_image(self) -> None:
|
||||
# id, text, and base64 image
|
||||
self.assertEqual(gui.choiceImage('id', 'text', 'image'), {'id': 'id', 'text': 'text', 'img': 'image'})
|
||||
self.assertEqual(
|
||||
gui.choiceImage('id', 'text', 'image'),
|
||||
{'id': 'id', 'text': 'text', 'img': 'image'},
|
||||
)
|
||||
|
||||
def test_to_bool(self) -> None:
|
||||
for val in ('true', 'True', 'TRUE', 'yes', 'Yes', 'YES', '1'):
|
||||
self.assertTrue(gui.toBool(val), 'Failed to convert {} to True'.format(val))
|
||||
for val in ('false', 'False', 'FALSE', 'no', 'No', 'NO', '0'):
|
||||
self.assertFalse(gui.toBool(val), 'Failed to convert {} to False'.format(val))
|
||||
self.assertFalse(
|
||||
gui.toBool(val), 'Failed to convert {} to False'.format(val)
|
||||
)
|
||||
|
@ -44,7 +44,6 @@ if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
|
||||
|
||||
|
||||
class WebLoginLogoutTest(test.WEBTestCase):
|
||||
"""
|
||||
Test WEB login and logout
|
||||
@ -77,8 +76,11 @@ class WebLoginLogoutTest(test.WEBTestCase):
|
||||
# Add users to some groups, ramdomly
|
||||
for user in users + admins + stafs:
|
||||
for group in random.sample(
|
||||
groups, random.randint(1, len(groups))# nosec: Simple test, not strong cryptograde needed
|
||||
):
|
||||
groups,
|
||||
random.randint(
|
||||
1, len(groups)
|
||||
), # nosec: Simple test, not strong cryptograde needed
|
||||
):
|
||||
user.groups.add(group)
|
||||
|
||||
# All users, admin and staff must be able to login
|
||||
@ -92,9 +94,7 @@ class WebLoginLogoutTest(test.WEBTestCase):
|
||||
response = self.do_login(up[0], up[1], auth.uuid)
|
||||
# Now invoke logout
|
||||
response = typing.cast('HttpResponse', self.client.get('/uds/page/logout'))
|
||||
self.assertRedirects(
|
||||
response, reverse('page.login'), status_code=302
|
||||
)
|
||||
self.assertRedirects(response, reverse('page.login'), status_code=302)
|
||||
# Ensures a couple of logs are created for every operation
|
||||
# Except for root, that has no user associated on db
|
||||
if up[0] is not root and up[1] is not rootpass: # root user is last one
|
||||
|
Loading…
x
Reference in New Issue
Block a user