forked from althonos/InstaLooter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_batch.py
69 lines (49 loc) · 1.58 KB
/
test_batch.py
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
65
66
67
68
69
# coding: utf-8
from __future__ import absolute_import
from __future__ import unicode_literals
import textwrap
import unittest
import warnings
import fs
import requests
from instalooter.cli import main
from instalooter.batch import BatchRunner
from instalooter.looters import InstaLooter
try:
CONNECTION_FAILURE = not requests.get("https://instagr.am/instagram").ok
except requests.exceptions.ConnectionError:
CONNECTION_FAILURE = True
class TestBatchRunner(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.session = requests.Session()
@classmethod
def tearDownClass(cls):
cls.session.close()
def setUp(self):
self.destfs = fs.open_fs("temp://")
self.tmpdir = self.destfs.getsyspath("/")
def tearDown(self):
self.destfs.close()
@unittest.skipIf(CONNECTION_FAILURE, "cannot connect to Instagram")
def test_cli(self):
cfg = textwrap.dedent(
"""
[my job]
num-to-dl = 3
quiet = true
users:
therock: {self.tmpdir}
nintendo: {self.tmpdir}
"""
).format(self=self)
with self.destfs.open('batch.ini', 'w') as batch_file:
batch_file.write(cfg)
retcode = main(["batch", self.destfs.getsyspath('batch.ini')])
self.assertEqual(retcode, 0)
self.assertGreaterEqual(
len(list(self.destfs.filterdir("/", ["*.jpg"]))), 6)
def setUpModule():
warnings.simplefilter('ignore')
def tearDownModule():
warnings.simplefilter(warnings.defaultaction)