requests_mock.mock

Here are the examples of the python api requests_mock.mock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

176 Examples 7

Example 1

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_api_call_no_check_ratelimits(self, m):
        with open(self.tests_path + '/fixtures/blocks_ids.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/blocks/ids.json', text=response)
        self.client.ratelimiter.check_limit = MagicMock()

        self.client._api_call('blocks/ids', check_ratelimit=False)
        self.assertFalse(self.client.ratelimiter.check_limit.called)

Example 2

Project: kpm Source File: test_registry.py
Function: test_generate_with_params
def test_generate_with_params():
    r = Registry()
    with requests_mock.mock() as m:
        response = '{"packages": "true"}'
        m.get(DEFAULT_REGISTRY + "/api/v1/packages/ant31/kube-ui/generate?version=1.3.4&namespace=testns", complete_qs=True, text=response)
        assert json.dumps(r.generate(name="ant31/kube-ui", namespace="testns", variables={"a": "b", "c": "d"}, version="1.3.4")) == response

Example 3

Project: django-bulbs Source File: test_tunic.py
    def test_get_weighted_campaigns(self):
        with requests_mock.mock() as mocker:
            mocker.get('http://onion.local/api/v1/campaign/?weighted=true',
                       status_code=200,
                       json={'results': [{'id': 1,
                                          'name': 'My Campaign'}]},
                       headers={'Authorizaton': 'Token 12345'})
            self.assertEqual(TunicClient().get_campaigns(filter_weighted=True),
                             {1: {'id': 1,
                                  'name': 'My Campaign'}})

Example 4

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_get_mentions_timeline_since_id(self, m):
        with open(self.tests_path + '/fixtures/statuses_mentions_timeline_since_id.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/statuses/mentions_timeline.json?since_id=653965849364180992', text=response)
        r = self.client.get_mentions_timeline(since_id=653965849364180992)
        self.assertEqual(len(r), 1)

Example 5

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_retweet_already_retweeted(self, m):
        with open(self.tests_path + '/fixtures/error_already_retweeted.json') as f:
            response = f.read()
        m.post('https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json', text=response)
        with self.assertRaises(TwitterClientRetweetedException):
            self.client.retweet("241259202004267009")

Example 6

Project: django-bulbs Source File: test_liveblog_tasks.py
Function: test_request_error
    def test_request_error(self):

        with requests_mock.mock() as mocker:
            mocker.delete(self.url, status_code=500)

            with self.assertRaises(HTTPError):
                firebase_update_entry(self.entry.id)

Example 7

Project: kpm Source File: test_kubernetes.py
def test_get_proxy_500_raise(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=500)
        with pytest.raises(requests.exceptions.HTTPError):
            k.get()

Example 8

Project: server-client-python Source File: test_group.py
Function: test_remove_user
    def test_remove_user(self):
        with open(POPULATE_USERS, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            url = self.baseurl + '/e7833b48-c6f7-47b5-a2a7-36e7dd232758/users' \
                                 '/dd2239f6-ddf1-4107-981a-4cf94e415794'
            m.delete(url, status_code=204)
            m.get(self.baseurl + '/e7833b48-c6f7-47b5-a2a7-36e7dd232758/users', text=response_xml)
            single_group = TSC.GroupItem('test')
            single_group._id = 'e7833b48-c6f7-47b5-a2a7-36e7dd232758'
            self.server.groups.populate_users(single_group)
            self.assertEqual(1, len(single_group.users))
            self.server.groups.remove_user(single_group, 'dd2239f6-ddf1-4107-981a-4cf94e415794')

        self.assertEqual(0, len(single_group.users))

Example 9

Project: kpm Source File: test_registry.py
Function: test_log_in
def test_login():
    r = Registry()
    with requests_mock.mock() as m:
        response = '{"email": "[email protected]", "token": "login_token"}'
        m.post(DEFAULT_REGISTRY + "/api/v1/users/login", complete_qs=True, text=response)
        login_r = r.login("ant31", "plop")
        assert json.dumps(login_r) == json.dumps(json.loads(response))
        assert r.auth.token == "login_token"

Example 10

Project: server-client-python Source File: test_group.py
    def test_add_user_before_populating(self):
        with open(GET_XML, 'rb') as f:
            get_xml_response = f.read().decode('utf-8')
        with open(ADD_USER, 'rb') as f:
            add_user_response = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl, text=get_xml_response)
            m.post('http://test/api/2.3/sites/dad65087-b08b-4603-af4e-2887b8aafc67/groups/ef8b19c0-43b6-11e6-af50'
                   '-63f5805dbe3c/users', text=add_user_response)
            all_groups, pagination_item = self.server.groups.get()
            single_group = all_groups[0]
            self.server.groups.add_user(single_group, '5de011f8-5aa9-4d5b-b991-f462c8dd6bb7')

