def test_roger_build_calls_prebuild_hook_when_present(self): settings = mock(Settings) appConfig = mock(AppConfig) dockerUtilsObj = mock(DockerUtils) dockerObj = mock(Docker) roger_build = RogerBuild() roger_build.utils = mock(Utils) mockedHooks = mock(Hooks) roger_env = {} roger_env["registry"] = "any registry" appdata = {} appdata["hooks"] = dict([("pre_build", "some command")]) config = self.config args = self.args args.config_file = 'any.json' args.app_name = 'any app' args.env = 'test' args.directory = '/tmp' data = self.data repo_name = 'test' repo_url = 'test.com' when(roger_build.utils).get_identifier(any(), any(), any()).thenReturn(any()) when(roger_build.utils).extract_app_name(any()).thenReturn("any app") when(settings, strict=False).getConfigDir().thenReturn(any()) when(settings, strict=False).getCliDir().thenReturn(any()) when(settings).getUser().thenReturn(any()) when(appConfig).getRogerEnv(any()).thenReturn(roger_env) when(appConfig).getConfig(any(), any()).thenReturn(config) when(appConfig).getAppData(any(), any(), any()).thenReturn(data) when(appConfig).getRepoUrl(any()).thenReturn(repo_name) when(appConfig).getRepoName(any()).thenReturn(repo_name) when(mockedHooks).run_hook(any(), any(), any(), any(), any(), any()).thenReturn(0) return_code = roger_build.main( settings, appConfig, mockedHooks, dockerUtilsObj, dockerObj, args) verify(mockedHooks).run_hook("pre_build", any(), any(), any())
def test_roger_build(self): try: settings = mock(Settings) appConfig = mock(AppConfig) dockerUtilsObj = mock(DockerUtils) dockerObj = mock(Docker) roger_build = RogerBuild() roger_build.utils = mock(Utils) mockedHooks = mock(Hooks) roger_env = self.roger_env config = self.config data = self.data repo_name = 'test' repo_url = 'test.com' raised_exception = False sc = mock(StatsClient) when(sc).timing(any(), any()).thenReturn(any()) when(roger_build.utils).getStatsClient().thenReturn(sc) when(roger_build.utils).get_identifier(any(), any(), any()).thenReturn(any()) when(roger_build.utils).extract_app_name(any()).thenReturn(any()) when(settings, strict=False).getConfigDir().thenReturn(any()) when(settings, strict=False).getCliDir().thenReturn(any()) when(settings).getUser().thenReturn(any()) when(appConfig).getRogerEnv(any()).thenReturn(roger_env) when(appConfig).getConfig(any(), any()).thenReturn(config) when(appConfig).getAppData(any(), any(), any()).thenReturn(data) when(appConfig).getRepoUrl(any()).thenReturn(repo_name) when(appConfig).getRepoName(any()).thenReturn(repo_name) when(mockedHooks, strict=False).run_hook(any(), any(), any(), any()).thenReturn(0) args = self.args # Setting app_name as empty args.app_name = '' args.env = 'test' args.config_file = 'app.json' args.directory = self.base_dir # with self.assertRaises(ValueError): roger_build.main(settings, appConfig, mockedHooks, dockerUtilsObj, dockerObj, args) except: raised_exception = True self.assertFalse(raised_exception)