-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CE-114] Add test case for user management module
Add run test case in Makefile check Add test case for user management module Change-Id: I5abbfcd6a849cb6f6ff64b5522c81b5228184a96 Signed-off-by: Haitao Yue <hightall@me.com>
- Loading branch information
Showing
13 changed files
with
205 additions
and
12 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
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,3 @@ | ||
COMPOSE_PROJECT_NAME=dashboard-test | ||
STATIC_FOLDER=themes/basic/static | ||
TEMPLATE_FOLDER=themes/basic/templates |
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,8 @@ | ||
# Copyright IBM Corp, All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
test: | ||
docker-compose up --abort-on-container-exit | ||
|
||
all: test |
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,5 @@ | ||
|
||
# Copyright IBM Corp, All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# |
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,23 @@ | ||
|
||
# Copyright IBM Corp, All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
import sys | ||
import unittest | ||
from test_user_management import UserManagementTestCase | ||
|
||
|
||
def suite(): | ||
suit = unittest.TestSuite() | ||
suit.addTest(unittest.makeSuite(UserManagementTestCase)) | ||
|
||
return suit | ||
|
||
|
||
def run(): | ||
result = unittest.TextTestRunner(verbosity=2).run(suite()) | ||
|
||
|
||
if __name__ == '__main__': | ||
run() |
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,98 @@ | ||
|
||
# Copyright IBM Corp, All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
import unittest | ||
from flask_testing import TestCase | ||
import sys | ||
import os | ||
import logging | ||
import json | ||
from faker import Factory | ||
fake = Factory.create() | ||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'src')) | ||
from dashboard import app | ||
from common import log_handler, LOG_LEVEL | ||
from resources.models import COMMON_USER | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(LOG_LEVEL) | ||
logger.addHandler(log_handler) | ||
|
||
|
||
class UserManagementTestCase(TestCase): | ||
def create_app(self): | ||
app.config['TESTING'] = True | ||
app.config['LOGIN_DISABLED'] = False | ||
return app | ||
|
||
def _login(self, username, password): | ||
return self.client.post('/api/auth/login', | ||
data=dict( | ||
username=username, | ||
password=password | ||
), | ||
follow_redirects=True) | ||
|
||
def test_server_is_up_and_running(self): | ||
response = self.client.get("/login") | ||
self.assert200(response) | ||
|
||
def test_login_required(self): | ||
response = self.client.get("/") | ||
self.assertRedirects(response, "/login") | ||
|
||
def test_valid_login(self): | ||
response = self._login("admin", "pass") | ||
response = response.data.decode("utf-8") | ||
response = json.loads(response) | ||
self.assertEqual(response.get("status", ""), "OK") | ||
|
||
def test_list_user(self): | ||
self._login("admin", "pass") | ||
raw_response = self.client.get("/api/user/list") | ||
response = raw_response.data.decode("utf-8") | ||
response = json.loads(response) | ||
users = response.get("users", {}).get("result", []) | ||
self.assertTrue(len(users) >= 1) | ||
|
||
def test_create_update_delete_user(self): | ||
self._login("admin", "pass") | ||
user_name = fake.user_name() | ||
password = fake.password() | ||
raw_response = self.client.post("/api/user/create", | ||
data=dict( | ||
username=user_name, | ||
password=password, | ||
active=True, | ||
role=COMMON_USER | ||
)) | ||
response = raw_response.data.decode("utf-8") | ||
response = json.loads(response) | ||
user_id = response.get("id", "") | ||
self.assertTrue(user_id != "") | ||
|
||
response = self._login(user_name, password) | ||
response = response.data.decode("utf-8") | ||
response = json.loads(response) | ||
self.assertEqual(response.get("status", ""), "OK") | ||
|
||
self._login("admin", "pass") | ||
|
||
new_user_name = fake.user_name() | ||
response = self.client.put("/api/user/update/%s" % user_id, | ||
data=dict( | ||
username=new_user_name, | ||
active=True, | ||
role=COMMON_USER | ||
)) | ||
response = response.data.decode("utf-8") | ||
response = json.loads(response) | ||
self.assertEqual(response.get("status", ""), "OK") | ||
|
||
response = self.client.delete("/api/user/delete/%s" % user_id) | ||
response = response.data.decode("utf-8") | ||
response = json.loads(response) | ||
self.assertEqual(response.get("status", ""), "OK") |
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 @@ | ||
# This compose file will deploy the services, and bootup a mongo server. | ||
|
||
# Copyright IBM Corp., All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Local `/opt/cello/mongo` will be used for the db storage. | ||
# dashboard: dashboard service of cello, listen on 8080 | ||
# app: app service of cello, listen on 80 | ||
# nginx: front end | ||
# mongo: mongo db | ||
|
||
version: '2' | ||
services: | ||
# cello dashboard service | ||
dashboard: | ||
build: | ||
context: ../src | ||
dockerfile: Dockerfile-dashboard | ||
image: cello-dashboard | ||
container_name: dashboard-test | ||
hostname: cello-dashboard | ||
environment: | ||
- MONGO_URL=mongodb://mongo:27017 | ||
- MONGO_DB=dev | ||
- DEBUG=False # in debug mode, service will auto-restart | ||
- LOG_LEVEL=INFO # what level log will be output | ||
- STATIC_FOLDER=$STATIC_FOLDER | ||
- TEMPLATE_FOLDER=$TEMPLATE_FOLDER | ||
expose: | ||
- "8080" | ||
volumes: # This should be removed in product env | ||
- ../src:/src | ||
- ./:/test | ||
command: bash -c "python /test/cases/run.py" | ||
|
||
# mongo database, may use others in future | ||
mongo: | ||
image: mongo:3.2 | ||
hostname: mongo | ||
container_name: mongo-test | ||
mem_limit: 2048m | ||
environment: | ||
- NO_USED=0 |
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,5 @@ | ||
|
||
# Copyright IBM Corp, All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# |