コード例 #1
0
    def test_get_items_should_return_a_list_of_available_items(self, mock_urllib2, mock_exists):
        mock_exists.return_value = False
        test_installer_api = InstallerAPI('config_url')
        sample = '{"version": 0, "applications":[%s]}' % json.dumps(self.get_sample_application_config())
        expected_result = [Application.from_configs(self.get_sample_application_config())]
        mock_urllib2.urlopen.return_value = self.make_mock_response(code=200, data=sample)
        init_result = list(test_installer_api.initialize())
        self.assertTrue(init_result[0], init_result[2])

        result = test_installer_api.get_items()

        self.assertEqual(expected_result, result)
コード例 #2
0
    def test_initialize_should_create_correct_application(self, mock_urllib2, mock_exists):
        mock_exists.return_value = True
        mock_urllib2.urlopen.return_value = self.make_mock_response(code=200, data=self.get_sample_web_config())
        mock_open_file = mock_open(read_data=json.dumps(self.get_sample_installed_config()))
        expected_app = Application.from_configs(self.get_sample_application_config(), self.get_sample_installed_config())

        with patch('installer_api.open', mock_open_file, create=True):
            test_installer_api = InstallerAPI('config_url')

            result = test_installer_api.initialize()
            self.assertTrue(result[0])
            apps = test_installer_api.get_items()

            self.assertEquals(1, len(apps))
            self.assertEquals(expected_app, apps[0])