def test_get(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {
            'configuration': copy.deepcopy(EXAMPLE_GROUP)
        }
        mock_response.headers = {}

        self.sess.get.return_value = mock_response

        sot = configuration.ConfigurationGroup.new(
            project_id=PROJECT_ID,
            id=IDENTIFIER,
            # **EXAMPLE_GROUP
        )

        result = sot.get(self.sess, headers=OS_HEADERS)

        self.sess.get.assert_called_once_with(
            '%s/configurations/%s' % (PROJECT_ID, IDENTIFIER),
            headers=OS_HEADERS,
        )

        self.assertEqual(
            configuration.ConfigurationGroup(project_id=PROJECT_ID,
                                             **EXAMPLE_GROUP), result)
 def setUp(self):
     super(TestConfigurationGroup, self).setUp()
     self.sess = mock.Mock(spec=adapter.Adapter)
     self.sess.get = mock.Mock()
     self.sess.post = mock.Mock()
     self.sess.delete = mock.Mock()
     self.sess.put = mock.Mock()
     self.sess.patch = mock.Mock()
     self.sess.get_project_id = mock.Mock(return_value=PROJECT_ID)
     self.sot = configuration.ConfigurationGroup(**EXAMPLE_GROUP)
 def test_basic(self):
     sot = configuration.ConfigurationGroup()
     self.assertEqual('configuration', sot.resource_key)
     self.assertEqual('configurations', sot.resources_key)
     self.assertEqual('/%(project_id)s/configurations', sot.base_path)
     self.assertTrue(sot.allow_list)
     self.assertTrue(sot.allow_create)
     self.assertTrue(sot.allow_get)
     self.assertTrue(sot.allow_update)
     self.assertTrue(sot.allow_delete)
    def test_get_associated_instances(self):
        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = []
        mock_response.headers = {}

        self.sess.get.return_value = mock_response

        sot = configuration.ConfigurationGroup(project_id=PROJECT_ID,
                                               **EXAMPLE_GROUP)

        url = '%(project_id)s/configurations/%(id)s/instances' % \
            {
                'project_id': PROJECT_ID,
                'id': sot.id
            }

        # Invoke without endpoint_override
        self._verify2(expected_result=mock_response,
                      mock_method=self.sess.get,
                      test_method=sot.get_associated_instances,
                      method_args=[self.sess],
                      method_kwargs={},
                      expected_args=[url],
                      expected_kwargs={
                          'headers': OS_HEADERS,
                      })

        # Invoke with endpoint_override as argument
        self._verify2(expected_result=mock_response,
                      mock_method=self.sess.get,
                      test_method=sot.get_associated_instances,
                      method_args=[self.sess],
                      method_kwargs={'endpoint_override': ENDPOINT},
                      expected_args=[url],
                      expected_kwargs={
                          'headers': OS_HEADERS,
                          'endpoint_override': ENDPOINT
                      })

        # Invoke with endpoint_override as attribute
        sot.endpoint_override = ENDPOINT
        self._verify2(expected_result=mock_response,
                      mock_method=self.sess.get,
                      test_method=sot.get_associated_instances,
                      method_args=[self.sess],
                      method_kwargs={},
                      expected_args=[url],
                      expected_kwargs={
                          'headers': OS_HEADERS,
                          'endpoint_override': ENDPOINT
                      })
    def test_list(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {'configurations': [EXAMPLE_GROUP]}

        self.sess.get.return_value = mock_response

        result = list(
            self.sot.list(self.sess, project_id=PROJECT_ID,
                          headers=OS_HEADERS))

        self.sess.get.assert_called_once_with('/%s/configurations' %
                                              (PROJECT_ID),
                                              headers=OS_HEADERS,
                                              params={})

        self.assertEqual([configuration.ConfigurationGroup(**EXAMPLE_GROUP)],
                         result)
    def test_delete(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {}
        mock_response.headers = {}

        self.sess.delete.return_value = mock_response

        sot = configuration.ConfigurationGroup(project_id=PROJECT_ID,
                                               **EXAMPLE_GROUP)

        sot.delete(self.sess, headers=OS_HEADERS)

        url = '%(project_id)s/configurations/%(id)s' % \
            {
                'project_id': PROJECT_ID,
                'id': sot.id
            }

        # utils.urljoin strips leading '/', but it is not a problem
        self.sess.delete.assert_called_once_with(url, headers=OS_HEADERS)
    def test_create(self):

        mock_response = mock.Mock()
        mock_response.status_code = 200
        mock_response.json.return_value = {
            'configuration': copy.deepcopy(EXAMPLE_GROUP)
        }
        mock_response.headers = {}

        self.sess.post.return_value = mock_response

        sot = configuration.ConfigurationGroup.new(project_id=PROJECT_ID,
                                                   **EXAMPLE_GROUP)

        result = sot.create(self.sess, headers=OS_HEADERS)

        self.sess.post.assert_called_once_with(
            '/%s/configurations' % (PROJECT_ID),
            headers=OS_HEADERS,
            json={'configuration': EXAMPLE_GROUP})

        self.assertEqual(
            configuration.ConfigurationGroup(project_id=PROJECT_ID,
                                             **EXAMPLE_GROUP), result)
 def test_make_it(self):
     # TODO(agoncharov) check all parameters
     sot = configuration.ConfigurationGroup(**EXAMPLE_GROUP)
     self.assertEqual(IDENTIFIER, sot.id)
     self.assertEqual(EXAMPLE_GROUP['name'], sot.name)
     self.assertEqual(EXAMPLE_GROUP['created'], sot.created)