def test_kinoman_login_bad(self, mock_player):
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", "fake_login")
        mock_player.set_setting("password", "fake_password")

        with self.assertRaises(kinoman_api.LoginError):
            kinoman_api._kinoman_login(self.session)
Example #2
0
    def test_kinoman_login_empty_credentials(self, mock_player):
        mock_session = mock.MagicMock()
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", "")
        mock_player.set_setting("password", "")

        with self.assertRaises(kinoman_api.LoginError):
            kinoman_api._kinoman_login(mock_session)
Example #3
0
    def test_kinoman_login_network_error(self, mock_player):
        mock_session = mock.MagicMock()
        mock_player.set_setting("_cookie", "{}")
        mock_player.set_setting("_last_check", 0)

        mock_session.get.side_effect = requests.ConnectionError

        with self.assertRaises(kinoman_api.NetworkError):
            kinoman_api._kinoman_login(mock_session)
Example #4
0
    def test_kinoman_login_network_error_credentials(self, mock_player):
        mock_session = mock.MagicMock()
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", "fake_login")
        mock_player.set_setting("password", "fake_password")

        mock_session.post.side_effect = requests.ConnectionError

        with self.assertRaises(kinoman_api.NetworkError):
            kinoman_api._kinoman_login(mock_session)
Example #5
0
    def test_kinoman_login_bad_unknown(self, mock_player):
        mock_session = mock.MagicMock()
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", "fake_login")
        mock_player.set_setting("password", "fake_password")

        fake_page = namedtuple("FakePage", ["status_code", "text"])
        mock_session.post.return_value = fake_page(status_code=200, text="{}")

        with self.assertRaises(kinoman_api.LoginError):
            kinoman_api._kinoman_login(mock_session)
Example #6
0
    def test_kinoman_login_bad_expired_subscription(self, mock_player):
        mock_session = mock.MagicMock()
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", "fake_login")
        mock_player.set_setting("password", "fake_password")

        fake_page = namedtuple("FakePage", ["status_code", "text"])
        mock_session.post.return_value = fake_page(
            status_code=200, text='{"user": {"abon_time_is_active": false}}')

        with self.assertRaises(kinoman_api.LoginError):
            kinoman_api._kinoman_login(mock_session)
    def test_kinoman_login_good_cookie_expired(self, mock_player):
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", KINOMAN_USER)
        mock_player.set_setting("password", KINOMAN_PASS)

        self.assertTrue(kinoman_api._kinoman_login(self.session))

        mock_player.set_setting("_last_check", 0)

        self.assertTrue(kinoman_api._kinoman_login(self.session))
        self.assertIn("SESSIONID",
                      json.loads(mock_player.get_setting("_cookie")))
        self.assertNotEqual(mock_player.get_setting("_last_check", "int"), 0)

        self.kinoman_logout()
    def setUpClass(cls):
        cls.patcher = mock.patch("resources.kinoman_api.player",
                                 new_callable=FakePlayer)
        cls.mock_player = cls.patcher.start()

        cls.mock_player.set_setting("_cookie", "")
        cls.mock_player.set_setting("_last_check", 0)
        cls.mock_player.set_setting("username", KINOMAN_USER)
        cls.mock_player.set_setting("password", KINOMAN_PASS)

        session = requests.Session()
        session.headers.update({"User-Agent": kinoman_api.SPOOF_USER_AGENT})

        cls.login_success = kinoman_api._kinoman_login(session)

        session.close()
Example #9
0
    def test_kinoman_login_good_cookie_expired(self, mock_player, mock_time):
        mock_session = mock.MagicMock()
        mock_time.time.return_value = 1000
        mock_player.set_setting("_cookie", "{}")
        mock_player.set_setting("_last_check", 0)

        fake_page = namedtuple("FakePage", ["status_code", "text"])
        mock_session.get.return_value = fake_page(
            status_code=200,
            text='{"user": {"abon_time_is_active": true, "user_id": 100}}',
        )
        mock_session.cookies.get_dict.return_value = {
            "updated_cookie": "updated_value"
        }

        self.assertTrue(kinoman_api._kinoman_login(mock_session))
        self.assertEqual(
            json.loads(mock_player.get_setting("_cookie")),
            {"updated_cookie": "updated_value"},
        )
        self.assertEqual(mock_player.get_setting("_last_check", "int"), 1000)
Example #10
0
    def test_kinoman_login_good(self, mock_player, mock_time):
        mock_session = mock.MagicMock()
        mock_time.time.return_value = 1000
        mock_player.set_setting("_cookie", "")
        mock_player.set_setting("_last_check", 0)
        mock_player.set_setting("username", "fake_login")
        mock_player.set_setting("password", "fake_password")

        fake_page = namedtuple("FakePage", ["status_code", "text"])
        mock_session.post.return_value = fake_page(
            status_code=200,
            text='{"user": {"user_id": 100, "abon_time_is_active": true}}',
        )
        mock_session.cookies.get_dict.return_value = {
            "new_cookie": "new_value"
        }

        self.assertTrue(kinoman_api._kinoman_login(mock_session))
        self.assertEqual(json.loads(mock_player.get_setting("_cookie")),
                         {"new_cookie": "new_value"})
        self.assertEqual(mock_player.get_setting("_last_check", "int"), 1000)
        self.assertEqual(mock_player.get_setting("_user_id", "int"), 100)
Example #11
0
    def test_kinoman_login_cookie_fresh(self, mock_player):
        mock_session = mock.MagicMock()
        mock_player.set_setting("_cookie", "{}")
        mock_player.set_setting("_last_check", int(time.time()) + 1000)

        self.assertTrue(kinoman_api._kinoman_login(mock_session))