'Test that config won\'t be created if a similar operation
is in progress for that app.'

@mock.patch(u'requests.post', mock_status_ok)
def test_overlapping_config(self):

    url = u'/v1/apps'
    response = self.client.post(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 201)
    app_id = response.data[u'id']
    url = u'/v1/apps/{app_id}/config'.format(**locals())
    response = self.client.get(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 200)
    self.assertIn(u'values', response.data)
    self.assertEqual(response.data[u'values'], {})
    config1 = response.data
    lockfile = os.path.join(tempfile.gettempdir(), (app_id + u'-config'))
    with SimpleFlock(lockfile):
        body = {u'values': json.dumps({u'NEW_URL1': u'http://localhost:8080/'})}
        response = self.client.post(url, json.dumps(body), content_type=u'application/json', HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
        self.assertEqual(response.status_code, 409)
        self.assertNotIn(u'values', response.data)
        self.assertNotIn(u'uuid', response.data)
    response = self.client.get(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 200)
    config2 = response.data
    self.assertEqual(config1, config2)
    self.assertNotIn(u'NEW_URL1', response.data[u'values'])
