Skip to content

Commit

Permalink
Add Unit Tests for WSClient
Browse files Browse the repository at this point in the history
Ref #279
  • Loading branch information
algorys committed Apr 11, 2018
1 parent d2b44a8 commit 0eb6923
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
4 changes: 2 additions & 2 deletions alignak_app/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def patch(self, endpoint, data, headers):

return request

def acknowledge(self, item, sticky, notify, comment):
def acknowledge(self, item, sticky, notify, comment): # pragma: no cover
"""
Prepare data for acknowledge and POST on backend API or WS if available
Expand Down Expand Up @@ -303,7 +303,7 @@ def acknowledge(self, item, sticky, notify, comment):
return request

# pylint: disable=too-many-arguments
def downtime(self, item, fixed, duration, start_stamp, end_stamp, comment):
def downtime(self, item, fixed, duration, start_stamp, end_stamp, comment): # pragma: no cover
"""
Prepare data for downtime and POST on backend API or WS if available
Expand Down
4 changes: 2 additions & 2 deletions alignak_app/backend/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def login(self, token):
logger.warning(msg)
logger.debug(exp)

def get(self, endpoint, params):
def get(self, endpoint, params): # pragma: no cover
"""
GET on alignak Backend Web Service
Expand Down Expand Up @@ -108,7 +108,7 @@ def get(self, endpoint, params):

return request.json()

def post(self, endpoint, params=None):
def post(self, endpoint, params=None): # pragma: no cover
"""
Post on alignak Backend Web Service
Expand Down
2 changes: 1 addition & 1 deletion test/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TestAppBackend(unittest2.TestCase):
This file test methods of AppBackend class
"""

# Create config for all methods.
# Init config for all methods.
settings.init_config()
host_id = '59c4e40635d17b8e0c6accae'
hostname = 'cogny'
Expand Down
54 changes: 54 additions & 0 deletions test/test_ws_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2018:
# Matthieu Estrada, ttamalfor@gmail.com
#
# This file is part of (AlignakApp).
#
# (AlignakApp) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (AlignakApp) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (AlignakApp). If not, see <http://www.gnu.org/licenses/>.

import unittest2

from alignak_app.backend.ws_client import WSClient
from alignak_app.utils.config import settings


class TestWSClient(unittest2.TestCase):
"""
This file test methods of WSClient class
"""

# Init config for all methods.
settings.init_config()

def test_initialize_ws_client(self):
"""Initialize Web Service"""

under_test = WSClient()

self.assertFalse(under_test.token)
self.assertFalse(under_test.ws_backend)
self.assertIsNone(under_test.auth)

def test_login_ws_with_wrong_token(self):
"""Login to WS with Wrong Token"""

under_test = WSClient()
under_test.login('wrong_token')

self.assertFalse(under_test.token)
self.assertEqual('http://demo.alignak.net:8888', under_test.ws_backend)
# WS is not auth
self.assertIsNone(under_test.auth)

0 comments on commit 0eb6923

Please sign in to comment.