예제 #1
0
from functools import partial

import automock
from six.moves import mock


@automock.register('tests.dummies.func_to_mock')
def mock_factory(mockery='I have large ears'):
    mocked = mock.MagicMock()
    mocked.return_value = mockery
    return mocked


custom_mock_factory = partial(mock_factory, 'I like PHP')

automock.register('tests.dummies.other_func_to_mock', custom_mock_factory)
automock.register('tests.dummies.yet_another_func_to_mock')
import automock

automock.register('opendata.importer.insert_or_update')
automock.register('db.connect.get_connection')
예제 #3
0
    import crontab

    def new_job(command: str, comment: str) -> crontab.CronItem:
        job = crontab.CronItem(
            command=command,
            comment=comment,
            user=None,
            cron=None,
            pre_comment=False,
        )
        return job

    m.return_value.__enter__.return_value.new.side_effect = new_job
    return m


def pwd_mock(valid: bool = True) -> Mock:
    m = Mock()
    if valid:
        m.getpwnam.return_value.pw_uid = 1000
    else:
        m.getpwnam.side_effect = KeyError
    return m


automock.register("adhan_pi.utils.Nominatim", geocode_mock)
automock.register("adhan_pi.cli.CronTab", cron_mock)
automock.register("adhan_pi.cli.AudioSegment")
automock.register("adhan_pi.cli.play")
automock.register("adhan_pi.cli.pwd", pwd_mock)
from cloud import importer
import automock

automock.register('db.connect.get_connection')


def test_import_package(mocker):
    mock_gather_data = mocker.patch('cloud.importer.ckan.gather_data')
    mock_importer = mocker.patch('cloud.importer.importer.import_package')
    mock_gather_data.return_value = {id: 1}
    importer.import_package(1, 'fake', 1)
    mock_gather_data.assert_called_once_with(1, 'fake', 1)
    mock_importer.assert_called_once_with({id: 1})
예제 #5
0
                "in_reply_to_screen_name": None,
                "in_reply_to_status_id": None,
                "in_reply_to_status_id_str": None,
                "in_reply_to_user_id": None,
                "in_reply_to_user_id_str": None,
                "is_quote_status": False,
                "lang": "en",
                "place": None,
                "possibly_sensitive": False,
                "retweet_count": 9,
                "retweeted": False,
                "source":
                '<a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>',
                "text":
                "#NYCASP rules will be suspended tomorrow, Sunday, September 20",
                "truncated": False,
                "user": {},
            },
        ]

    def side_effect(screen_name=None, max_id=None, count=5):
        return response, tweets

    m = Mock()
    m().get_tweets.side_effect = side_effect
    return m


automock.register("alt_side_parking.sms.get_client")
automock.register("alt_side_parking.feed.TwitterBot", tweet_mock_factory)