コード例 #1
0
 def test_getting_all_successfully(self):
     op = OpenPy(test_key)
     self.requests_mock.return_value.json.return_value = list_of_ethereum_scaffolds
     response = op.ethereum_scaffold.get_all()
     self.assertEqual(response, list_of_ethereum_scaffolds)
     self.requests_mock.assert_called_with(
         base_url_mock('ethereum-scaffolds'), headers=authorization_header)
コード例 #2
0
 def test_getting_single_with_wrong_address(self):
     mock_response = Mock()
     http_error = requests.exceptions.HTTPError()
     mock_response.raise_for_status.side_effect = http_error
     self.requests_mock.return_value = mock_response
     self.requests_mock.return_value.json.return_value = {
         'timestamp':
         '2018-07-25T09:44:00.491+0000',
         'status':
         404,
         'error':
         'Not Found',
         'message':
         'Not Found',
         'path':
         '/api/ethereum_scaffolds/0x0000000000000000000000000000000000000000'
     }
     op = OpenPy(test_key)
     with self.assertRaises(requests.exceptions.HTTPError) as error:
         op.ethereum_scaffold.get_single(valid_address)
     self.requests_mock.assert_called_with(
         base_url_mock('ethereum-scaffolds/' + valid_address),
         headers=authorization_header)
     self.assertTrue(mock_response.raise_for_status.called)
     self.assertEqual('Not Found', str(error.exception))
コード例 #3
0
 def test_getting_single_successfully(self):
     op = OpenPy(test_key)
     self.requests_mock.return_value.json.return_value = ethereum_scaffold
     response = op.ethereum_scaffold.get_single(valid_address)
     self.assertEqual(response, ethereum_scaffold)
     self.requests_mock.assert_called_with(
         base_url_mock('ethereum-scaffolds/' + valid_address),
         headers=authorization_header)
コード例 #4
0
 def test_getting_quota_successfully(self):
     op = OpenPy(test_key)
     result_qouta = {'limitCount': 10, 'currentCount': 4}
     self.requests_mock.return_value.json.return_value = result_qouta
     response = op.ethereum_scaffold.get_quota()
     self.assertEqual(response, result_qouta)
     self.requests_mock.assert_called_with(
         base_url_mock('ethereum-scaffolds/quota'),
         headers=authorization_header)
コード例 #5
0
    def test_deactivating(self, post_mock):
        post_mock.return_value.json.return_value = ethereum_scaffold

        op = OpenPy(test_key)
        response = op.ethereum_scaffold.deactivate(valid_address)

        self.assertEqual(response, ethereum_scaffold)
        post_mock.assert_called_with(base_url_mock('ethereum-scaffolds/' +
                                                   valid_address),
                                     headers=request_headers)
コード例 #6
0
    def test_removing(self, post_mock):
        post_mock.return_value.json.return_value = removing_shareholder
        op = OpenPy(test_key)
        response = op.ethereum_shareholder.remove(valid_address,
                                                  developer_address)

        self.assertEqual(response, removing_shareholder)
        post_mock.assert_called_with(
            base_url_mock('ethereum-scaffolds/' + valid_address + '/holders/' +
                          developer_address),
            headers=request_headers)
コード例 #7
0
    def test_creation(self, post_mock):
        post_mock.return_value.json.return_value = new_shareholders
        op = OpenPy(test_key)
        response = op.ethereum_shareholder.create(
            valid_address, ethereum_shareholder_to_be_added)

        self.assertEqual(response, new_shareholders)
        post_mock.assert_called_with(base_url_mock('ethereum-scaffolds/' +
                                                   valid_address + '/holders'),
                                     json=ethereum_shareholder_to_be_added,
                                     headers=request_headers)
コード例 #8
0
    def test_setting_web_hook(self, post_mock):
        post_mock.return_value.json.return_value = ethereum_scaffold
        web_hook = {'webHook': 'https://zensoft.io'}
        op = OpenPy(test_key)
        response = op.ethereum_scaffold.set_webhook(valid_address, web_hook)

        self.assertEqual(response, ethereum_scaffold)
        post_mock.assert_called_with(base_url_mock('ethereum-scaffolds/' +
                                                   valid_address),
                                     json=web_hook,
                                     headers=request_headers)
コード例 #9
0
    def test_deploying(self, post_mock):
        post_mock.return_value.json.return_value = ethereum_scaffold

        op = OpenPy(test_key)
        response = op.ethereum_scaffold.deploy(ethereum_scaffold_data)

        self.assertEqual(response, ethereum_scaffold)
        post_mock.assert_called_with(
            base_url_mock('ethereum-scaffolds/doDeploy'),
            json=ethereum_scaffold_data,
            headers=request_headers)
コード例 #10
0
    def test_getting_list(self):
        self.requests_mock.return_value = Mock(ok=True)
        self.requests_mock.return_value.json.return_value = list_of_ethereum_scaffolds

        # Send a request to the API server and store the response.
        op = OpenPy(test_key)
        response = op.ethereum_scaffold.get_all()

        # Confirm that the request-response cycle completed successfully.
        self.assertEqual(response, list_of_ethereum_scaffolds)
        self.requests_mock.assert_called_with(
            base_url_mock('ethereum-scaffolds'), headers=authorization_header)
コード例 #11
0
    def test_updating(self, post_mock):
        post_mock.return_value.json.return_value = ethereum_scaffold
        op = OpenPy(test_key)
        response = op.ethereum_shareholder.update(
            valid_address, developer_address,
            ethereum_shareholder_to_be_updated)

        self.assertEqual(response, ethereum_scaffold)
        post_mock.assert_called_with(
            base_url_mock('ethereum-scaffolds/' + valid_address + '/holders/' +
                          developer_address),
            json=ethereum_shareholder_to_be_updated,
            headers=request_headers)
コード例 #12
0
    def test_getting_single_with_wrong_token(self):
        mock_response = Mock()
        http_error = requests.exceptions.HTTPError()
        mock_response.raise_for_status.side_effect = http_error
        self.requests_mock.return_value = mock_response

        invalid_key = 'some_invalid_open_key'
        self.requests_mock.return_value.json.return_value = {
            'status': 401,
            'message': 'Open token is invalid or disabled'
        }
        op = OpenPy(invalid_key)
        with self.assertRaises(requests.HTTPError) as error:
            op.ethereum_scaffold.get_single(valid_address)
        self.assertEqual(str(error.exception),
                         'Open token is invalid or disabled')
        self.requests_mock.assert_called_with(
            base_url_mock('ethereum-scaffolds/' + valid_address),
            headers={'Authorization': invalid_key})
コード例 #13
0
 def test_getting_single_without_token(self):
     with self.assertRaises(AttributeError) as error:
         OpenPy()
     self.assertEqual(str(error.exception), 'open_key can not be empty')