<reponame>jalanb/portals
import unittest

import requests_mock

from portals.wwits.apis.rest_services import GTAccess, set_environment


set_environment("QA")


@requests_mock.Mocker()
class TestStartSession(unittest.TestCase):
    def setUp(self):
        self.user_id = "rsaxena"
        self.password = "<PASSWORD>"
        self.url = (
            "http://hstapptest.ad.wwts.com/WWITS-RESTServer/"
            "Access/Session/v1/QA/WMP/Start"
        )

    def test_success(self, mocker):
        mock_resp = {
            "Parms": {
                "UserID": "rsaxena",
                "Version": "v1",
                "Env": "QA",
                "Source": "WMP",
                "Session": 33187082,
                "ExpireDays": 999,
                "RC": 0,
                "ResultMsg": "Processed successfully",
            }
        }
        mocker.register_uri("GET", self.url, json=mock_resp)
        actual = GTAccess().start_session(user=self.user_id, password=self.password)
        self.assertTrue(actual.success)

    def test_fail(self, mocker):
        mock_resp = {
            "Parms": {
                "UserID": "rsaxena",
                "Version": "v1",
                "Env": "QA",
                "Source": "WMP",
                "Session": 33187082,
                "ExpireDays": 999,
                "RC": 1000,
                "ResultMsg": "WWTS not available",
            }
        }
        mocker.register_uri("GET", self.url, json=mock_resp)
        actual = GTAccess().start_session(user=self.user_id, password=self.password)
        self.assertTrue(actual.fail)

    def test_error_msg(self, mocker):
        mock_resp = {
            "Parms": {
                "UserID": "rsaxena",
                "Version": "v1",
                "Env": "QA",
                "Source": "WMP",
                "Session": 33187082,
                "ExpireDays": 999,
                "RC": 1000,
                "ResultMsg": "WWTS not available",
            }
        }
        mocker.register_uri("GET", self.url, json=mock_resp)
        response = GTAccess().start_session(user=self.user_id, password=self.password)
        actual = response.ErrorMsg
        expected = "WWTS not available"
        self.assertEqual(actual, expected)

    def test_session(self, mocker):
        mock_resp = {
            "Parms": {
                "UserID": "rsaxena",
                "Version": "v1",
                "Env": "QA",
                "Source": "WMP",
                "Session": 33187082,
                "ExpireDays": 999,
                "RC": 0,
                "ResultMsg": "Processed successfully",
            }
        }
        mocker.register_uri("GET", self.url, json=mock_resp)
        response = GTAccess().start_session(user=self.user_id, password=self.password)
        actual = response.Session
        expected = 33187082
        self.assertEqual(actual, expected)


@requests_mock.Mocker()
class TestEndSession(unittest.TestCase):
    def setUp(self):
        self.user_id = "rsaxena"

    def test_success(self, mocker):
        pass

    def test_fail(self, mocker):
        pass