Example 11

Project: Yatcobot Source File: test_twitterclient.py
Function: test_get_blocks
    @requests_mock.mock()
    def test_get_blocks(self, m):
        with open(self.tests_path + '/fixtures/blocks_ids.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/blocks/ids.json', text=response)
        r = self.client.get_blocks()
        self.assertEqual(len(r), 1)

Example 12

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_get_friends_ids(self, m):
        with open(self.tests_path + '/fixtures/friends_ids.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/friends/ids.json', text=response)
        r = self.client.get_friends_ids()
        self.assertEqual(len(r), 31)

Example 13

Project: django-bulbs Source File: test_liveblog_tasks.py
    def test_update_published(self):

        now = timezone.now()

        with factory.django.mute_signals(signals.post_save):  # Disable triggering method under test
            self.entry.published = now
            self.entry.save()

        with requests_mock.mock() as mocker:
            mocker.patch(self.url, status_code=200)

            firebase_update_entry(self.entry.id)

            self.assertEqual(mocker.call_count, 1)
            self.assertEqual(mocker.request_history[0].json(),
                             {'published': now.isoformat()})

Example 14

Project: Yatcobot Source File: test_twitterclient.py
Function: test_update_ratelimits
    @requests_mock.mock()
    def test_update_ratelimits(self, m):
        #revert original function
        with open(self.tests_path + '/fixtures/application_rate_limit_status.json') as f:
            response = f.read()

        m.get('https://api.twitter.com/1.1/application/rate_limit_status.json', text=response)
        self.client.update_ratelimits(False)
        self.assertEqual(len(self.client.ratelimiter), 80)
        #check if percent is computed
        for x in self.client.ratelimiter.values():
            self.assertIn('percent', x)
            self.assertEqual(x['limit'] / 100 * x['percent'], x['remaining'])

Example 15

Project: server-client-python Source File: test_group.py
Function: test_get
    def test_get(self):
        with open(GET_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl, text=response_xml)
            all_groups, pagination_item = self.server.groups.get()

        self.assertEqual(3, pagination_item.total_available)
        self.assertEqual('ef8b19c0-43b6-11e6-af50-63f5805dbe3c', all_groups[0].id)
        self.assertEqual('All Users', all_groups[0].name)
        self.assertEqual('local', all_groups[0].domain_name)

        self.assertEqual('e7833b48-c6f7-47b5-a2a7-36e7dd232758', all_groups[1].id)
        self.assertEqual('Another group', all_groups[1].name)
        self.assertEqual('local', all_groups[1].domain_name)

        self.assertEqual('86a66d40-f289-472a-83d0-927b0f954dc8', all_groups[2].id)
        self.assertEqual('TableauExample', all_groups[2].name)
        self.assertEqual('local', all_groups[2].domain_name)

Example 16

Project: kpm Source File: test_kubernetes.py
Function: test_get_proxy
def test_get_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response)
        assert json.dumps(k.get()) == json.dumps(json.loads(response))

Example 17

Project: django-bulbs Source File: test_liveblog_tasks.py
Function: test_request_error
    def test_request_error(self):

        with requests_mock.mock() as mocker:
            mocker.delete(self.url, status_code=500)

            with self.assertRaises(HTTPError):
                firebase_delete_entry(self.entry.id)

Example 18

Project: kpm Source File: test_kubernetes.py
Function: test_wait
def test_wait(svc_resource, monkeypatch):
    import time
    monkeypatch.setattr(time, 'sleep', lambda s: None)
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    url2 = "%s/%s/%s" % (k.proxy.geturl(), k.endpoint, k.name)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, [{'status_code': 404}, {'text': response, 'status_code': 200}])
        assert json.dumps(k.wait()) == json.dumps(json.loads(response))
        assert m.call_count == 2

Example 19

