@@ -126,14 +126,15 @@ def test_response_data(self, mock_requests):
126126 response = self .client .post (url , body )
127127 for key in response .data :
128128 self .assertIn (key , ['uuid' , 'owner' , 'created' , 'updated' , 'app' , 'values' , 'memory' ,
129- 'cpu' , 'tags' ])
129+ 'cpu' , 'tags' , 'registry' ])
130130 expected = {
131131 'owner' : self .user .username ,
132132 'app' : 'test' ,
133133 'values' : {'PORT' : '5000' },
134134 'memory' : {},
135135 'cpu' : {},
136- 'tags' : {}
136+ 'tags' : {},
137+ 'registry' : {}
137138 }
138139 self .assertDictContainsSubset (expected , response .data )
139140
@@ -148,14 +149,15 @@ def test_response_data_types_converted(self, mock_requests):
148149 self .assertEqual (response .status_code , 201 )
149150 for key in response .data :
150151 self .assertIn (key , ['uuid' , 'owner' , 'created' , 'updated' , 'app' , 'values' , 'memory' ,
151- 'cpu' , 'tags' ])
152+ 'cpu' , 'tags' , 'registry' ])
152153 expected = {
153154 'owner' : self .user .username ,
154155 'app' : 'test' ,
155156 'values' : {'PORT' : '5000' },
156157 'memory' : {},
157158 'cpu' : {'web' : "1024" },
158- 'tags' : {}
159+ 'tags' : {},
160+ 'registry' : {}
159161 }
160162 self .assertDictContainsSubset (expected , response .data )
161163
@@ -535,6 +537,76 @@ def test_tags(self, mock_requests):
535537 response = self .client .delete (url )
536538 self .assertEqual (response .status_code , 405 )
537539
540+ def test_registry (self , mock_requests ):
541+ """
542+ Test that registry information can be set on an application
543+ """
544+ url = '/v2/apps'
545+ response = self .client .post (url )
546+ self .assertEqual (response .status_code , 201 )
547+ app_id = response .data ['id' ]
548+
549+ # check default
550+ url = '/v2/apps/{app_id}/config' .format (** locals ())
551+ response = self .client .get (url )
552+ self .assertEqual (response .status_code , 200 )
553+ self .assertIn ('registry' , response .data )
554+ self .assertEqual (response .data ['registry' ], {})
555+
556+ # set some registry information
557+ body = {'registry' : json .dumps ({'username' : 'bob' })}
558+ response = self .client .post (url , body )
559+ self .assertEqual (response .status_code , 201 )
560+ registry1 = response .data
561+
562+ # check registry information again
563+ response = self .client .get (url )
564+ self .assertEqual (response .status_code , 200 )
565+ self .assertIn ('registry' , response .data )
566+ registry = response .data ['registry' ]
567+ self .assertIn ('username' , registry )
568+ self .assertEqual (registry ['username' ], 'bob' )
569+
570+ # set an additional value
571+ # set them upper case, internally it should translate to lower
572+ body = {'registry' : json .dumps ({'PASSWORD' : 's3cur3pw1' })}
573+ response = self .client .post (url , body )
574+ self .assertEqual (response .status_code , 201 )
575+ registry2 = response .data
576+ self .assertNotEqual (registry1 ['uuid' ], registry2 ['uuid' ])
577+ registry = response .data ['registry' ]
578+ self .assertIn ('password' , registry )
579+ self .assertEqual (registry ['password' ], 's3cur3pw1' )
580+ self .assertIn ('username' , registry )
581+ self .assertEqual (registry ['username' ], 'bob' )
582+
583+ # read the registry information again
584+ response = self .client .get (url )
585+ self .assertEqual (response .status_code , 200 )
586+ registry3 = response .data
587+ self .assertEqual (registry2 , registry3 )
588+ registry = response .data ['registry' ]
589+ self .assertIn ('password' , registry )
590+ self .assertEqual (registry ['password' ], 's3cur3pw1' )
591+ self .assertIn ('username' , registry )
592+ self .assertEqual (registry ['username' ], 'bob' )
593+
594+ # unset a value
595+ body = {'registry' : json .dumps ({'password' : None })}
596+ response = self .client .post (url , body )
597+ self .assertEqual (response .status_code , 201 )
598+ registry4 = response .data
599+ self .assertNotEqual (registry3 ['uuid' ], registry4 ['uuid' ])
600+ self .assertNotIn ('password' , json .dumps (response .data ['registry' ]))
601+
602+ # disallow put/patch/delete
603+ response = self .client .put (url )
604+ self .assertEqual (response .status_code , 405 )
605+ response = self .client .patch (url )
606+ self .assertEqual (response .status_code , 405 )
607+ response = self .client .delete (url )
608+ self .assertEqual (response .status_code , 405 )
609+
538610 def test_config_owner_is_requesting_user (self , mock_requests ):
539611 """
540612 Ensure that setting the config value is owned by the requesting user
0 commit comments