Skip to content

Commit

Permalink
Merge pull request #74 from spacemansteve/master
Browse files Browse the repository at this point in the history
enabled and fixed tweak unittest
  • Loading branch information
spacemansteve authored Nov 25, 2018
2 parents 4d9c798 + f89c43f commit 5e057e4
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 5e057e4

Please sign in to comment.