Skip to content

Commit

Permalink
fix kiwitcms#1620 add automated tests for missing coverage in tcms.rp…
Browse files Browse the repository at this point in the history
…c.api.auth
  • Loading branch information
iamabhishek0 authored and asankov committed Dec 2, 2020
1 parent 65361a7 commit ae7965b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tcms/rpc/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def login(username, password, **kwargs): # pylint: disable=missing-api-permissi
Login into Kiwi TCMS.
:param username: A Kiwi TCMS login or email address
:param username: A Kiwi TCMS login
:type username: str
:param password: The password
:type password: str
Expand Down
36 changes: 36 additions & 0 deletions tcms/rpc/tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
# pylint: disable=attribute-defined-outside-init

from xmlrpc.client import Fault as XmlRPCFault, ProtocolError
from tcms.rpc.tests.utils import APITestCase


class TestAuthLogin(APITestCase):
"""Test Auth.login method"""

def _fixture_setup(self):
super()._fixture_setup()

self.rpc_client.Auth.logout()

def test_login_with_username(self):
sesson_id = self.rpc_client.Auth.login(self.api_user.username, "api-testing")
self.assertIsNotNone(sesson_id)

def test_login_without_password(self):
with self.assertRaisesRegex(XmlRPCFault, "Username and password is required"):
self.rpc_client.Auth.login(self.api_user.username, "")

def test_login_with_incorrect_password(self):
with self.assertRaisesRegex(XmlRPCFault, "Wrong username or password"):
self.rpc_client.Auth.login(self.api_user.username, "kiwi-password")


class TestAuthLogout(APITestCase):
"""Test Auth.logout method"""

def test_logout(self):
self.rpc_client.Auth.logout()
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):
# this method requires a logged-in user
self.rpc_client.Bug.details("http://some.url")

0 comments on commit ae7965b

Please sign in to comment.