Example #1
0
def get_test_reviews_window():
    from mock import Mock

    appdetails_mock = Mock()
    appdetails_mock.version = "2.0"

    parent = Mock()
    parent.app_details = appdetails_mock

    review_data = Mock()
    review_data.app_name = "app"
    review_data.usefulness_favorable = 10
    review_data.usefulness_total = 12
    review_data.usefulness_submit_error = False
    review_data.reviewer_username = "name"
    review_data.reviewer_displayname = "displayname"
    review_data.date_created = "2011-01-01 18:00:00"
    review_data.summary = "summary"
    review_data.review_text = 10 * "loonng text"
    review_data.rating = "3.0"
    review_data.version = "1.0"

    # create reviewslist
    vb = UIReviewsList(parent)
    vb.add_review(review_data)
    vb.configure_reviews_ui()

    win = Gtk.Window()
    win.set_size_request(200, 200)
    win.add(vb)
    win.connect("destroy", Gtk.main_quit)
    win.show_all()
    return win
Example #2
0
def get_test_reviews_window():
    appdetails_mock = Mock()
    appdetails_mock.version = "2.0"

    parent = Mock()
    parent.app_details = appdetails_mock

    review_data = Mock()
    review_data.app_name = "app"
    review_data.usefulness_favorable = 10
    review_data.usefulness_total = 12
    review_data.usefulness_submit_error = False
    review_data.reviewer_username = "name"
    review_data.reviewer_displayname = "displayname"
    review_data.date_created = "2011-01-01 18:00:00"
    review_data.summary = "summary"
    review_data.review_text = 10 * "loonng text"
    review_data.rating = "3.0"
    review_data.version = "1.0"

    # create reviewslist
    vb = reviews.UIReviewsList(parent)
    vb.add_review(review_data)
    vb.configure_reviews_ui()

    win = get_test_window(child=vb)
    return win
    def check_get_version(self):
        """Check default and override behavior of get_version"""
        node = None
        assert get_version(node) == TRUNK

        node = Mock()
        node.version = None
        assert get_version(node) == TRUNK

        node = Mock()
        node.version = V_0_8_2_2
        assert get_version(node) == V_0_8_2_2
Example #4
0
    def build_mac_mocks(self):

        mac1 = Mock()
        mac1.vendor = "Wirecloud"
        mac1.short_name = "mac1"
        mac1.version = "1.0"
        mac1.template_uri = "Wirecloud_mac1_1.0.wgt"

        mac2 = Mock()
        mac2.vendor = "Wirecloud"
        mac2.short_name = "mac2"
        mac2.version = "1.0"
        mac2.template_uri = "Wirecloud_mac2_1.0.wgt"

        return mac1, mac2
Example #5
0
    def test_all_duplicate_reviews_keeps_going(self, mock_get_reviews):
        """AppDetailsView._reviews_ready_callback will fetch another page if
           all data returned was already displayed in the reviews list.
        """
        # Fixme: Do we have a test factory?
        review = Mock()
        review.rating = 3
        review.date_created = "2011-01-01 18:00:00"
        review.version = "1.0"
        review.summary = "some summary"
        review.review_text = "Some text"
        review.reviewer_username = "name"
        review.reviewer_displayname = "displayname"

        reviews = [review]
        self.view.reviews.reviews = reviews
        self.view._do_load_reviews()

        self.assertEqual(1, mock_get_reviews.call_count)
        kwargs = mock_get_reviews.call_args[1]
        self.assertEqual(False, kwargs["relaxed"])
        self.assertEqual(1, kwargs["page"])

        # Now we come back with no NEW data
        application = mock_get_reviews.call_args[0][0]
        self.view.review_loader.emit("get-reviews-finished", application, reviews)

        self.assertEqual(2, mock_get_reviews.call_count)
        kwargs = mock_get_reviews.call_args[1]
        self.assertEqual(False, kwargs["relaxed"])
        self.assertEqual(2, kwargs["page"])
Example #6
0
def test_simple_step():
    """
	Tests simple_job()
	"""
    conn = Mock()
    emr_jar_info = namedtuple("TestInfo", "name bucket version")
    mock_jar_info = emr_jar_info(name="FooName", bucket="FooBucket", version="FooVersion")
    input_dir = "s3n://foo_bucket/"
    jarargs = []
    options = Mock()
    options.job_name = None
    options.job_log_dir = None
    options.slave_spot_instances = None
    options.bootstrap = None
    options.ami_version = "FooAMIVersion"
    options.classname = "FooClassName"
    options.custom_output = None
    options.ninstances = 100
    options.isize = "m1.xlarge"
    options.debug = None
    options.version = "1.0.3"
    options.job_flow_role = "EMRJobflowDefault"
    options.slave_spot_instances = None
    options.keep_alive = False
    options.visible_to_all_users = False
    dummy_key_pair = "dummy_key_pair"

    bootstrap_action_return_value = [Mock()]
    mock_bootstrap_action.return_value = bootstrap_action_return_value

    job_log_dir = emr_under_test.build_job_log_prefix(emr_jar_info=mock_jar_info, options=options)

    mock_proj_name = emr_under_test._get_project_name(mock_jar_info, options)

    step_return_value = Mock()
    mock_step.return_value = step_return_value

    # Call the actual method under test.
    emr_under_test.simple_job(conn, mock_jar_info, input_dir, jarargs, dummy_key_pair, options)
    mock_step.assert_called_with(
        mock_proj_name, mock_jar_info, input_dir, jarargs, options.classname, options.custom_output
    )

    conn.run_jobflow.assert_called_with(
        name=mock_jar_info.name,
        log_uri=job_log_dir,
        steps=step_return_value,
        num_instances=options.ninstances,
        master_instance_type=options.isize,
        slave_instance_type=options.isize,
        enable_debugging=None,
        hadoop_version=options.version,
        bootstrap_actions=bootstrap_action_return_value,
        instance_groups=None,
        ami_version=options.ami_version,
        ec2_keyname=dummy_key_pair,
        keep_alive=False,
        job_flow_role=options.job_flow_role,
        visible_to_all_users=False,
    )
Example #7
0
 def test_verify_ceph_version_success(self, m_get_package_version, m_gitbuilder_project):
     gb = Mock()
     gb.version = "0.89.0"
     gb.project = "ceph"
     m_gitbuilder_project.return_value = gb
     m_get_package_version.return_value = "0.89.0"
     install.verify_package_version(Mock(), Mock(), Mock())
Example #8
0
 def test_pinned_requirement(self):
     req = Mock()
     req.key = "django"
     req.is_pinned = True
     req.latest_version_within_specs = "1.10"
     req.version = "1.0"
     self.assertEqual(Update.get_commit_message(req), "Update django from 1.0 to 1.10")
Example #9
0
 def test_requirement_pinned(self):
     req = Mock()
     req.key = "django"
     req.is_pinned = True
     req.latest_version_within_specs = "1.10"
     req.version = "1.0"
     self.assertEqual(SequentialUpdate.get_branch(req), "pyup-update-django-1.0-to-1.10")
Example #10
0
def default_args():
    args = Mock()
    args.conf_file = ".lamvery.yml"
    args.alias = "foo"
    args.version = "1"
    args.json = '{"foo": "bar"}'
    return args
Example #11
0
 def test_Adds_niprov_version(self):
     with patch("niprov.adding.pkg_resources") as pkgres:
         dist = Mock()
         dist.version = "5.4.1"
         pkgres.get_distribution.return_value = dist
         image = self.add("p/afile.f")
     self.assertEqual(self.lastProvenance["version-added"], 5.41)
Example #12
0
def default_args():
    args = Mock()
    args.conf_file = ".lamvery.yml"
    args.dry_run = True
    args.publish = True
    args.alias = None
    args.version = None
    return args
Example #13
0
 def test_skip_when_using_ceph_deploy(self, m_get_package_version, m_gitbuilder_project):
     gb = Mock()
     gb.version = "0.89.0"
     gb.project = "ceph"
     m_gitbuilder_project.return_value = gb
     # ceph isn't installed because ceph-deploy would install it
     m_get_package_version.return_value = None
     config = Mock()
     config.extras = True
     install.verify_package_version(Mock(), config, Mock())
Example #14
0
def make_file(pk, file_path, **kwargs):
    obj = Mock()
    obj.id = pk
    for k, v in kwargs.items():
        setattr(obj, k, v)
    obj.file_path = file_path
    obj.__str__ = lambda x: x.pk
    obj.version = Mock()
    obj.version.version = 1
    return obj
    def test_dir_from_spec(self):
        mock = Mock(spec=unittest.TestCase)
        testcase_attrs = set(dir(unittest.TestCase))
        attrs = set(dir(mock))

        # all attributes from the spec are included
        self.assertEqual(set(), testcase_attrs - attrs)

        # shadow a sys attribute
        mock.version = 3
        self.assertEqual(dir(mock).count("version"), 1)
Example #16
0
 def test_verify_ceph_version_failed(self, m_get_package_version, m_gitbuilder_project):
     gb = Mock()
     gb.version = "0.89.0"
     gb.project = "ceph"
     m_gitbuilder_project.return_value = gb
     m_get_package_version.return_value = "0.89.1"
     config = Mock()
     # when it looks for config.get('extras') it won't find it
     config.get.return_value = False
     with pytest.raises(RuntimeError):
         install.verify_package_version(Mock(), config, Mock())
    def test_should_use_usage_information(self, mock_option_parser_class):

        mock_option_parser = Mock()
        mock_values = Mock()
        mock_values.version = False
        mock_values.debug = False
        mock_arguments = ["foo", "bar"]
        mock_option_parser.parse_args.return_value = (mock_values, mock_arguments)
        mock_option_parser_class.return_value = mock_option_parser

        parse_arguments([], version="")

        mock_option_parser_class.assert_called_with(usage=USAGE_INFORMATION)
 def _make_version(self, not_automatic):
     ver = Mock(_Version)
     ver.description = "not_automatic: %s" % not_automatic
     ver.summary = "summary not_automatic: %s" % not_automatic
     ver.version = "version not_automatic: %s" % not_automatic
     mock_origin = Mock()
     if not_automatic:
         mock_origin.archive = "precise-backports"
     else:
         mock_origin.archive = "precise"
     ver.origins = [mock_origin]
     ver.not_automatic = not_automatic
     return ver
Example #19
0
    def test_remove_resources_from_template_url_forwards_conflict_allow_remove(self):

        resource_from_template = Mock()
        resource_from_template.vendor = "Wirecloud"
        resource_from_template.short_name = "test"
        resource_from_template.version = "1.0"
        resource_from_template.fromWGT = True

        migration = self._pick_migration("0007_remove_resources_from_template_url")
        orm = Mock(autospec=migration.orm())
        orm.CatalogueResource.objects.filter.return_value = TestQueryResult([resource_from_template])
        with self.settings(WIRECLOUD_REMOVE_UNSUPPORTED_RESOURCES_MIGRATION=True):
            migration.migration_instance().forwards(orm)
        self.assertEqual(len(resource_from_template.delete.mock_calls), 1)
        orm.CatalogueResource.objects.filter.assert_called_once_with(fromWGT=False)
    def test_should_print_help_screen_and_exit_when_less_than_two_positional_arguments_are_given(
        self, mock_option_parser_class, mock_exit
    ):

        mock_option_parser = Mock()
        mock_values = Mock()
        mock_values.version = False
        mock_values.debug = False
        mock_arguments = [""]
        mock_option_parser.parse_args.return_value = (mock_values, mock_arguments)
        mock_option_parser_class.return_value = mock_option_parser

        parse_arguments([], version="")

        mock_option_parser.print_help.assert_called_with()
        mock_exit.assert_called_with(1)
Example #21
0
 def test_oneshot(self, mock_client):
     expected_assoc = '"well formed HostGuestMapping"'
     expected_report = HostGuestAssociationReport(self.esx.config, expected_assoc)
     updateSet = Mock()
     updateSet.version = "some_new_version_string"
     updateSet.truncated = False
     mock_client.return_value.service.WaitForUpdatesEx.return_value = updateSet
     queue = Queue()
     self.esx.applyUpdates = Mock()
     getHostGuestMappingMock = Mock()
     getHostGuestMappingMock.return_value = expected_assoc
     self.esx.getHostGuestMapping = getHostGuestMappingMock
     self.run_once(queue)
     self.assertEqual(queue.qsize(), 1)
     result_report = queue.get(block=True, timeout=1)
     self.assertEqual(expected_report.config.hash, result_report.config.hash)
     self.assertEqual(expected_report._assoc, result_report._assoc)
