-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_async.py
More file actions
64 lines (46 loc) · 1.72 KB
/
test_async.py
File metadata and controls
64 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Tests async interaction support for DomainTools APIs"""
import asyncio
from tests.settings import api, vcr
def run_async(future):
return asyncio.get_event_loop().run_until_complete(future)
@vcr.use_cassette
def test_async_iteration():
async def async_iter_test():
domains = []
async for domain in api.domain_search('google'):
domains += domain
return domains
domains = run_async(async_iter_test())
assert domains
for domain in domains:
assert type(domain) == str
@vcr.use_cassette
def test_async_context_manager():
async def async_context_manager_test():
async with api.domain_search('google') as results:
return results
results = run_async(async_context_manager_test())
assert results
@vcr.use_cassette
def test_async_simple_await():
async def simple_await():
results = await api.domain_search('google')
return results
results = run_async(simple_await())
assert results
@vcr.use_cassette
def test_async_simple_await_post():
async def simple_await():
results = await api.iris_investigate(domains=['amazon.com', 'google.com'])
return results
investigation_results = run_async(simple_await())
assert investigation_results['results_count']
for result in investigation_results:
assert result['domain'] in ['amazon.com', 'google.com']
@vcr.use_cassette
def test_async_simple_await_patch():
async def simple_await():
results = await api.iris_detect_manage_watchlist_domains(watchlist_domain_ids=["gae08rdVWG"], state="watched")
return results
detect_results = run_async(simple_await())
assert detect_results['watchlist_domains'][0]['state'] == "watched"