Beispiel #1
0
 def test_valid_response(self, mock_post):
     self.api = gist.Gist('123123123')
     self.mock_response.status_code = 201
     with open(get_output('gist.json'), 'r') as f:
         content = json.load(f)
         self.mock_response.json.return_value = content
     mock_post.return_value = self.mock_response
     self.assertEqual(
         self.api.create({
             'files': {
                 'file.txt': {
                     'content': 'file with content'
                 }
             },
             'description': 'gist description'
         }), content)
Beispiel #2
0
 def test_proxies_property(self):
     tests = [
         {
             'proxies': {
                 'http_proxy': '123.123.123.123'
             },
             'expected': {}
         },
         {
             'proxies': {
                 'http_proxy': None
             },
             'expected': {}
         },
         {
             'proxies': {
                 'https_proxy': None,
                 'http_proxy': 'http://12.1'
             },
             'expected': {}
         },
         {
             'proxies': {
                 'http_proxy': 'localhost:9090'
             },
             'expected': {}
         },
         {
             'proxies': {
                 'http_proxy': 'http://localhost:9090'
             },
             'expected': {
                 'http': 'http://localhost:9090'
             }
         },
         {
             'proxies': {
                 'http_proxy': 'http://localhost:9090',
                 'https_proxy': None
             },
             'expected': {
                 'http': 'http://localhost:9090'
             }
         },
         {
             'proxies': {
                 'https_proxy': 'https://localhost:9090',
                 'http_proxy': None
             },
             'expected': {
                 'https': 'https://localhost:9090'
             }
         },
         {
             'proxies': {
                 'https_proxy': 'https://localhost:9090',
                 'http_proxy': 'http://localhost:9090',
             },
             'expected': {
                 'https': 'https://localhost:9090',
                 'http': 'http://localhost:9090',
             }
         },
     ]
     for test in tests:
         g = gist.Gist(**test['proxies'])
         self.assertDictEqual(test['expected'], g.proxies)
Beispiel #3
0
 def test_raise_authentication_error_without_token(self):
     self.api = gist.Gist()
     with self.assertRaises(gist.AuthenticationError):
         self.api.update('123', {})
Beispiel #4
0
 def setUp(self):
     self.api = gist.Gist()
     self.mock_response = mock.Mock()
Beispiel #5
0
 def setUp(self):
     self.api = gist.Gist('access token')
     self.mock_response = mock.Mock()
Beispiel #6
0
    def test_success_delete(self, mock_delete):
        self.api = gist.Gist('123123')
        self.mock_response.status_code = 204
        mock_delete.return_value = self.mock_response

        self.assertTrue(self.api.delete('123123'))
Beispiel #7
0
    def test_failed_delete(self, mock_delete):
        self.api = gist.Gist('123123')
        self.mock_response.status_code = 205
        mock_delete.return_value = self.mock_response

        self.assertFalse(self.api.delete('123123'))
Beispiel #8
0
 def test_argument_exception_without_id(self):
     self.api = gist.Gist('123123')
     with self.assertRaises(ValueError):
         self.api.delete('')
Beispiel #9
0
 def test_raise_argument_exception_with_no_dict(self):
     self.api = gist.Gist('some_access_token')
     with self.assertRaises(ValueError):
         self.api.create('')
Beispiel #10
0
 def test_unprocessable_data_error(self, mock_patch):
     self.mock_response.status_code = 422
     mock_patch.return_value = self.mock_response
     self.api = gist.Gist('some_access_token')
     with self.assertRaises(gist.UnprocessableDataError):
         self.api.update('123123123', {'description': 'some description'})
Beispiel #11
0
 def test_argument_exception_without_data(self):
     self.api = gist.Gist('some_access_token')
     with self.assertRaises(ValueError):
         self.api.create({})