本文整理汇总了Python中txclib.project.Project.getset_host_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python Project.getset_host_credentials方法的具体用法?Python Project.getset_host_credentials怎么用?Python Project.getset_host_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txclib.project.Project
的用法示例。
在下文中一共展示了Project.getset_host_credentials方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getset_host_credentials_update_transifexrc
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def test_getset_host_credentials_update_transifexrc(
self, m_parser, m_input):
p = Project(init=False)
dummy_token = 'salala'
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.validate_credentials = Mock(return_value=True)
p.txrc.get.side_effect = [
'foo', 'bar'
]
# transifexrc does not get updated if credentials are the same
username, password = p.getset_host_credentials(
'test', username='foo', password='bar'
)
self.assertEqual(username, 'foo')
self.assertEqual(password, 'bar')
self.assertEqual(p.txrc.set.call_count, 0)
self.assertEqual(m_input.call_count, 0)
self.assertEqual(p.save.call_count, 0)
# transifexrc is not updated if confirm is no
p.txrc.get.side_effect = [
'foo', 'bar'
]
m_input.return_value = False
username, password = p.getset_host_credentials('test',
token=dummy_token)
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
self.assertEqual(p.txrc.set.call_count, 0)
self.assertEqual(m_input.call_count, 1)
self.assertEqual(p.save.call_count, 0)
# transifexrc is not updated if confirm is yes
p.txrc.get.side_effect = [
'foo', 'bar'
]
m_input.return_value = True
m_input.reset_mock()
username, password = p.getset_host_credentials('test',
token=dummy_token)
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
self.assertEqual(p.txrc.set.call_count, 2)
self.assertEqual(m_input.call_count, 1)
p.save.assert_called()
示例2: __init__
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def __init__(self, path_to_tx):
p = Project(path_to_tx)
self.host = p.config.get('main', 'host')
username, token_or_password = p.getset_host_credentials(
self.host, only_token=True)
self.api = Api(username=username, password=token_or_password,
host=self.host, path_to_tx=p.txrc_file)
示例3: test_getset_host_credentials
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def test_getset_host_credentials(self, m_parser):
p = Project(init=False)
# let suppose a token has been set at the config
dummy_token = 'salala'
p.txrc = m_parser
p.txrc.add_section = Mock()
p.txrc.set = Mock()
p.txrc.get = Mock()
p.txrc.get.side_effect = ['api', dummy_token, None, None]
p.txrc_file = '/tmp'
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
# let's try to get credentials for someone without
# a token
p.txrc.get.side_effect = [
'username',
'passw0rdz'
]
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'username')
self.assertEqual(password, 'passw0rdz')
示例4: test_getset_host_credentials_env_variable_first_time
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def test_getset_host_credentials_env_variable_first_time(
self, m_parser, m_input):
p = Project(init=False)
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.txrc.has_section.side_effect = [False]
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, 'environment_value')
# ensure that we have set host in the txrc_file, even though TX_TOKEN
# exists
self.assertEqual(p.txrc.set.call_count, 2)
p.save.assert_called()
示例5: test_getset_host_credentials_env_variable
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def test_getset_host_credentials_env_variable(
self, m_parser, m_input):
p = Project(init=False)
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.txrc.has_section.side_effect = [False]
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, 'environment_value')
self.assertEqual(p.txrc.set.call_count, 2)
# no input will be asked, password will be used by environment variable
self.assertEqual(m_input.call_count, 0)
p.save.assert_called()
示例6: test_getset_host_credentials_both_token_and_env
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def test_getset_host_credentials_both_token_and_env(
self, m_logger, m_parser):
p = Project(init=False)
p.txrc = m_parser
p.save = Mock()
p.txrc_file = '/tmp'
p.txrc.has_section.side_effect = [False]
username, password = p.getset_host_credentials('test', token='demo')
self.assertEqual(username, 'api')
self.assertEqual(password, 'environment_value')
# ensure that we did not make additional calls to set the token in the
# txrc file
self.assertEqual(p.txrc.set.call_count, 2)
p.save.assert_called()
self.assertEqual(m_logger.warning.call_count, 1)
示例7: test_getset_host_credentials_no_transifexrc
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
def test_getset_host_credentials_no_transifexrc(
self, m_parser, m_input):
p = Project(init=False)
# let suppose a token has been set at the config
dummy_token = 'salala'
p.txrc = m_parser
p.save = Mock()
p.validate_credentials = Mock(return_value=True)
p.txrc_file = '/tmp'
p.txrc.get.side_effect = configparser.NoSectionError('test')
m_input.return_value = dummy_token
username, password = p.getset_host_credentials('test')
self.assertEqual(username, 'api')
self.assertEqual(password, dummy_token)
self.assertEqual(p.txrc.set.call_count, 2)
self.assertEqual(m_input.call_count, 1)
p.save.assert_called()
示例8: Project
# 需要导入模块: from txclib.project import Project [as 别名]
# 或者: from txclib.project.Project import getset_host_credentials [as 别名]
import requests
from txclib.parsers import status_parser
from txclib.project import Project
from txclib.utils import find_dot_tx
project_slug = 'documentation-5'
organization_slug = 'opendatasoft'
prj = Project(find_dot_tx())
api_auth = prj.getset_host_credentials('https://api.transifex.com')
offset = 0
remote_resources = []
while True:
r = requests.get('https://api.transifex.com/organizations/{}/projects/{}/resources/?offset={}'.format(organization_slug, project_slug, offset), auth=api_auth)
results = r.json()
if len(results) == 0:
break
remote_resources.extend(results)
offset += 100
remote_resources_set = set([res['slug'] for res in remote_resources])
local_resources_set = set([res.split('.')[1] for res in prj.get_chosen_resources([])])
print "remote resources count: {}".format(len(remote_resources_set))
print "local resources count: {}".format(len(local_resources_set))
outdated_resources = remote_resources_set - local_resources_set