Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# This prints a bunch of text/password controls, but only ONE CheckboxControl
def edit_account(br, nick, password, new_password, new_password2, name, email, design, pref_st):
br.open(URL_BASE + '/preferinte').read()
br.select_form(name='accountForm')
if nick: br['nick'] = nick
if password: br['curPass'] = password
if new_password: br['newPass'] = new_password
if new_password2: br['newPass2'] = new_password2
if name: br['name'] = name
if email: br['email'] = email
if design: br['skin'] = [design]
if pref_st is not None: br.find_control('userPrefs[]').items[0].selected = pref_st
resp = br.submit()
return resp
class LoginTest(unittest.TestCase):
def test_register_bad_info(self):
br = mechanize.Browser()
resp = create_account(br, '', '', '')
html = resp.read()
self.assertIn('Trebuie să vă alegeți un nume de cont', html)
resp = create_account(br, 'john', '', '')
html = resp.read()
self.assertIn('Trebuie să vă alegeți o parolă', html)
resp = create_account(br, 'john', 'john@john.com', 'password', 'mismatched password')
html = resp.read()
self.assertIn('Parolele nu coincid', html)
resp = create_account(br, 'vasile', 'john@john.com', 'password')
import b3
import logging
import unittest2 as unittest
from mockito import mock, when, any as anything, verify
from mock import Mock, patch, ANY
from b3.clients import Client
from b3.config import XmlConfigParser
from b3.events import Event
from b3.fake import FakeClient
from b3.parsers.iourt41 import Iourt41Parser
log = logging.getLogger("test")
log.setLevel(logging.INFO)
class Iourt41TestCase(unittest.TestCase):
"""
Test case that is suitable for testing iourt41 parser specific features
"""
@classmethod
def setUpClass(cls):
from b3.parsers.q3a.abstractParser import AbstractParser
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# Iourt41Parser -> AbstractParser -> FakeConsole -> Parser
def setUp(self):
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""
self.assertRaises(TypeError, omits, 0, 4)
class Test__contains(unittest2.TestCase):
def test__contains_value(self):
self.assertTrue(_contains_fallback(range(4), 3))
self.assertFalse(_contains_fallback(range(4), 43))
self.assertTrue(_contains_fallback({"a": 4, "b": 5}, "a"))
self.assertFalse(_contains_fallback({"a": 4, "b": 5}, "c"))
def test_TypeError_when_not_iterable(self):
self.assertRaises(TypeError, _contains_fallback, None, 4)
self.assertRaises(TypeError, _contains_fallback, True, 4)
self.assertRaises(TypeError, _contains_fallback, 0, 4)
# Unique, union, difference, and without tests.
class Test_difference(unittest2.TestCase):
def test_difference(self):
self.assertEqual(difference(range(1, 6), [5, 2, 10]), [1, 3, 4])
self.assertEqual(difference("abcdefg", "abc"), list("defg"))
self.assertEqual(difference("abcdefg", "xyz"), list("abcdefg"))
def test_TypeError_when_not_iterable(self):
self.assertRaises(TypeError, difference, None, None)
self.assertRaises(TypeError, difference, None, True)
self.assertRaises(TypeError, difference, None, 0)
self.assertRaises(TypeError, difference, 0, None)
self.assertRaises(TypeError, difference, 0, True)
self.assertRaises(TypeError, difference, 0, 0)
class Test_idifference(unittest2.TestCase):
def test_idifference(self):
self.assertEqual(list(idifference(range(1, 6), [5, 2, 10])), [1, 3, 4])
self.config.from_ini(self.config_file)
self.assertEqual(
self.config(),
{
'section1': {
'value1': 'test-value',
},
},
)
self.assertEqual(self.config.section1(), {'value1': 'test-value'})
self.assertEqual(self.config.section1.value1(), 'test-value')
class ConfigFromYamlTests(unittest.TestCase):
def setUp(self):
self.config = providers.Configuration(name='config')
_, self.config_file_1 = tempfile.mkstemp()
with open(self.config_file_1, 'w') as config_file:
config_file.write(
'section1:\n'
' value1: 1\n'
'\n'
'section2:\n'
' value2: 2\n'
)
_, self.config_file_2 = tempfile.mkstemp()
with open(self.config_file_2, 'w') as config_file:
17 31 1 6
16 32 1 6
19 18 1 0
7 4 1 0
10 12 2 0
17 16 1 0
28 30 1 0
M END
>
CHEMBL1200735
$$$$
'''
class TestSequenceFunctions(unittest.TestCase):
def test_resolve(self):
ret = resolve('viagra')
self.assertEqual(len(ret), 1)
self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL1737')
ret = resolve('gleevec')
self.assertEqual(len(ret), 2)
self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')
self.assertEqual(ret[1]['molecule_chembl_id'], 'CHEMBL1642')
ret = resolve('gleevec', single_result=True)
self.assertEqual(len(ret), 1)
self.assertEqual(ret[0]['molecule_chembl_id'], 'CHEMBL941')
# -*- coding: utf-8 -*-
import sys
import unittest2 as unittest
import slumber
class UtilsTestCase(unittest.TestCase):
def test_copy_kwargs(self):
self.assertEqual({ 'x': 1 }, slumber.copy_kwargs({ 'x': 1 }))
def test_url_join_http(self):
self.assertEqual(slumber.url_join("http://example.com/"), "http://example.com/")
self.assertEqual(slumber.url_join("http://example.com/", "test"), "http://example.com/test")
self.assertEqual(slumber.url_join("http://example.com/", "test", "example"), "http://example.com/test/example")
self.assertEqual(slumber.url_join("http://example.com"), "http://example.com/")
self.assertEqual(slumber.url_join("http://example.com", "test"), "http://example.com/test")
self.assertEqual(slumber.url_join("http://example.com", "test", "example"), "http://example.com/test/example")
def test_url_join_https(self):
self.assertEqual(slumber.url_join("https://example.com/"), "https://example.com/")
self.assertEqual(slumber.url_join("https://example.com/", "test"), "https://example.com/test")
"flushIntervalMs": 2000
},
"quotaAggregatorConfig": {
"cacheEntries": 10,
"expirationMs": 2000,
"flushIntervalMs": 1000
},
"reportAggregatorConfig": {
"cacheEntries": 10,
"flushIntervalMs": 1000
}
}
"""
class TestEnvironmentLoader(unittest2.TestCase):
SERVICE_NAME = u'environment-loader'
def setUp(self):
json_fd = tempfile.NamedTemporaryFile(delete=False)
with json_fd as f:
f.write(_TEST_CONFIG.encode('ascii'))
self._config_file = json_fd.name
os.environ[client.CONFIG_VAR] = self._config_file
def tearDown(self):
if os.path.exists(self._config_file):
os.remove(self._config_file)
@mock.patch(u"endpoints_management.control.client.ReportOptions", autospec=True)
@mock.patch(u"endpoints_management.control.client.QuotaOptions", autospec=True)
@mock.patch(u"endpoints_management.control.client.CheckOptions", autospec=True)
self.assertFalse(CatalogA.p11.is_overridden)
self.assertFalse(CatalogA.p12.is_overridden)
class CatalogModuleBackwardCompatibility(unittest.TestCase):
"""Backward compatibility test of catalog module."""
def test_import_catalog(self):
"""Test that module `catalog` is the same as `catalogs`."""
from dependency_injector import catalog
from dependency_injector import catalogs
self.assertIs(catalog, catalogs)
class TestCatalogWithProvidingCallbacks(unittest.TestCase):
"""Catalog with providing callback tests."""
def test_concept(self):
"""Test concept."""
class UsersService(object):
"""Users service, that has dependency on database."""
class AuthService(object):
"""Auth service, that has dependencies on users service."""
def __init__(self, users_service):
"""Initializer."""
self.users_service = users_service
class Services(catalogs.DeclarativeCatalog):
"""Catalog of service providers."""
import unittest2
from .loudness import mu_law, inverse_mu_law, inverse_one_hot, instance_scale
import numpy as np
class TestLoudness(unittest2.TestCase):
def test_can_invert_mu_law(self):
a = np.random.normal(0, 1, (100, 4))
adjusted = mu_law(a)
inverted = inverse_mu_law(adjusted)
np.testing.assert_allclose(a, inverted)
class TestInverseOneHot(unittest2.TestCase):
def test_inverse_one_hot_1d_produces_scalar(self):
arr = np.zeros(10)
arr[5] = 1
x = inverse_one_hot(arr)
self.assertEqual((), x.shape)
def test_inverse_one_hot_2d_produces_1d_output(self):
arr = np.eye(10)
key3: val3,
}
tuple_key = multistore_file._dict_to_tuple_key(test_dict)
# the resulting key should be naturally sorted
expected_output = (
(key2, val2),
(key3, val3),
(key1, val1),
)
self.assertTupleEqual(expected_output, tuple_key)
# check we get the original dictionary back
self.assertDictEqual(test_dict, dict(tuple_key))
class MultistoreFileTests(unittest2.TestCase):
def tearDown(self):
try:
os.unlink(FILENAME)
except OSError:
pass
def setUp(self):
try:
os.unlink(FILENAME)
except OSError:
pass
def _create_test_credentials(self, client_id='some_client_id',
expiration=None):
access_token = 'foo'