'Test creating a Build via an API Hook'

@mock.patch(u'requests.post', mock_status_ok)
def test_build_hook(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']
    build = {u'username': u'autotest', u'app': app_id}
    url = u'/v1/hooks/builds'.format(**locals())
    body = {u'receive_user': u'autotest', u'receive_repo': app_id, u'image': u'{app_id}:v2'.format(**locals())}
    response = self.client.post(url, json.dumps(body), content_type=u'application/json')
    self.assertEqual(response.status_code, 401)
    response = self.client.post(url, json.dumps(body), content_type=u'application/json', HTTP_X_DEIS_BUILDER_AUTH=settings.BUILDER_KEY)
    self.assertEqual(response.status_code, 200)
    self.assertIn(u'release', response.data)
    self.assertIn(u'version', response.data[u'release'])
    self.assertIn(u'domains', response.data)
