Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@gen_test
def test_modify_unknown_object(self):
yield self.maindoc.objects.modify(id=ObjectId(), docname='dn')
total = yield self.maindoc.objects.all().count()
self.assertEqual(total, 0)
self.assertFalse(None)
@testing.gen_test
def test_set_default_headers_options(self):
origin = 'http://foo.com'
self.handler.request = MockRequest(
method='OPTIONS',
headers={
'Origin': origin,
}
)
self.handler.set_default_headers()
assert origin == self.handler.headers['Access-Control-Allow-Origin']
@tornado.testing.gen_test
def test_global_funcs(self):
yield self.resetTables()
task = two.task.Task(self.app, None, 1, 2, twcommon.misc.now())
ctx = EvalPropContext(task, loctx=self.loctx, level=LEVEL_EXECUTE)
res = yield ctx.eval('len("xyzzy")', evaltype=EVALTYPE_CODE)
self.assertEqual(res, 5)
res = yield ctx.eval('len(ls)', evaltype=EVALTYPE_CODE)
self.assertEqual(res, 3)
res = yield ctx.eval('min(5,3,4)', evaltype=EVALTYPE_CODE)
self.assertEqual(res, 3)
res = yield ctx.eval('min([5,3,4])', evaltype=EVALTYPE_CODE)
self.assertEqual(res, 3)
res = yield ctx.eval('max(5,3,4)', evaltype=EVALTYPE_CODE)
self.assertEqual(res, 5)
@tornado.testing.gen_test
def test_add_remove_multiple_channels(self):
ch1 = "channel-groups-tornado-ch1"
ch2 = "channel-groups-tornado-ch2"
gr = "channel-groups-tornado-cg"
# add
env = yield self.pubnub.add_channel_to_channel_group() \
.channels([ch1, ch2]).channel_group(gr).future()
assert isinstance(env.result, PNChannelGroupsAddChannelResult)
yield gen.sleep(1)
# list
env = yield self.pubnub.list_channels_in_channel_group().channel_group(gr).future()
assert isinstance(env.result, PNChannelGroupsListResult)
@gen_test
def test_can_save_prefs_as_superuser(self):
self.db.query(User).delete()
user = UserFactory(email='superuser@user.com', is_superuser=True)
domain = DomainFactory.create(name='globo.com')
key = KeyFactory.create(name='some.random')
DomainsViolationsPrefsFactory.create(domain=domain, key=key, value=100)
loaded_prefs = DomainsViolationsPrefs.get_domains_violations_prefs_by_domain(self.db, domain.name)
expect(loaded_prefs).to_length(1)
expect(loaded_prefs[0]).to_be_like({
'value': 100,
'key': 'some.random'
})
yield self.authenticated_fetch(
'/domains/%s/violations-prefs/' % domain.name,
@testing.gen_test
def test_exists_single(self):
yield self.client.connect()
key = str(uuid.uuid4()).encode('ascii')
value = str(uuid.uuid4()).encode('ascii')
result = yield self.client.set(key, value)
self.assertTrue(result)
result = yield self.client.exists(key)
self.assertTrue(result)
@testing.gen_test
def test_conflict(self):
self.source_provider.move = utils.MockCoroutine(
return_value=(utils.MockFileMetadata(), True)
)
payload = self.payload()
payload['conflict'] = 'keep'
resp = yield self.http_client.fetch(
self.get_url('/ops/move'),
method='POST',
body=json.dumps(payload)
)
assert resp.code == 201
assert self.source_provider.move.called
@tornado.testing.gen_test
def test_GIVEN_protocol_acting_as_ifclose_message_recieved_WHEN_upload_to_repo_THEN_lock_cleared(self):
on_message_backup = UploadToRepoHandler.on_message
def on_message(handler, message):
handler.write_message("")
try:
UploadToRepoHandler.on_message = on_message
self.assertFalse(IsContainerizationOngoingHandler.is_containerization_ongoing())
request_url = "ws://localhost:" + str(self.get_http_port()) + "/upload_to_repo"
ws1 = yield tornado.websocket.websocket_connect(request_url)
ws1.write_message(json.dumps(False))
_ = yield ws1.read_message()
self.assertTrue(IsContainerizationOngoingHandler.is_containerization_ongoing())
old_containerizing_client = UploadToRepoHandler.containerizing_client
self.assertNotEqual(None, old_containerizing_client)
# this is what the protocol object does when it recieves a close message request
# i do this rather than send a close message request directly because it would be hard to
@gen_test
def test_blocking_pipeline(self):
key = "g_pipeline_test"
key1 = "g_pipeline_test1"
pipeline = self.client.pipeline()
pipeline.set(key, "gredis")
pipeline.set(key1, "gredis1")
pipeline.execute()
ret = yield self.client.get(key)
self.assertEqual(ret, "gredis")
ret1 = yield self.client.get(key1)
self.assertEqual(ret1, "gredis1")
@tornado.testing.gen_test
def test_roundrobin_multiconnection_pool(self):
servers = [
(self.pingpong_thrift_client.host,
self.pingpong_thrift_client.port),
(self.pingpong_thrift_client.host,
self.pingpong_thrift_client.port2),
]
from thrift_connector.tornado import TornadoRoundRobinMultiServerClient
roundrobin_pool = TornadoRoundRobinMultiServerClient(
self.pingpong_thrift_client.pool.service,
servers=servers,
name=self.pingpong_thrift_client.pool.name,
raise_empty=False, max_conn=3,
connection_class=self.pingpong_thrift_client.pool.connection_class,
)