diff --git a/adsmp/app.py b/adsmp/app.py index 7481bd6..c2b2de0 100644 --- a/adsmp/app.py +++ b/adsmp/app.py @@ -17,8 +17,8 @@ import zlib import requests from copy import deepcopy -from os import listdir -from os.path import join, isdir +from os.path import join +import os class ADSMasterPipelineCelery(ADSCelery): @@ -82,8 +82,8 @@ def __init__(self, app_name, *args, **kwargs): def load_tweak_files(self): """load all tweak files from the tweak directory""" - if isdir(self.tweak_dir): - tweak_files = listdir(self.tweak_dir) + if os.path.isdir(self.tweak_dir): + tweak_files = os.listdir(self.tweak_dir) tweak_files.sort() for t in tweak_files: if t.endswith('.json'): diff --git a/adsmp/tests/test_app.py b/adsmp/tests/test_app.py index efa3587..7648224 100644 --- a/adsmp/tests/test_app.py +++ b/adsmp/tests/test_app.py @@ -1,26 +1,19 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - from mock import patch from mock import mock_open import mock import unittest -import sys import os import json -import re -import os -import math - import adsputils -from io import BytesIO -from datetime import datetime from adsmp import app, models from adsmp.models import Base, MetricsBase import testing.postgresql + class TestAdsOrcidCelery(unittest.TestCase): """ Tests the appliction's methods @@ -391,16 +384,11 @@ def test_solr_tweak(self): self.assertTrue('title' in doc) self.assertEqual('1971SPIE...26..187M', doc['bibcode']) - @unittest.skip('mock not yet working') - def test_read_tweak_files(self, mocked_isdir): - self.assertTrue(os.path.isdir('/asdfsdf')) - self.app.quux() - with mock.patch('adsmp.app.os.path.isdir', return_value=True), \ - mock.patch('os.listdir', return_value=('foo.json', 'bar')), \ + def test_read_tweak_files(self): + """validates code that processes directory of tweak files""" + with mock.patch('os.path.isdir', return_value=True), \ + mock.patch('os.listdir', return_value=['foo.json', 'bar.txt']), \ mock.patch('adsmp.app.ADSMasterPipelineCelery.load_tweak_file') as m: - self.assertTrue(os.path.isdir('/asdfsdf')) - self.foo() - self.app.quux() self.app.load_tweak_files() m.assert_called_once_with('foo.json')