-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not allow tag and badge to have same value (#106)
* Do not allow tag and badge to have same value * Update * Added unit test
- Loading branch information
1 parent
83a165a
commit 6c0dc13
Showing
2 changed files
with
62 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import unittest | ||
from http import HTTPStatus | ||
|
||
from mock import patch, Mock | ||
|
||
from tests.unit.test_basics import BasicTestCase | ||
|
||
TABLE_NAME = 'magic' | ||
BADGE_NAME = 'foo' | ||
TAG_NAME = 'bar' | ||
|
||
|
||
class TableTagAPI(BasicTestCase): | ||
def setUp(self) -> None: | ||
super().setUp() | ||
|
||
self.mock_client = patch('metadata_service.api.table.get_proxy_client') | ||
self.mock_proxy = self.mock_client.start().return_value = Mock() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
|
||
self.mock_client.stop() | ||
|
||
def test_block_tag_on_reserved_badge_value(self) -> None: | ||
self.app.config['WHITELIST_BADGES'] = [BADGE_NAME] | ||
response = self.app.test_client().put(f'/table/{TABLE_NAME}/tag/{BADGE_NAME}') | ||
|
||
self.assertEqual(response.status_code, HTTPStatus.CONFLICT) | ||
|
||
def test_tag_on_unreserved_badge_value(self) -> None: | ||
self.app.config['WHITELIST_BADGES'] = [BADGE_NAME] | ||
response = self.app.test_client().put(f'/table/{TABLE_NAME}/tag/{TAG_NAME}') | ||
|
||
self.assertEqual(response.status_code, HTTPStatus.OK) | ||
|
||
def test_badge_on_reserved_badge_value(self) -> None: | ||
self.app.config['WHITELIST_BADGES'] = [BADGE_NAME] | ||
response = self.app.test_client().put(f'/table/{TABLE_NAME}/tag/{BADGE_NAME}?tag_type=badge') | ||
|
||
self.assertEqual(response.status_code, HTTPStatus.OK) | ||
|
||
def test_badge_on_unreserved_badge_value(self) -> None: | ||
self.app.config['WHITELIST_BADGES'] = [BADGE_NAME] | ||
response = self.app.test_client().put(f'/table/{TABLE_NAME}/tag/{TAG_NAME}?tag_type=badge') | ||
|
||
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |