Esempio n. 1
0
class TestBeDependQuery(TestCase):
    JUDY_BE_DEPEND_INFO = MockData.read_mock_json_data(
        os.path.join(MOCK_DATA_FILE, 'JudyBeDepend.json'))

    def setUp(self):
        self.query_instance = Query()
        self.be_depend_instance = BeDependRequires()

    def test_normal_query(self):
        self.query_instance.session.query = MagicMock(
            return_value=self.JUDY_BE_DEPEND_INFO)

        result = self.be_depend_instance.get_be_req(binary_list=['Judy'],
                                                    database='os_version_1')
        expect_value = MockData.read_mock_json_data(
            os.path.join(MOCK_DATA_FILE, 'returnJudyResult.json'))

        self.assertEqual(result, expect_value)

    def test_not_exist(self):
        self.query_instance.session.query = MagicMock(return_value={})
        result = self.be_depend_instance.get_be_req(binary_list=['Test'],
                                                    database='os_version_1')

        self.assertEqual(result, [])
Esempio n. 2
0
    def test_normal_query(self):
        self.query_instance.session.query = MagicMock(
            return_value=self.JUDY_BE_DEPEND_INFO)

        result = self.be_depend_instance.get_be_req(binary_list=['Judy'],
                                                    database='os_version_1')
        expect_value = MockData.read_mock_json_data(
            os.path.join(MOCK_DATA_FILE, 'returnJudyResult.json'))

        self.assertEqual(result, expect_value)
Esempio n. 3
0
    def get_data(file_name):
        """
        get mock data
        Args:
            file_name:  mock data file

        Returns: file content

        """
        file_path = os.path.join(MOCK_DATA_FILE, file_name)
        return MockData.read_mock_json_data(file_path)
Esempio n. 4
0
"""
test_be_depend
"""
import json
import os
import sys
import unittest
import argparse
from unittest import mock
from requests.exceptions import ConnectionError as ConnErr
from packageship.application.cli.commands.bedepend import BeDependCommand
from test.base_code.read_mock_data import MockData

MOCK_DATA_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                              "mock_data")
PACKAGES_INFO = MockData.read_mock_json_data(
    os.path.join(MOCK_DATA_FILE, "be_depend.json"))


class Redirect:
    _content = ""

    def write(self, s):
        self._content += s

    def flush(self):
        self._content = ""

    def getvalue(self):
        return self._content

class TestInstallRequireDbQuery(TestCase):
    DATABASE_LIST = ['os_version_1', 'os_version_2']
    JUDY_BINARY_INFO = MockData.read_mock_json_data(
        os.path.join(MOCK_DATA_FILE, "JudyBinary.json"))
    PROVIDES_COMPONENTS_INFO = MockData.read_mock_json_data(
        os.path.join(MOCK_DATA_FILE, "providesComponentsInfo.json"))
    FILES_COMPONENTS_INFO = MockData.read_mock_json_data(
        os.path.join(MOCK_DATA_FILE, "filesComponentsInfo.json"))
    EXPECT_VALUE = MockData.read_mock_json_data(
        os.path.join(MOCK_DATA_FILE, "returnJudyResult.json"))

    def setUp(self):
        """
        Precondition for test cases
        Returns:
        """
        self.query_instance = Query()
        self.install_instance = InstallRequires(
            database_list=self.DATABASE_LIST)

    def test_empty_param(self):
        """
        Test input empty binary_list
        Returns:
        """
        result = self.install_instance.get_install_req(binary_list=[])
        expect_value = []

        self.assertEqual(expect_value, result)

    def test_no_specify_db(self):
        """
        Test not specify database
        Returns:
        """
        self.query_instance.session.query = MagicMock(side_effect=[
            self.JUDY_BINARY_INFO, self.PROVIDES_COMPONENTS_INFO,
            self.FILES_COMPONENTS_INFO
        ])

        result = self.install_instance.get_install_req(binary_list=['Judy'])
        result_require = self._format_return(result)
        expect_require = self._format_return(self.EXPECT_VALUE)

        self.assertEqual(expect_require, result_require)

    def test_specify_db(self):
        """
        Test specify database
        Returns:
        """
        self.query_instance.session.query = MagicMock(side_effect=[
            self.JUDY_BINARY_INFO, self.PROVIDES_COMPONENTS_INFO,
            self.FILES_COMPONENTS_INFO
        ])

        result = self.install_instance.get_install_req(
            binary_list=['Judy'], specify_db='os_version_1')
        result_require = self._format_return(result)
        expect_require = self._format_return(self.EXPECT_VALUE)

        self.assertEqual(expect_require, result_require)

    def test_query_no_data(self):
        """
        Test query for packages that do not exist
        Returns:
        """
        self.query_instance.session.query = MagicMock(return_value={})
        result = self.install_instance.get_install_req(
            binary_list=['Judy'], specify_db='os_version_1')

        self.assertEqual(result, [])

    @staticmethod
    def _format_return(return_data):
        format_data = [
            dict(binary_name=data.get('binary_name'),
                 bin_version=data.get('bin_version'),
                 database=data.get('database'),
                 src_name=data.get('src_name'),
                 src_version=data.get('src_version'),
                 requires=data.get('requires').sort(
                     key=lambda x: x.get('component'))) for data in return_data
        ]
        return format_data
class TestBuildRequireDbQuery(TestCase):
    DATABASE_LIST = ['os_version_1', 'os_version_2']
    JUDY_SOURCE_INFO = MockData.read_mock_json_data(os.path.join(MOCK_DATA_FILE, "JudySource.json"))
    COMPONENTS_INFO = MockData.read_mock_json_data(os.path.join(MOCK_DATA_FILE, "components_info,json"))
    EXCEPT_RETURN_VALUE = MockData.read_mock_json_data(os.path.join(MOCK_DATA_FILE, "returnJudyResult.json"))

    def setUp(self):
        """
        Precondition for test cases
        Returns:
        """
        self.query_instance = Query()
        self.build_instance = BuildRequires(database_list=self.DATABASE_LIST)

    def test_empty_param(self):
        """
        Test input empty source_list
        Returns:
        """
        result = self.build_instance.get_build_req(source_list=[])
        expect_value = []

        self.assertEqual(expect_value, result)

    def test_specify_database(self):
        """
        Test specify database
        Returns:
        """
        self.query_instance.session.query = MagicMock(side_effect=[
            self.JUDY_SOURCE_INFO,
            self.COMPONENTS_INFO
        ])

        result = self.build_instance.get_build_req(source_list=['Judy'], specify_db='os_version_1')

        self.assertEqual(result, self.EXCEPT_RETURN_VALUE)

    def test_no_specify_database(self):
        """
         Test not specify database
         Returns:
         """
        self.query_instance.session.query = MagicMock(side_effect=[
            self.JUDY_SOURCE_INFO,
            self.COMPONENTS_INFO
        ])

        result = self.build_instance.get_build_req(source_list=['Judy'])

        self.assertEqual(result, self.EXCEPT_RETURN_VALUE)

    def test_query_no_data(self):
        """
        Test query for packages that do not exist
        Returns:
        """
        self.query_instance.session.query = MagicMock(return_value={})
        result = self.build_instance.get_build_req(source_list=['Judy'], specify_db='os_version_1')

        self.assertEqual(result, [])