from boto import auth from garcon import activity from unittest.mock import MagicMock import boto.swf.layer2 as swf import pytest from octopus.flows.dim_refresh import tasks from subprocess import Popen from octopus.flows.dim_refresh import generator def test_bootstrap(monkeypatch): monkeypatch.setattr(auth, 'get_auth_handler', MagicMock()) monkeypatch.setattr(swf, 'ActivityWorker', MagicMock) monkeypatch.setattr(generator, 'get_min_max_list', MagicMock(return_value=[])) resp = tasks.bootstrap(activity.Activity(), 'dim_artist') assert isinstance(resp, dict) assert resp.get('entity') assert resp.get('destination_s3_key') def test_bootstrap_failures(): with pytest.raises(Exception): tasks.bootstrap(None, dict()) with pytest.raises(Exception): tasks.bootstrap(None, dict( entity='bla')) with pytest.raises(Exception): tasks.bootstrap(None, dict( destination_s3key='blabla')) def test_pipe_sql_to_stdout(monkeypatch): monkeypatch.setattr(auth, 'get_auth_handler', MagicMock()) monkeypatch.setattr(swf, 'ActivityWorker', MagicMock) resp = tasks.pipe_sql_to_stdout(activity.Activity(), 'dim_artistt') assert isinstance(resp, dict) assert isinstance(resp.get('pipe'), Popen) def test_dim_refresh_load(monkeypatch): """Configuration files should not contain errors. """ from garcon import activity monkeypatch.setattr(activity, 'create', MagicMock) from octopus.flows import dim_refresh assert dim_refresh