'Test that a null build is created and that users can post new builds'

@mock.patch(u'requests.post', mock_status_ok)
def test_build(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}/builds'.format(**locals())
    response = self.client.get(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 200)
    self.assertEqual(response.data[u'count'], 0)
    body = {u'image': u'autotest/example'}
    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, 201)
    build_id = response.data[u'uuid']
    build1 = response.data
    self.assertEqual(response.data[u'image'], body[u'image'])
    url = u'/v1/apps/{app_id}/builds/{build_id}'.format(**locals())
    response = self.client.get(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 200)
    build2 = response.data
    self.assertEqual(build1, build2)
    url = u'/v1/apps/{app_id}/builds'.format(**locals())
    body = {u'image': u'autotest/example'}
    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, 201)
    self.assertIn(u'x-deis-release', response._headers)
    build3 = response.data
    self.assertEqual(response.data[u'image'], body[u'image'])
    self.assertNotEqual(build2[u'uuid'], build3[u'uuid'])
    response = self.client.put(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 405)
    response = self.client.patch(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 405)
    response = self.client.delete(url, HTTP_AUTHORIZATION=u'token    {}'.format(self.token))
    self.assertEqual(response.status_code, 405)
