示例#1
0
 def test_hash_password(self):
     self.assertEqual(Helpers.hash_password(self.vesync_1.password),
                      '5f4dcc3b5aa765d61d8327deb882cf99')
     self.assertEqual(Helpers.hash_password(self.vesync_5.password),
                      'd41d8cd98f00b204e9800998ecf8427e')
     with self.assertRaises(AttributeError):
         Helpers.hash_password(self.vesync_6.password)
示例#2
0
    def test_login(self):
        """Test login method."""
        mock_vesync = mock.Mock()
        mock_vesync.login.return_value = True
        self.assertTrue(mock_vesync.login())
        mock_vesync.login.return_value = False
        self.assertFalse(mock_vesync.login())

        with patch('pyvesync.helpers.Helpers.call_api') as mocked_post:
            d = {
                'result': {
                    'accountID': '12346536',
                    'userType': '1',
                    'token': 'somevaluehere',
                },
                'code': 0,
            }
            mocked_post.return_value = (d, 200)

            data = self.vesync_1.login()
            body = Helpers.req_body(self.vesync_1, 'login')
            body['email'] = self.vesync_1.username
            body['password'] = Helpers.hash_password(self.vesync_1.password)
            mocked_post.assert_called_with('/cloud/v1/user/login',
                                           'post',
                                           json_object=body)
            self.assertTrue(data)
示例#3
0
    def test_login(self):
        mock_vesync = mock.Mock()
        mock_vesync.login.return_value = True
        self.assertTrue(mock_vesync.login())
        mock_vesync.login.return_value = False
        self.assertFalse(mock_vesync.login())

        with patch('pyvesync.helpers.Helpers.call_api') as mocked_post:
            d = {
                "result": {
                    "accountID": "12346536",
                    "userType": "1",
                    "token": "somevaluehere"
                },
                "code": 0
            }
            mocked_post.return_value = (d, 200)

            data = self.vesync_1.login()
            body = Helpers.req_body(self.vesync_1, 'login')
            body['email'] = self.vesync_1.username
            body['password'] = Helpers.hash_password(self.vesync_1.password)
            mocked_post.assert_called_with('/cloud/v1/user/login',
                                           'post',
                                           json=body)
            self.assertTrue(data)