Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_it_should_be_able_to_translate_text_in_the_interpreter_language(self):
r = Request(self.agent, None, {
'a text': 'un texte',
})
expect(r._('a text')).to.equal('un texte')
expect(r._('not found')).to.equal('not found')
def test_httpretty_should_allow_multiple_methods_for_the_same_uri():
"""HTTPretty should allow registering multiple methods for the same uri"""
url = 'http://test.com/test'
methods = ['GET', 'POST', 'PUT', 'OPTIONS']
for method in methods:
HTTPretty.register_uri(
getattr(HTTPretty, method),
url,
method
)
for method in methods:
request_action = getattr(requests, method.lower())
expect(request_action(url).text).to.equal(method)
def test_can_inspect_last_request():
"""HTTPretty.last_request is a mimetools.Message request from last match"""
HTTPretty.register_uri(HTTPretty.POST, "http://api.github.com/",
body='{"repositories": ["HTTPretty", "lettuce"]}')
response = requests.post(
'http://api.github.com',
'{"username": "gabrielfalcao"}',
headers={
'content-type': 'text/json',
},
)
expect(HTTPretty.last_request.method).to.equal('POST')
expect(HTTPretty.last_request.body).to.equal(
b'{"username": "gabrielfalcao"}',
)
expect(HTTPretty.last_request.headers['content-type']).to.equal(
'text/json',
)
expect(response.json()).to.equal({"repositories": ["HTTPretty", "lettuce"]})
def test_httpretty_should_mock_headers_requests(now):
"HTTPretty should mock basic headers with requests"
HTTPretty.register_uri(HTTPretty.GET, "http://github.com/",
body="this is supposed to be the response",
status=201)
response = requests.get('http://github.com')
expect(response.status_code).to.equal(201)
expect(dict(response.headers)).to.equal({
'content-type': 'text/plain; charset=utf-8',
'connection': 'close',
'content-length': '35',
'status': '201',
'server': 'Python/HTTPretty',
'date': now.strftime('%a, %d %b %Y %H:%M:%S GMT'),
})
def test_uri_info_full_url():
uri_info = URIInfo(
username='johhny',
password='password',
hostname=b'google.com',
port=80,
path=b'/',
query=b'foo=bar&baz=test',
fragment='',
scheme='',
)
expect(uri_info.full_url()).to.equal(
"http://johhny:password@google.com/?baz=test&foo=bar"
)
expect(uri_info.full_url(use_querystring=False)).to.equal(
"http://johhny:password@google.com/"
)
def test_it_should_install_dependencies_when_updating(self):
s = SkillsManager('skills')
p = os.path.abspath('skills')
with patch('os.path.isdir', return_value=True):
with patch('os.path.isfile', return_value=True):
with patch('builtins.open', mock_open(read_data='')):
with patch('subprocess.check_output') as sub_mock:
succeeded, failed = s.update('my/skill')
expect(succeeded).to.equal(['my/skill'])
expect(failed).to.be.empty
expect(sub_mock.call_count).to.equal(2)
sub_mock.assert_has_calls([
call(['git', 'pull'], cwd=os.path.join(
p, 'my__skill'), stderr=subprocess.STDOUT),
call(['pip', 'install', '-r', 'requirements.txt'],
cwd=os.path.join(p, 'my__skill'), stderr=subprocess.STDOUT),
])
def test_it_should_have_a_unique_id(self):
agt1 = Agent(self.interpreter)
agt2 = Agent(self.interpreter)
expect(agt1.id).to_not.be.none
expect(agt1.id).to.be.a(str)
expect(agt2.id).to_not.be.none
expect(agt2.id).to.be.a(str)
expect(agt1.id).to_not.equal(agt2.id)
def test_set_email_address_should_update_email_address(self, **kwargs):
self.setup_mocks(**kwargs)
self.mock_client.set_email_address.return_value = {'email_addr': 'test@users.org', 'email_timestamp': 1234}
assert self.session.email_timestamp == 0
self.session.set_email_address('newaddr')
expect(self.session.email_address).to.equal('test@users.org')
def test_load_backends(self):
loaded_backends = load_backends((
'social.backends.github.GithubOAuth2',
'social.backends.facebook.FacebookOAuth2',
'social.backends.flickr.FlickrOAuth'
))
keys = list(loaded_backends.keys())
keys.sort()
expect(keys).to.equal(['facebook', 'flickr', 'github'])
backends = ()
loaded_backends = load_backends(backends, force_load=True)
expect(len(list(loaded_backends.keys()))).to.equal(0)
def test_background_parsing_with_mmf():
feature = Feature.from_string(FEATURE16)
expect(feature.description).to.equal(
"As a rental store owner\n"
"I want to keep track of my clients\n"
"So that I can manage my business better"
)
expect(feature).to.have.property('background').being.a(Background)
expect(feature.background).to.have.property('steps')
expect(feature.background.steps).to.have.length_of(2)
step1, step2 = feature.background.steps
step1.sentence.should.equal(
'Given I have the following movies in my database:')
step1.hashes.should.equal(HashList(step1, [
{
u'Available': u'6',
u'Rating': u'4 stars',
u'Name': u'Matrix Revolutions',
u'New': u'no',
},
{
u'Available': u'11',
u'Rating': u'5 stars',
u'Name': u'Iron Man 2',
u'New': u'yes',