'Test creating a Dockerfile build via an API Hook'

def test_build_hook_dockerfile(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())
    SHA = u'ecdff91c57a0b9ab82e89634df87e293d259a3aa'
    DOCKERFILE = u'\n                                FROM    busybox\n                                CMD    /bin/true\n                                '
    body = {u'receive_user': u'autotest', u'receive_repo': app_id, u'image': u'{app_id}:v2'.format(**locals()), u'sha': SHA, u'dockerfile': DOCKERFILE}
    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)
    url = u'/v1/apps/{app_id}/builds'.format(**locals())
    response = self.client.get(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 200)
    self.assertIn(u'results', response.data)
    build = response.data[u'results'][0]
    self.assertEqual(build[u'sha'], SHA)
    self.assertEqual(build[u'dockerfile'], DOCKERFILE)
    url = u'/v1/apps/{app_id}/containers/cmd'.format(**locals())
    response = self.client.get(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 200)
    self.assertEqual(len(response.data[u'results']), 1)
    container = response.data[u'results'][0]
    self.assertEqual(container[u'type'], u'cmd')
    self.assertEqual(container[u'num'], 1)
