-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
YDA-5506 Extract utility functions for Yoda names
Move utility functions for names of Yoda entities (e.g. categories, user names, etc) to utils and add unit tests. This also standardizes the function for determining whether a user is internal or external between the group manager and the statistics module.
- Loading branch information
Showing
6 changed files
with
63 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Unit tests for the yoda_names utils functions""" | ||
|
||
__copyright__ = 'Copyright (c) 2023, Utrecht University' | ||
__license__ = 'GPLv3, see LICENSE' | ||
|
||
import sys | ||
from unittest import TestCase | ||
|
||
sys.path.append('../util') | ||
|
||
from yoda_names import _is_internal_user, is_email_username, is_valid_category, is_valid_groupname, is_valid_subcategory | ||
|
||
|
||
class UtilYodaNamesTest(TestCase): | ||
|
||
def test_is_valid_category(self): | ||
self.assertEquals(is_valid_category(""), False) | ||
self.assertEquals(is_valid_category("foo"), True) | ||
self.assertEquals(is_valid_category("foo123"), True) | ||
self.assertEquals(is_valid_category("foo-bar"), True) | ||
self.assertEquals(is_valid_category("foo_bar"), True) | ||
|
||
def test_is_valid_subcategory(self): | ||
self.assertEquals(is_valid_subcategory(""), False) | ||
self.assertEquals(is_valid_subcategory("foo"), True) | ||
self.assertEquals(is_valid_subcategory("foo123"), True) | ||
self.assertEquals(is_valid_subcategory("foo-bar"), True) | ||
self.assertEquals(is_valid_subcategory("foo_bar"), True) | ||
|
||
def test_is_valid_groupname(self): | ||
self.assertEquals(is_valid_groupname(""), False) | ||
self.assertEquals(is_valid_groupname("foo"), True) | ||
self.assertEquals(is_valid_groupname("foo123"), True) | ||
self.assertEquals(is_valid_groupname("foo-bar"), True) | ||
self.assertEquals(is_valid_groupname("foo_bar"), False) | ||
|
||
def test_is_email_username(self): | ||
self.assertEquals(is_email_username("peter"), False) | ||
self.assertEquals(is_email_username("[email protected]"), True) | ||
|
||
def test_is_internal_user(self): | ||
self.assertEquals(_is_internal_user("peter", ["uu.nl"]), False) | ||
self.assertEquals(_is_internal_user("[email protected]", ["uu.nl"]), True) | ||
self.assertEquals(_is_internal_user("[email protected]", ["uu.nl"]), False) | ||
self.assertEquals(_is_internal_user("[email protected]", ["uu.nl"]), False) | ||
self.assertEquals(_is_internal_user("[email protected]", ["buu.nl"]), False) | ||
self.assertEquals(_is_internal_user("[email protected]", ["*.uu.nl"]), True) | ||
self.assertEquals(_is_internal_user("[email protected]", ["*.uu.nl"]), False) | ||
self.assertEquals(_is_internal_user("[email protected]", ["*.uu.nl"]), False) | ||
self.assertEquals(_is_internal_user("[email protected]", ["*.uu.nl"]), True) | ||
self.assertEquals(_is_internal_user("[email protected]", ["*.cs.uu.nl"]), True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters