-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6d25c4
commit 6d694e9
Showing
1 changed file
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import re | ||
import unittest | ||
from unittest.mock import patch | ||
from .misc import button_array, ButtonDict | ||
|
||
class TestButtonArray(unittest.TestCase): | ||
|
||
def normalize_whitespace(self, s): | ||
return re.sub(r'\s+', ' ', s) | ||
|
||
def test_button_array_generates_correct_html(self): | ||
buttons = [ | ||
ButtonDict(name="Button 1", image="image1", url="url1"), | ||
ButtonDict(name="Button 2", image="image2", url="url2"), | ||
] | ||
expected_html = self.normalize_whitespace( | ||
'<div class="da-button-set da-field-buttons ">' | ||
'<a class="btn btn-da btn-light btn-da btn-da-custom " href="url1">' | ||
'<i class="fa fa-image1"></i> Button 1' | ||
'</a>' | ||
'<a class="btn btn-da btn-light btn-da btn-da-custom " href="url2">' | ||
'<i class="fa fa-image2"></i> Button 2' | ||
'</a>' | ||
'</div>' | ||
) | ||
self.assertEqual(self.normalize_whitespace(button_array(buttons)), expected_html) | ||
|
||
@patch('.misc.user_has_privilege', return_value=False) | ||
def test_button_array_filters_by_privilege(self, mock_privilege): | ||
buttons = [ | ||
ButtonDict(name="Button 1", image="image1", url="url1", privilege="admin"), | ||
ButtonDict(name="Button 2", image="image2", url="url2"), | ||
] | ||
expected_html = self.normalize_whitespace( | ||
'<div class="da-button-set da-field-buttons ">' | ||
'<a class="btn btn-da btn-light btn-da btn-da-custom " href="url2">' | ||
'<i class="fa fa-image2"></i> Button 2' | ||
'</a>' | ||
'</div>' | ||
) | ||
self.assertEqual(self.normalize_whitespace(button_array(buttons)), expected_html) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |