Skip to content

Commit

Permalink
Make tests pass from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Artsiom Kushnariou committed Nov 4, 2018
1 parent 76f5d86 commit 5c0b2d8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ tests/unit/out
*.swp

out/
.DS_Store
2 changes: 0 additions & 2 deletions tests/integration/.az

This file was deleted.

7 changes: 5 additions & 2 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from modules import main


THIS_DIR = os.path.dirname(os.path.abspath(__file__))

class IntegrationTest(unittest.TestCase):

def setUp(self):
Expand All @@ -21,9 +23,10 @@ def test_from_cli(self):
os.mkdir(out_dir)

runner = CliRunner()
runner.invoke(main.run, ['-n', '5', '-d', '2015-12-11:', '-m', 'play.google.com', '-o', out_dir, '-sd', '1'], catch_exceptions=False)
input_file_path = os.path.join(THIS_DIR,'resources/latest_first50.csv')
runner.invoke(main.run, ['-i', input_file_path, '-n', '5', '-d', '2015-12-11:', '-m', 'play.google.com', '-o', out_dir, '-sd', '1'], catch_exceptions=False)
out_dir_contents = os.listdir(out_dir)
self.assertEqual(out_dir_contents, self.expected_out_dir_contents)
self.assertEqual(set(out_dir_contents), set(self.expected_out_dir_contents))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_dataset_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setUp(self):
self.dataset = Dataset(self.apk, self.apk2)
self.constructor_mock = mock.create_autospec(UrlConstructor)
self.constructor_mock.construct.side_effect = lambda apk:' https://'+apk.sha256 # use sha256 of apk as download url, just for a test
self.dataset_downloader = DatasetDownloader(self.dataset, url_constructor=self.constructor_mock, out_dir='out')
self.dataset_downloader = DatasetDownloader(self.dataset, threads=4, url_constructor=self.constructor_mock, out_dir='out')

@mock.patch('requests.get')
@mock.patch("modules.services.dataset_downloader.open")
Expand All @@ -37,7 +37,7 @@ def test_downloads_apks(self, get_mock, open_mock, os_mock):
self.assertEqual(self.constructor_mock.construct.call_args_list, [mock.call(self.apk), mock.call(self.apk2)])
self.constructor_mock.reset_mock()
self.assertEqual(get_mock.call_count, 2)
self.assertEqual(open_mock.call_args_list, [mock.call(r'out\apk1.apk', 'wb'), mock.call(r'out\apk2.apk', 'wb')])
self.assertEqual(open_mock.call_args_list, [mock.call(r'out/apk1.apk', 'wb'), mock.call(r'out/apk2.apk', 'wb')])


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_metadata_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_saves_metadata(self):
apk1,8,01-01-2001,play\n\
apk2,13,01-03-2001,china|play\n\
'
self.assertTrue(os.path.exists(r'out\metadata.csv'))
with open('out\metadata.csv') as f:
self.assertTrue(os.path.exists(r'out/metadata.csv'))
with open('out/metadata.csv') as f:
self.assertEqual(expected_out, f.read())


Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_source.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import unittest

import os

from modules.entities.apk import Apk
from modules.entities.source import Source

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


class SourceTest(unittest.TestCase):

def test_initializes_from_file(self):
source = Source(input_file='resources/sample.csv')
source = Source(input_file=os.path.join(THIS_DIR, 'resources/sample.csv'))
expected_apks = [Apk(**{'sha256': '0000003B455A6C7AF837EF90F2EAFFD856E3B5CF49F5E27191430328DE2FA670','sha1':'9C14D537A7ADB4CFC43D291352F73E05E0CCDD4A','md5':'3EDFC78AB53521942798AD551027D04F','dex_date':'2016-04-05 17:58:46','apk_size':'10386469','pkg_name':'com.zte.bamachaye','vercode':'121','vt_detection':'0','vt_scan_date':'2016-06-15 15:26:44','dex_size':'4765888','markets':'anzhi'}),
Apk(**{'sha256': '00000439A3FFA123C3F9BC45E5E821351B1A5C276871B36447AB80C74261F354','sha1':'375D6FFD167BB5E7E2935B1B927F87D8E44A9AB4','md5':'9283C74DD8356C18BB6D94B88B8FDD9B','dex_date':'2011-10-25 02:30:56','apk_size':'1044597','pkg_name':'bmthx.god102409paperi','vercode':'6','vt_detection':'1','vt_scan_date':'2014-04-27 06:30:31','dex_size':'105660','markets':'appchina'})]
actual_apks = []
Expand Down

0 comments on commit 5c0b2d8

Please sign in to comment.