def test_issue_052(self): """Thanks to @cyrusclarke for reporting this bug. Checks that on hashtags with a lot of posts, the time parameter doesn't cause the program to crash without finding any media to download. """ main(["hashtag", "happy", self.tmpdir, "-q", "-t", "thisweek", "-n", "5"]) self.assertGreaterEqual(len(self.destfs.listdir('/')), 5)
def test_issue_019(self): """ Thanks to @emijawdo for reporting this bug. Checks that instalooter does not crash when not given a destination directory and uses the current directory. """ initial_dir = os.getcwd() os.chdir(self.tmpdir) try: main(["user", "mysteryjets", "-n", "3", "-q"]) self.assertEqual(len(self.destfs.listdir("/")), 3) finally: os.chdir(initial_dir)
def test_user(self): with contexter.Contexter() as ctx: ctx << mock.patch('instalooter.cli.ProfileLooter.pages', MockPages('nintendo')) r = main(["user", "nintendo", self.tmpdir, "-q", '-n', '10']) self.assertEqual(r, 0) self.assertEqual(len(self.destfs.listdir('/')), 10)
def test_issue_019(self): """ Thanks to @emijawdo for reporting this bug. Checks that instalooter does not crash when not given a destination directory and uses the current directory. """ initial_dir = os.getcwd() os.chdir(self.tmpdir) try: with contexter.Contexter() as ctx: ctx << mock.patch('instalooter.looters.InstaLooter.pages', MockPages('nintendo')) main(["user", "nintendo", "-n", "3", "-q"]) self.assertGreaterEqual(len(self.destfs.listdir("/")), 3) finally: os.chdir(initial_dir)
def test_dump_only(self): r = main(["post", "BIqZ8L8AHmH", self.tmpdir, '-q', '-D']) self.assertEqual(r, 0) self.assertTrue(self.destfs.exists("1308972728853756295.json")) self.assertFalse(self.destfs.exists("1308972728853756295.jpg")) with self.destfs.open("1308972728853756295.json") as fp: json_metadata = json.load(fp) self.assertEqual("1308972728853756295", json_metadata["id"]) self.assertEqual("BIqZ8L8AHmH", json_metadata["shortcode"])
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 test_single_post_from_url(self): url = "https://www.instagram.com/p/BFB6znLg5s1/" main(["post", url, self.tmpdir, "-q"]) self.assertIn("1243533605591030581.jpg", os.listdir(self.tmpdir))
def test_usage(self): handle = six.moves.StringIO() main(["--usage"], stream=handle) self.assertEqual(handle.getvalue().strip(), USAGE.strip())
def test_single_post(self): r = main(["post", "BFB6znLg5s1", self.tmpdir, "-q"]) self.assertEqual(r, 0) self.assertTrue(self.destfs.exists("1243533605591030581.jpg"))
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Running a test example. """ import sys from instalooter.cli import main def usage(): return ''' python run_example.py user carsandgu ./output -t 2018-12-31:2018-01-01 -n 25 -D -e --traceback -N ''' if __name__ == '__main__': main() # is the same as # main(sys.argv[1:])
def test_user(self): r = main(["user", "mysteryjets", self.tmpdir, "-q", '-n', '10']) self.assertEqual(r, 0) self.assertEqual(len(self.destfs.listdir('/')), 10)