Example #22
0
 def test_get_output(self):
     pack = Mock()
     pack.name = "foopack"
     pack.version = "0.1.2"
     pack.maintainers = ["m1", "m2"]
     pack.build_depends = ["bd1", "bd2"]
     pack.run_depends = ["rd1", "rd2"]
     result = _get_output(pack)
     self.assertEqual(
         [
             'set(_CATKIN_CURRENT_PACKAGE "foopack")',
             'set(foopack_RUN_DEPENDS "rd1" "rd2")',
             'set(foopack_VERSION "0.1.2")',
             'set(foopack_MAINTAINER "m1, m2")',
             'set(foopack_BUILD_DEPENDS "bd1" "bd2")',
         ],
         result,
     )
    def test_create_item_empty_body(self):
        """This test case ensures an item can not be created if no body is given."""

        url = "/sample-resources"
        version = "1.0"

        resource = Mock()
        resource.url = url
        resource.version = version

        request = Mock()
        request.body = None

        self._resources_registry.find_by_url = Mock(return_value=resource)

        response = self._controller.create_item(request, version, url)

        self._assert_resource_error(response, 400, 10020, version, url)

        self._resources_registry.find_by_url.assert_called_once_with(url, float(version))
Example #24
0
def test_get_requirements(get_distribution_from_source_file):
    "freeze.get_requirements() Should return a list of imports in a piece of code"

    # Given the following snippet
    code = """
from distlib import util

print(util.in_venv())
"""

    # And a fake distribution
    distribution = Mock()
    distribution.name = "distlib"
    distribution.version = "0.1.2"
    get_distribution_from_source_file.return_value = distribution

    # When I try to figure out which packages I need to run this
    # piece of code
    requirements = freeze.get_requirements(code)

    # Then I see it found the right version of 'distlib' our only
    # requirement here
    requirements.should.equal(["distlib==0.1.2"])
Example #25
0
File: common.py Project: pjc42/nbx
def makeFakeGist():
    gist = Mock()
    gist.description = "Test Gist #notebook #pandas #woo"
    gist.id = 123
    # fake files
    filenames = ["a.ipynb", "b.ipynb", "test.txt"]
    files = {}
    for fn in filenames:
        fo = Mock()
        fo.filename = fn
        fo.content = fn + " content"
        files[fn] = fo

    gist.files = files
    # fake history
    history = []
    dates = pd.date_range("2000", freq="D", periods=4).to_pydatetime()
    for i, date in enumerate(dates):
        state = Mock()
        state.version = i
        state.committed_at = date
        raw_data = {}
        files = {}
        for fn in filenames:
            fo = {"content": "{fn}_{i}_revision_content".format(fn=fn, i=i), "filename": fn}
            files[fn] = fo
        # after 2, don't include 'a.ipynb'
        if i >= 2:
            del files["a.ipynb"]

        raw_data["files"] = files
        state.raw_data = raw_data
        history.append(state)

    gist.history = history

    return gist
Example #26
0
 def test_get_output(self):
     pack = Mock()
     pack.name = "foopack"
     pack.version = "0.1.2"
     pack.maintainers = ["m1", "m2"]
     pack.build_depends = ["bd1", "bd2"]
     pack.buildtool_depends = ["catkin"]
     pack.run_depends = ["rd1", "rd2"]
     pack.exports = []
     result = _get_output(pack)
     self.assertEqual(
         set(
             [
                 'set(_CATKIN_CURRENT_PACKAGE "foopack")',
                 'set(foopack_MAINTAINER "m1, m2")',
                 'set(foopack_DEPRECATED "")',
                 'set(foopack_VERSION "0.1.2")',
                 'set(foopack_BUILD_DEPENDS "bd1" "bd2")',
                 'set(foopack_RUN_DEPENDS "rd1" "rd2")',
                 'set(foopack_BUILDTOOL_DEPENDS "catkin")',
             ]
         ),
         set(result),
     )
Example #27
0
    def test_get_version(self, mock_get_distribution):
        mock_distribution = Mock()
        mock_distribution.version = "1.2.3"
        mock_get_distribution.return_value = mock_distribution

        self.assertEquals(status_manager.get_version(), {"platform_version": "1.2.3"})