text: """ Quantum Inspire SDK
  
  Copyright 2018 QuTech Delft
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
     http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  """
  import unittest
  from unittest import mock
  
  from coreapi.auth import BasicAuthentication, TokenAuthentication
  from qiskit.providers import QiskitBackendNotFoundError
  
  from quantuminspire.exceptions import ApiError
  from quantuminspire.qiskit.quantum_inspire_provider import QuantumInspireProvider, QI_URL
  
  
  class TestQuantumInspireProvider(unittest.TestCase):
      def test_backends(self):
          with mock.patch('quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI') as api:
              quantum_inpire_provider = QuantumInspireProvider()
              with self.assertRaises(ApiError):
                  quantum_inpire_provider.backends(name='quantum-inspire')
              email = 'bla@bla.bla'
              secret = 'secret'
              quantum_inpire_provider.set_basic_authentication(email, secret)
              authentication = BasicAuthentication(email, secret)
              api.assert_called_with(QI_URL, authentication)
              quantum_inpire_provider._api.get_backend_types.return_value = [{'name': 'qi_simulator', 'is_allowed': True}]
              backend = quantum_inpire_provider.get_backend(name='qi_simulator')
              self.assertEqual('qi_simulator', backend.name())
              with self.assertRaises(QiskitBackendNotFoundError) as error:
                  quantum_inpire_provider.get_backend(name='not-quantum-inspire')
              self.assertEqual(('No backend matches the criteria',), error.exception.args)
  
      def test_set_authentication_details(self):
          with mock.patch('quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI') as api:
              quantum_inpire_provider = QuantumInspireProvider()
              with self.assertRaises(ApiError):
                  quantum_inpire_provider.backends(name='quantum-inspire')
              email = 'bla@bla.bla'
              secret = 'secret'
              quantum_inpire_provider.set_authentication_details(email, secret)
              authentication = BasicAuthentication(email, secret)
              api.assert_called_with(QI_URL, authentication)
              quantum_inpire_provider._api.get_backend_types.return_value = [{'name': 'qi_simulator', 'is_allowed': True}]
              backend = quantum_inpire_provider.get_backend(name='qi_simulator')
              self.assertEqual('qi_simulator', backend.name())
  
      def test_set_basic_authentication(self):
          with mock.patch('quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI') as api:
              quantum_inpire_provider = QuantumInspireProvider()
              with self.assertRaises(ApiError):
                  quantum_inpire_provider.backends(name='quantum-inspire')
              email = 'bla@bla.bla'
              secret = 'secret'
              quantum_inpire_provider.set_basic_authentication(email, secret)
              authentication = BasicAuthentication(email, secret)
              api.assert_called_with(QI_URL, authentication)
              quantum_inpire_provider._api.get_backend_types.return_value = [{'name': 'qi_simulator', 'is_allowed': True}]
              backend = quantum_inpire_provider.get_backend(name='qi_simulator')
              self.assertEqual('qi_simulator', backend.name())
  
      def test_set_basic_authentication_with_url(self):
          with mock.patch('quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI') as api:
              api.get_backend_types.return_value = [{'name': 'qi_simulator', 'is_allowed': True}]
              quantum_inpire_provider = QuantumInspireProvider()
              with self.assertRaises(ApiError):
                  quantum_inpire_provider.backends(name='quantum-inspire')
              email = 'bla@bla.bla'
              secret = 'secret'
              url = 'https/some-api.api'
              quantum_inpire_provider.set_basic_authentication(email, secret, url)
              authentication = BasicAuthentication(email, secret)
              api.assert_called_with(url, authentication)
  
      def test_set_token_authentication(self):
          with mock.patch('quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI') as api:
              quantum_inpire_provider = QuantumInspireProvider()
              with self.assertRaises(ApiError):
                  quantum_inpire_provider.backends(name='quantum-inspire')
              token = 'This_is_a_nice_looking_token'
              quantum_inpire_provider.set_token_authentication(token)
              api.assert_called_once()
  
      def test_set_authentication(self):
          with mock.patch('quantuminspire.qiskit.quantum_inspire_provider.QuantumInspireAPI') as api:
              quantum_inpire_provider = QuantumInspireProvider()
              with self.assertRaises(ApiError):
                  quantum_inpire_provider.backends(name='quantum-inspire')
              token = 'This_is_a_nice_looking_token'
              authentication = TokenAuthentication(token, scheme="token")
              quantum_inpire_provider.set_authentication(authentication)
              api.assert_called_with(QI_URL, authentication)
              authentication = BasicAuthentication('email', 'password')
              quantum_inpire_provider.set_authentication(authentication)
              api.assert_called_with(QI_URL, authentication)
  
      def test_string_method(self):
          quantum_inpire_provider = QuantumInspireProvider()
          expected = 'QI'
          actual = str(quantum_inpire_provider)
          self.assertEqual(expected, actual)
  