How to use the mock.call.get function in mock

To help you get started, we’ve selected a few mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bradmontgomery / django-redis-metrics / redis_metrics / tests.py View on Github external
def test_get_metric(self):
        """Tests getting a single metric; ``R.get_metric``."""
        slug = 'test-metric'
        self.r.get_metric(slug)

        # Verify that we GET the keys from redis
        day, week, month, year = self.r._build_keys(slug)
        self.redis.assert_has_calls([
            call.get(day),
            call.get(week),
            call.get(month),
            call.get(year),
        ])
github pypa / pip / tests / unit / test_collector.py View on Github external
request is responded with text/html.
    """
    session = mock.Mock(PipSession)
    session.head.return_value = mock.Mock(**{
        "request.method": "HEAD",
        "headers": {"Content-Type": "text/html"},
    })
    session.get.return_value = mock.Mock(headers={"Content-Type": "text/html"})

    resp = _get_html_response(url, session=session)

    assert resp is not None
    assert session.mock_calls == [
        mock.call.head(url, allow_redirects=True),
        mock.call.head().raise_for_status(),
        mock.call.get(url, headers={
            "Accept": "text/html", "Cache-Control": "max-age=0",
        }),
        mock.call.get().raise_for_status(),
    ]
github eve-val / evelink / tests / test_account.py View on Github external
result, current, expires = self.account.characters()

        self.assertEqual(result, {
                1365215823: {
                    'corp': {
                        'id': 238510404,
                        'name': 'Puppies To the Rescue',
                    },
                    'alliance': None,
                    'id': 1365215823,
                    'name': 'Alexis Prey',
                },
            })
        self.assertEqual(self.api.mock_calls, [
                mock.call.get('account/Characters', params={}),
            ])
        self.assertEqual(current, 12345)
        self.assertEqual(expires, 67890)

        self.api.get.return_value = self.make_api_result("account/characters_with_alliance.xml")

        result, current, expires = self.account.characters()

        self.assertEqual(result[93698525]['alliance'], {
                'id': 99000739,
                'name': "Of Sound Mind",
            })
github eve-val / evelink / tests / test_char.py View on Github external
self.assertEqual(result, {
                308734131: {
                    'data': {
                        'level': 10,
                        'message': 'Hi, I want to social network with you!',
                    },
                    'id': 308734131,
                    'sender': {
                        'id': 797400947,
                        'name': 'CCP Garthagk',
                    },
                    'timestamp': 1275174240,
                },
            })
        self.assertEqual(self.api.mock_calls, [
                mock.call.get('char/ContactNotifications', params={'characterID': 1}),
            ])
github lyft / linty_fresh / tests / reporters / test_github_reporter.py View on Github external
Problem('some_dir/some_file', 40, 'really sad'),
            Problem('another_file', 2, 'This is OK'),
            Problem('another_file', 2, 'This is OK'),
            Problem('another_file', 3, 'I am a duplicate!'),
            Problem('another_file', 52, "#close_enough!!!"),
            Problem('missing_file', 42, "Missing file comment!!!"),
        ])

        loop = asyncio.get_event_loop()

        try:
            loop.run_until_complete(async_report)
        except HadLintErrorsException:
            pass

        diff_request = call.get(
            'https://api.github.com/repos/foo/bar/pulls/1234',
            headers={
                'Accept': 'application/vnd.github.diff',
                'Authorization': 'token MY_TOKEN'
            })
        existing_comments_request = call.get(
            'https://api.github.com/repos/foo/bar/pulls/1234/comments',
            headers={
                'Authorization': 'token MY_TOKEN'
            })
        existing_issues_request = call.get(
            'https://api.github.com/repos/foo/bar/issues/1234/comments',
            headers={
                'Authorization': 'token MY_TOKEN'
            })
        first_comment = call.post(
github eve-val / evelink / tests / test_char.py View on Github external
def test_wallet_transcations(self, mock_parse):
        self.api.get.return_value = API_RESULT_SENTINEL
        mock_parse.return_value = mock.sentinel.parsed_transactions

        result, current, expires = self.char.wallet_transactions()
        self.assertEqual(result, mock.sentinel.parsed_transactions)
        self.assertEqual(mock_parse.mock_calls, [
                mock.call(mock.sentinel.api_result),
            ])
        self.assertEqual(self.api.mock_calls, [
                mock.call.get('char/WalletTransactions', params={'characterID': 1}),
            ])
        self.assertEqual(current, 12345)
        self.assertEqual(expires, 67890)
github gluster / gluster-swift / test / unit / proxy / controllers / test_base.py View on Github external
info_c = get_info(app, env, 'a', 'c')
        # Check that you got proper info
        self.assertEqual(info_c['status'], 200)
        self.assertEqual(info_c['bytes'], 6666)
        self.assertEqual(info_c['object_count'], 1000)
        # Make sure the env cache is set
        self.assertEqual(env['swift.infocache'].get('account/a'),
                         exp_cached_info_a)
        self.assertEqual(env['swift.infocache'].get('container/a/c'),
                         exp_cached_info_c)
        # check app calls both account and container
        self.assertEqual(app.responses.stats['account'], 1)
        self.assertEqual(app.responses.stats['container'], 1)
        # Make sure account info was cached but container was not
        self.assertEqual(mock_cache.mock_calls, [
            mock.call.get('container/a/c'),
            mock.call.get('account/a'),
            mock.call.set('account/a', exp_cached_info_a, time=0),
            mock.call.set('container/a/c', exp_cached_info_c, time=0),
        ])
github eve-val / evelink / tests / test_char.py View on Github external
def test_wallet_journal(self, mock_parse):
        self.api.get.return_value = API_RESULT_SENTINEL
        mock_parse.return_value = mock.sentinel.parsed_journal

        result, current, expires = self.char.wallet_journal()
        self.assertEqual(result, mock.sentinel.parsed_journal)
        self.assertEqual(mock_parse.mock_calls, [
                mock.call(mock.sentinel.api_result),
            ])
        self.assertEqual(self.api.mock_calls, [
                mock.call.get('char/WalletJournal', params={'characterID': 1}),
            ])
        self.assertEqual(current, 12345)
        self.assertEqual(expires, 67890)
github eve-val / evelink / tests / test_char.py View on Github external
def test_wallet_paged(self):
        self.api.get.return_value = self.make_api_result("char/wallet_journal.xml")

        self.char.wallet_journal(before_id=1234)
        self.assertEqual(self.api.mock_calls, [
                mock.call.get('char/WalletJournal', params={'characterID': 1, 'fromID': 1234}),
            ])
github eve-val / evelink / tests / test_eve.py View on Github external
'secondary': 'charisma',
                                },
                            'required_skills': {
                                3363 : { 'id' : 3363, 'level' : 2, 'name' : None },
                                3444 : { 'id' : 3444, 'level' : 3, 'name' : None },
                                },
                            'bonuses': {}
                            }
                        }
                    }
                })
        self.assertEqual(current, 12345)
        self.assertEqual(expires, 67890)

        self.assertEqual(self.api.mock_calls, [
                mock.call.get('eve/SkillTree', params={})
                ])