示例#1
0
 def test_gocd_api_service_should_update_returns_false_if_resource_does_not_exist(self):
     data = dict(x='y')
     with patch.multiple(gocd_api.GocdApiRequest, get_entity=DEFAULT) as values:
         values['get_entity'].return_value.status_code = 404
         gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                    self.PASSWORD, data, 'present')
         assert not gocd_api_service.should_update()
示例#2
0
 def test_gocd_api_service_should_create(self, mock_method):
     data = dict(x='y')
     gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                self.PASSWORD, data, 'present')
     result = gocd_api_service.create()
     assert result == dict(a='b')
     mock_method.assert_called_with(data)
示例#3
0
 def test_gocd_api_service_should_update_returns_true_if_resource_already_exists_and_data_is_different(self):
     data = dict(x='y')
     with patch.multiple(gocd_api.GocdApiRequest, get_entity=DEFAULT) as values:
         values['get_entity'].return_value.status_code = 200
         values['get_entity'].return_value.json.return_value = dict(x1='y1')
         gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                    self.PASSWORD, data, 'present')
         assert gocd_api_service.should_update()
示例#4
0
 def test_gocd_api_service_is_data_same_should_return_true_if_data_is_same(self):
     other_data = {
         "location": {
             "city": "",
             "state": None,
             "tags": []
         },
         "name": "Nick's Caffee",
         "reviews": [{}]
     }
     data = {"name": "Nick's Caffee"}
     gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                self.PASSWORD, data, 'absent')
     assert gocd_api_service.is_data_same(other_data)
示例#5
0
    def test_gocd_api_service_should_update_when_etag_is_not_present(self):
        with patch.multiple(gocd_api.GocdApiRequest, get_entity=DEFAULT, put_entity=DEFAULT) as values:
            headers = dict(some_header='some-value')
            data = dict(x='y')
            put_data = dict(put_key='put-value')

            values['get_entity'].return_value.headers = headers
            values['put_entity'].return_value = put_data

            gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                       self.PASSWORD, data, 'present')
            result = gocd_api_service.update()

            assert result == put_data
            values['put_entity'].assert_called_with(None, data)
示例#6
0
 def test_gocd_api_service_is_data_same_should_return_false_if_data_is_not_same_after_removing_ignore_keys(self):
     other_data = {
         "location": {
             "city": "",
             "state": None,
             "tags": []
         },
         "name": "Nick's Caffee Shop",
         "reviews": [{}],
         "ignore_2": [{"x": "y"}, {"x1": "y1"}],
         "_links": "links"
     }
     data = {"name": "Nick's Caffee"}
     gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                self.PASSWORD, data, 'absent')
     assert not gocd_api_service.is_data_same(other_data)
示例#7
0
 def test_gocd_api_service_should_delete_returns_true_if_resource_exist_and_state_is_absent(self):
     with patch.multiple(gocd_api.GocdApiRequest, get_entity=DEFAULT) as values:
         values['get_entity'].return_value.status_code = 200
         gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                    self.PASSWORD, None, 'absent')
         assert gocd_api_service.should_delete()
示例#8
0
 def test_gocd_api_service_should_update_returns_false_if_state_is_absent(self):
     data = dict(x='y')
     gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                self.PASSWORD, data, 'absent')
     assert not gocd_api_service.should_update()
示例#9
0
 def test_gocd_api_service_should_create_returns_false_if_resource_already_exists(self):
     with patch.multiple(gocd_api.GocdApiRequest, get_entity=DEFAULT) as values:
         values['get_entity'].return_value.status_code = 200
         gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                    self.PASSWORD, None, 'present')
         assert not gocd_api_service.should_create()
示例#10
0
 def test_gocd_api_service_should_create_returns_false_if_resource_is_a_non_resource(self):
     gocd_api_service = gocd_api.GocdApiService(self.CONFIG_TYPE, self.DOMAIN, self.ENTITY_ID, self.USERNAME,
                                                self.PASSWORD, None, 'absent')
     assert not gocd_api_service.should_create()