Permalink
Browse files

remove requires internet, replace with mocks

  • Loading branch information...
1 parent 6cb8267 commit eb704b8cd6fbe5caf30eef3917ec7769e150710f @pld pld committed Dec 22, 2012
@@ -149,7 +149,6 @@ def group(self):
return argmax_df.join(newest_col)
-
class MeanAggregation(MultiColumnAggregation):
"""Calculate the arithmetic mean.
View
@@ -3,7 +3,7 @@
import tempfile
from celery.task import task
-from pandas import read_csv
+import pandas as pd
from bamboo.core.frame import BambooFrame
from bamboo.lib.utils import call_async
@@ -15,7 +15,7 @@ def import_dataset(dataset, dframe=None, filepath_or_buffer=None,
delete=False):
"""For reading a URL and saving the corresponding dataset."""
if filepath_or_buffer:
- dframe = BambooFrame(read_csv(filepath_or_buffer)).recognize_dates()
+ dframe = BambooFrame(pd.read_csv(filepath_or_buffer)).recognize_dates()
if delete:
os.unlink(filepath_or_buffer)
@@ -2,7 +2,9 @@
from datetime import datetime
import pickle
from time import mktime, sleep
+from urllib2 import URLError
+from mock import patch
import simplejson as json
from bamboo.controllers.abstract_controller import AbstractController
@@ -15,7 +17,7 @@
from bamboo.models.dataset import Dataset
from bamboo.tests.controllers.test_abstract_datasets import\
TestAbstractDatasets
-from bamboo.tests.decorators import requires_async, requires_internet
+from bamboo.tests.decorators import requires_async
from bamboo.tests.mock import MockUploadedFile
@@ -26,6 +28,7 @@ def setUp(self):
self._file_path = 'tests/fixtures/%s' % self._file_name
self._file_uri = 'file://%s' % self._file_path
self.url = 'http://formhub.org/mberg/forms/good_eats/data.csv'
+ self.dframe = self.test_data['good_eats.csv']
self.cardinalities = pickle.load(
open('tests/fixtures/good_eats_cardinalities.p', 'rb'))
self.simpletypes = pickle.load(
@@ -96,26 +99,30 @@ def test_create_from_url_failure(self):
self.assertTrue(isinstance(result, dict))
self.assertTrue(Datasets.ERROR in result)
- @requires_internet
def test_create_from_url(self):
- result = json.loads(self.controller.create(url=self.url))
+ with patch('pandas.read_csv', return_value=self.dframe) as mock:
+ result = json.loads(self.controller.create(url=self.url))
self.assertTrue(isinstance(result, dict))
self.assertTrue(Dataset.ID in result)
+ results = json.loads(self.controller.show(result[Dataset.ID]))
+ self.assertEqual(len(results), self.NUM_ROWS)
+
self._test_summary_built(result)
- @requires_internet
@requires_async
- def test_create_from_not_csv_url(self):
+ @patch('pandas.read_csv', return_value=None)
+ def test_create_from_not_csv_url(self, read_csv):
result = json.loads(self.controller.create(
url='http://74.125.228.110/'))
self.assertTrue(isinstance(result, dict))
self.assertTrue(Dataset.ID in result)
+
results = json.loads(self.controller.show(result[Dataset.ID]))
self.assertEqual(len(results), 0)
- @requires_internet
- def test_create_from_bad_url(self):
+ @patch('pandas.read_csv', return_value=None, side_effect=URLError(''))
+ def test_create_from_bad_url(self, read_csv):
result = json.loads(self.controller.create(
url='http://dsfskfjdks.com'))
self.assertTrue(isinstance(result, dict))
@@ -6,7 +6,7 @@
from bamboo.models.dataset import Dataset
from bamboo.tests.controllers.test_abstract_datasets import\
TestAbstractDatasets
-from bamboo.tests.decorators import requires_async, requires_internet
+from bamboo.tests.decorators import requires_async
class TestDatasetsPostUpdate(TestAbstractDatasets):
@@ -41,26 +41,3 @@ def wrapper(*args, **kwargs):
print "SECONDS:", seconds, func.__name__, kwargs
return result
return wrapper
-
-
-def requires_internet(func, url='http://74.125.113.99'):
- @wraps(func)
- def wrapper(*args, **kwargs):
- if not _internet_on(url):
- raise AssertionError('This test requires an internet connection to'
- 'run/pass.')
- return func(*args, **kwargs)
- return wrapper
-
-
-def _check_url(url, timeout=1):
- try:
- response = urllib2.urlopen(url, timeout=timeout)
- return True
- except urllib2.URLError as e:
- pass
- return False
-
-
-def _internet_on(url):
- return _check_url(url)
@@ -16,16 +16,3 @@ def _test_decorator(self, func):
def test_print_time(self):
self._test_decorator(test_decorators.print_time)
-
- def test_requires_internet(self):
- self._test_decorator(test_decorators.requires_internet)
-
- def test_requires_internet_bad_url(self):
- wrapped_test_func = test_decorators.requires_internet(
- self._test_func, 'http://')
- self.assertTrue(hasattr(wrapped_test_func, '__call__'))
- self.assertRaises(AssertionError, wrapped_test_func)
-
- def test_check_bad_url(self):
- result = test_decorators._check_url('http://')
- self.assertEqual(result, False)
@@ -1,3 +1,4 @@
+mock==1.0.1
nose==1.2.1
nose-cov==1.5
nose-progressive==1.3

0 comments on commit eb704b8

Please sign in to comment.