99
1010from django .contrib .auth .models import User
1111from django .core .cache import cache
12+ from django .conf import settings
1213from rest_framework .test import APITransactionTestCase
1314from unittest import mock
1415from rest_framework .authtoken .models import Token
@@ -130,9 +131,11 @@ def test_build_default_containers(self, mock_requests):
130131 app_id = response .data ['id' ]
131132 # post a new build with procfile
132133 url = "/v2/apps/{app_id}/builds" .format (** locals ())
133- body = {'image' : 'autotest/example' ,
134- 'sha' : 'a' * 40 ,
135- 'dockerfile' : "FROM scratch" }
134+ body = {
135+ 'image' : 'autotest/example' ,
136+ 'sha' : 'a' * 40 ,
137+ 'dockerfile' : "FROM scratch"
138+ }
136139 response = self .client .post (url , body )
137140 self .assertEqual (response .status_code , 201 )
138141
@@ -154,10 +157,14 @@ def test_build_default_containers(self, mock_requests):
154157
155158 # post a new build with procfile
156159 url = "/v2/apps/{app_id}/builds" .format (** locals ())
157- body = {'image' : 'autotest/example' ,
158- 'sha' : 'a' * 40 ,
159- 'dockerfile' : "FROM scratch" ,
160- 'procfile' : {'worker' : 'node worker.js' }}
160+ body = {
161+ 'image' : 'autotest/example' ,
162+ 'sha' : 'a' * 40 ,
163+ 'dockerfile' : "FROM scratch" ,
164+ 'procfile' : {
165+ 'worker' : 'node worker.js'
166+ }
167+ }
161168 response = self .client .post (url , body )
162169 self .assertEqual (response .status_code , 201 )
163170
@@ -179,10 +186,14 @@ def test_build_default_containers(self, mock_requests):
179186 # post a new build with procfile
180187
181188 url = "/v2/apps/{app_id}/builds" .format (** locals ())
182- body = {'image' : 'autotest/example' ,
183- 'sha' : 'a' * 40 ,
184- 'procfile' : json .dumps ({'web' : 'node server.js' ,
185- 'worker' : 'node worker.js' })}
189+ body = {
190+ 'image' : 'autotest/example' ,
191+ 'sha' : 'a' * 40 ,
192+ 'procfile' : json .dumps ({
193+ 'web' : 'node server.js' ,
194+ 'worker' : 'node worker.js'
195+ })
196+ }
186197 response = self .client .post (url , body )
187198 self .assertEqual (response .status_code , 201 )
188199
@@ -306,3 +317,33 @@ def test_new_build_does_not_scale_up_automatically(self, mock_requests):
306317 response = self .client .get (url )
307318 self .assertEqual (response .status_code , 200 )
308319 self .assertEqual (len (response .data ['results' ]), 0 )
320+
321+ def test_build_image_in_registry (self , mock_requests ):
322+ """When the image is already in the deis registry no pull/tag/push happens"""
323+ body = {'id' : 'test' }
324+ url = '/v2/apps'
325+ response = self .client .post (url , body )
326+
327+ # post an image as a build using registry hostname
328+ url = "/v2/apps/test/builds" .format (** locals ())
329+ image = '{}/autotest/example' .format (settings .REGISTRY_HOST )
330+ body = {'image' : image }
331+ response = self .client .post (url , body )
332+ self .assertEqual (response .status_code , 201 )
333+
334+ build = Build .objects .get (uuid = response .data ['uuid' ])
335+ release = build .app .release_set .latest ()
336+ # Registry host is internally stripped off
337+ self .assertEqual (release .image , 'autotest/example' )
338+
339+ # post an image as a build using registry hostname + port
340+ url = "/v2/apps/test/builds" .format (** locals ())
341+ image = '{}/autotest/example' .format (settings .REGISTRY_URL )
342+ body = {'image' : image }
343+ response = self .client .post (url , body )
344+ self .assertEqual (response .status_code , 201 )
345+
346+ build = Build .objects .get (uuid = response .data ['uuid' ])
347+ release = build .app .release_set .latest ()
348+ # Registry host + port is internally stripped off
349+ self .assertEqual (release .image , 'autotest/example' )
0 commit comments