Skip to content

Commit

Permalink
enabled and fixed tweak unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacemanSteve authored and SpacemanSteve committed Nov 25, 2018
1 parent aa4fc38 commit f89c43f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
8 changes: 4 additions & 4 deletions adsmp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'):
Expand Down
22 changes: 5 additions & 17 deletions adsmp/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit f89c43f

Please sign in to comment.