Project: server-client-python Source File: test_datasource.py
Function: test_update
    def test_update(self):
        with open(UPDATE_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.put(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', text=response_xml)
            single_datasource = TSC.DatasourceItem('test', '1d0304cd-3796-429f-b815-7258370b9b74')
            single_datasource.owner_id = 'dd2239f6-ddf1-4107-981a-4cf94e415794'
            single_datasource._id = '9dbd2263-16b5-46e1-9c43-a76bb8ab65fb'
            single_datasource = self.server.datasources.update(single_datasource)

        self.assertEqual('9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', single_datasource.id)
        self.assertEqual('1d0304cd-3796-429f-b815-7258370b9b74', single_datasource.project_id)
        self.assertEqual('dd2239f6-ddf1-4107-981a-4cf94e415794', single_datasource.owner_id)

Example 20

Project: kpm Source File: test_registry.py
def test_signup_existing():
    r = Registry()
    with requests_mock.mock() as m:
        response = '{"email": "[email protected]", "token": "signup_token"}'
        m.post(DEFAULT_REGISTRY + "/api/v1/users", complete_qs=True, text=response, status_code=401)
        with pytest.raises(requests.HTTPError):
            sign_r = r.signup("ant31", "plop", "plop", "[email protected]")

Example 21

Project: rxv Source File: test_rxv.py
    @requests_mock.mock()
    def test_discover_zones(self, m):
        rec = rxv.RXV(FAKE_IP)
        m.get(rec.unit_desc_url, text=sample_content('rx-v675-desc.xml'))
        zones = rec.zone_controllers()
        self.assertEqual(len(zones), 2, zones)
        self.assertEqual(zones[0].zone, "Main_Zone")
        self.assertEqual(zones[1].zone, "Zone_2")

Example 22

Project: Yatcobot Source File: test_token_getter.py
Function: test_get_auth
    @requests_mock.mock()
    def test_get_auth(self, m):
        self._set_up_mock(m)

        tokens = get_access_token('test', 'test')
        self.assertEqual(tokens['secret'], '2EEfA6BG3ly3sR3RjE0IBSnlQu4ZrUzPiYKmrkVU')
        self.assertEqual(tokens['token'], '6253282-eWudHldSbIaelX7swmsiHImEL4KinwaGloHANdrY')

Example 23

Project: server-client-python Source File: test_datasource.py
Function: test_update_copy_fields
    def test_update_copy_fields(self):
        with open(UPDATE_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.put(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', text=response_xml)
            single_datasource = TSC.DatasourceItem('test', '1d0304cd-3796-429f-b815-7258370b9b74')
            single_datasource._id = '9dbd2263-16b5-46e1-9c43-a76bb8ab65fb'
            single_datasource._tags = ['a', 'b', 'c']
            single_datasource._project_name = 'Tester'
            updated_datasource = self.server.datasources.update(single_datasource)

        self.assertEqual(single_datasource.tags, updated_datasource.tags)
        self.assertEqual(single_datasource._project_name, updated_datasource._project_name)

Example 24

Project: Yatcobot Source File: test_twitterclient.py
Function: test_get_tweet
    @requests_mock.mock()
    def test_get_tweet(self, m):
        with open(self.tests_path + '/fixtures/statuses_show.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/statuses/show/210462857140252672.json', text=response)
        r = self.client.get_tweet("210462857140252672")
        self.assertEqual(r['id'], 210462857140252672)

Example 25

Project: server-client-python Source File: test_group.py
    def test_add_user_missing_user_id(self):
        with open(POPULATE_USERS, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/e7833b48-c6f7-47b5-a2a7-36e7dd232758/users', text=response_xml)
            single_group = TSC.GroupItem(name='Test Group')
            single_group._id = 'e7833b48-c6f7-47b5-a2a7-36e7dd232758'
            self.server.groups.populate_users(single_group)

        self.assertRaises(ValueError, self.server.groups.add_user, single_group, '')

Example 26

Project: Yatcobot Source File: test_twitterclient.py
Function: test_favorite
    @requests_mock.mock()
    def test_favorite(self, m):
        with open(self.tests_path + '/fixtures/favorites_create.json') as f:
            response = f.read()
        m.post('https://api.twitter.com/1.1/favorites/create.json', text=response)
        r = self.client.favorite(243138128959913986)
        self.assertEqual(r['id'], 243138128959913986)

Example 27

Project: Yatcobot Source File: test_twitterclient.py
Function: test_follow
    @requests_mock.mock()
    def test_follow(self, m):
        with open(self.tests_path + '/fixtures/friendship_create.json') as f:
            response = f.read()
        m.post('https://api.twitter.com/1.1/friendships/create.json', text=response)
        r = self.client.follow(1401881)
        self.assertEqual(r['id'], 1401881)

Example 28

Project: server-client-python Source File: test_group.py
    def test_remove_user_missing_user_id(self):
        with open(POPULATE_USERS, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/e7833b48-c6f7-47b5-a2a7-36e7dd232758/users', text=response_xml)
            single_group = TSC.GroupItem(name='Test Group')
            single_group._id = 'e7833b48-c6f7-47b5-a2a7-36e7dd232758'
            self.server.groups.populate_users(single_group)

        self.assertRaises(ValueError, self.server.groups.remove_user, single_group, '')

Example 29

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_get_mentions_timeline(self, m):
        with open(self.tests_path + '/fixtures/statuses_mentions_timeline.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/statuses/mentions_timeline.json', text=response)
        r = self.client.get_mentions_timeline()
        self.assertEqual(len(r), 2)

Example 30

Project: server-client-python Source File: test_datasource.py
Function: test_download
    def test_download(self):
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/content',
                  headers={'Content-Disposition': 'name="tableau_datasource"; filename="Sample datasource.tds"'})
            file_path = self.server.datasources.download('9dbd2263-16b5-46e1-9c43-a76bb8ab65fb')
            self.assertTrue(os.path.exists(file_path))
        os.remove(file_path)

Example 31

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_get_mentions_timeline_count_1(self, m):
        with open(self.tests_path + '/fixtures/statuses_mentions_timeline_count_1.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/statuses/mentions_timeline.json?count=1', text=response)
        r = self.client.get_mentions_timeline(count=1)
        self.assertEqual(len(r), 1)

Example 32

Project: django-bulbs Source File: test_liveblog_tasks.py
    def test_update_unpublished(self):

        with requests_mock.mock() as mocker:
            mocker.delete(self.url, status_code=200)

            firebase_update_entry(self.entry.id)

            self.assertEqual(mocker.call_count, 1)

Example 33

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_api_call_error(self, m):
        with open(self.tests_path + '/fixtures/error.json') as f:
            response = f.read()
        m.get(requests_mock.ANY, text=response)
        with self.assertRaises(TwitterClientException):
            self.client._api_call('blocks/ids')

Example 34

Project: server-client-python Source File: test_datasource.py
Function: test_get_by_id
    def test_get_by_id(self):
        with open(GET_BY_ID_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', text=response_xml)
            single_datasource = self.server.datasources.get_by_id('9dbd2263-16b5-46e1-9c43-a76bb8ab65fb')

        self.assertEqual('9dbd2263-16b5-46e1-9c43-a76bb8ab65fb', single_datasource.id)
        self.assertEqual('dataengine', single_datasource.datasource_type)
        self.assertEqual('Sampledatasource', single_datasource.content_url)
        self.assertEqual('2016-08-04T21:31:55Z', single_datasource.created_at)
        self.assertEqual('2016-08-04T21:31:55Z', single_datasource.updated_at)
        self.assertEqual('default', single_datasource.project_name)
        self.assertEqual('Sample datasource', single_datasource.name)
        self.assertEqual('ee8c6e70-43b6-11e6-af4f-f7b0d8e20760', single_datasource.project_id)
        self.assertEqual('5de011f8-5aa9-4d5b-b991-f462c8dd6bb7', single_datasource.owner_id)
        self.assertEqual(set(['world', 'indicators', 'sample']), single_datasource.tags)

Example 35

Project: Yatcobot Source File: test_twitterclient.py
    @requests_mock.mock()
    def test_api_call_decrease_remaining_calls(self, m):
        with open(self.tests_path + '/fixtures/blocks_ids.json') as f:
            response = f.read()
        m.get('https://api.twitter.com/1.1/blocks/ids.json', text=response)
        self.client.ratelimiter.check_limit = MagicMock()

        before_remaining = self.client.ratelimiter['/blocks/ids']['remaining']

        self.client._api_call('blocks/ids')

        self.assertEqual(before_remaining - 1, self.client.ratelimiter['/blocks/ids']['remaining'])

Example 36

Project: django-bulbs Source File: test_liveblog_tasks.py
Function: test_delete
    def test_delete(self):

        with requests_mock.mock() as mocker:
            mocker.delete(self.url, status_code=200)

            firebase_delete_entry(self.entry.id)

            self.assertEqual(mocker.call_count, 1)

Example 37

Project: kpm Source File: test_kubernetes.py
def test_get_proxy_404(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s/%s" % (proxy, svc_resource['endpoint'][1:-1], svc_resource['name'])
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.get(url, text=response, status_code=404)
        assert k.get() is None

Example 38

Project: server-client-python Source File: test_group.py
    def test_populate_users(self):
        with open(POPULATE_USERS, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl + '/e7833b48-c6f7-47b5-a2a7-36e7dd232758/users', text=response_xml)
            single_group = TSC.GroupItem(name='Test Group')
            single_group._id = 'e7833b48-c6f7-47b5-a2a7-36e7dd232758'
            pagination_item = self.server.groups.populate_users(single_group)

        self.assertEqual(1, pagination_item.total_available)
        user = single_group.users.pop()
        self.assertEqual('dd2239f6-ddf1-4107-981a-4cf94e415794', user.id)
        self.assertEqual('alice', user.name)
        self.assertEqual('Publisher', user.site_role)
        self.assertEqual('2016-08-16T23:17:06Z', user.last_login)

Example 39

Project: kpm Source File: test_kubernetes.py
def test_create_proxy(svc_resource):
    proxy = "http://localhost:8001"
    k = Kubernetes(body=svc_resource['body'], proxy=proxy, endpoint=svc_resource['endpoint'])
    url = "%s/%s" % (proxy, svc_resource['endpoint'][1:-1])
    url2 = "%s/%s" % (k.proxy.geturl(), k.endpoint)
    assert url == url2
    with requests_mock.mock() as m:
        response = get_response(svc_resource["name"], svc_resource["kind"])
        m.post(url, text=response)
        m.get(url + "/" + svc_resource['name'], status_code=404)
        assert k.create() == "created"

Example 40

Project: django-bulbs Source File: test_tunic.py
    def test_get_active_campaigns(self):
        with requests_mock.mock() as mocker:
            mocker.get('http://onion.local/api/v1/campaign/?active=true',
                       status_code=200,
                       json={'results': [{'id': 1,
                                          'name': 'My Campaign'},
                                         {'id': 2,
                                          'name': 'Another Campaign'}]},
                       headers={'Authorizaton': 'Token 12345'})
            self.assertEqual(TunicClient().get_active_campaigns(),
                             {1: {'id': 1,
                                  'name': 'My Campaign'},
                              2: {'id': 2,
                                  'name': 'Another Campaign'}})

Example 41

Project: kpm Source File: test_registry.py
Function: test_generate
def test_generate():
    r = Registry()
    with requests_mock.mock() as m:
        response = '{"packages": "true"}'
        m.get(DEFAULT_REGISTRY + "/api/v1/packages/ant31/kube-ui/generate", complete_qs=True, text=response)
        assert json.dumps(r.generate(name="ant31/kube-ui")) == response

Example 42

Project: pyup Source File: test_requirements.py
    @requests_mock.mock()
    def test_package_not_found(self, requests):
        requests.get("https://pypi.python.org/pypi/Fango/json", text="404", status_code=404)
        r = Requirement.parse("Fango", 0)
        self.assertEqual(r._fetched_package, False)
        self.assertEqual(r._package, None)

        # this triggers the fetch
        self.assertEqual(r.package, None)
        self.assertEqual(r._fetched_package, True)
        self.assertEqual(r._package, None)

Example 43

Project: kpm Source File: test_registry.py
Function: test_sign_up
def test_signup():
    r = Registry()
    with requests_mock.mock() as m:
        response = '{"email": "[email protected]", "token": "signup_token"}'
        m.post(DEFAULT_REGISTRY + "/api/v1/users", complete_qs=True, text=response)
        sign_r = r.signup("ant31", "plop", "plop", "[email protected]")
        assert json.dumps(sign_r) == json.dumps(json.loads(response))
        assert r.auth.token == "signup_token"

Example 44

Project: django-bulbs Source File: test_tunic.py
Function: test_backend_error
    def test_backend_error(self):
        with self.assertRaises(RequestFailure):
            with requests_mock.mock() as mocker:
                mocker.get('http://onion.local/api/v1/campaign/?active=true',
                           status_code=500,
                           headers={'Authorizaton': 'Token 12345'})
                TunicClient().get_active_campaigns()

Example 45

Project: server-client-python Source File: test_group.py
Function: test_add_user
    def test_add_user(self):
        with open(ADD_USER, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.post(self.baseurl + '/e7833b48-c6f7-47b5-a2a7-36e7dd232758/users', text=response_xml)
            single_group = TSC.GroupItem('test')
            single_group._id = 'e7833b48-c6f7-47b5-a2a7-36e7dd232758'
            single_group._users = set()
            self.server.groups.add_user(single_group, '5de011f8-5aa9-4d5b-b991-f462c8dd6bb7')

        self.assertEqual(1, len(single_group.users))
        user = single_group.users.pop()
        self.assertEqual('5de011f8-5aa9-4d5b-b991-f462c8dd6bb7', user.id)
        self.assertEqual('testuser', user.name)
        self.assertEqual('ServerAdministrator', user.site_role)

Example 46

Project: pyup Source File: test_requirements.py
    @requests_mock.mock()
    def test_package_found(self, requests):
        with open(os.path.dirname(os.path.realpath(__file__)) + "/data/django.json") as f:
            requests.get("https://pypi.python.org/pypi/Django/json", text=f.read())
        r = Requirement.parse("Django==1.9rc1", 0)
        self.assertEqual(r._fetched_package, False)
        self.assertEqual(r._package, None)

        # this triggers the fetch
        self.assertNotEqual(r.package, None)
        self.assertEqual(r._fetched_package, True)
        self.assertNotEqual(r._package, None)

Example 47

Project: server-client-python Source File: test_datasource.py
Function: test_get_empty
    def test_get_empty(self):
        with open(GET_EMPTY_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl, text=response_xml)
            all_datasources, pagination_item = self.server.datasources.get()

        self.assertEqual(0, pagination_item.total_available)
        self.assertEqual([], all_datasources)

Example 48

Project: server-client-python Source File: test_datasource.py
Function: test_publish
    def test_publish(self):
        with open(PUBLISH_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.post(self.baseurl, text=response_xml)
            new_datasource = TSC.DatasourceItem('SampleDS', 'ee8c6e70-43b6-11e6-af4f-f7b0d8e20760')
            new_datasource = self.server.datasources.publish(new_datasource,
                                                             os.path.join(TEST_ASSET_DIR, 'SampleDS.tds'),
                                                             mode=self.server.PublishMode.CreateNew)

        self.assertEqual('e76a1461-3b1d-4588-bf1b-17551a879ad9', new_datasource.id)
        self.assertEqual('SampleDS', new_datasource.name)
        self.assertEqual('SampleDS', new_datasource.content_url)
        self.assertEqual('dataengine', new_datasource.datasource_type)
        self.assertEqual('2016-08-11T21:22:40Z', new_datasource.created_at)
        self.assertEqual('2016-08-17T23:37:08Z', new_datasource.updated_at)
        self.assertEqual('ee8c6e70-43b6-11e6-af4f-f7b0d8e20760', new_datasource.project_id)
        self.assertEqual('default', new_datasource.project_name)
        self.assertEqual('5de011f8-5aa9-4d5b-b991-f462c8dd6bb7', new_datasource.owner_id)

Example 49

Project: server-client-python Source File: test_group.py
    def test_remove_user_before_populating(self):
        with open(GET_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.get(self.baseurl, text=response_xml)
            m.delete('http://test/api/2.3/sites/dad65087-b08b-4603-af4e-2887b8aafc67/groups/ef8b19c0-43b6-11e6-af50'
                     '-63f5805dbe3c/users/5de011f8-5aa9-4d5b-b991-f462c8dd6bb7',
                     text='ok')
            all_groups, pagination_item = self.server.groups.get()
            single_group = all_groups[0]
            self.server.groups.remove_user(single_group, '5de011f8-5aa9-4d5b-b991-f462c8dd6bb7')

Example 50

Project: Yatcobot Source File: test_twitterclient.py
Function: test_unfollow
    @requests_mock.mock()
    def test_unfollow(self, m):
        with open(self.tests_path + '/fixtures/friendship_create.json') as f:
            response = f.read()
        m.post('https://api.twitter.com/1.1/friendships/destroy.json', text=response)
        r = self.client.unfollow(1401881)
        self.assertEqual(r['id'], 1401881)
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4