Example #1
0
 def setUp(self):
     self.symbols = []
     # columns
     self.columns_count = -1
     for i in range(0, 8, 1):
         symbol = Mock()
         symbol.location = (
             (0 + (7 - i) * 20, 0),
             ((7 - i) * 20, 10),
             (10 + (7 - i) * 20, 10),
             (10 + (7 - i) * 20, 0),
         )
         symbol.data = "__"
         self.symbols.append(symbol)
         self.columns_count += 1
     # cards
     self.cards_count = 0
     for i in range(0, 7, 1):
         symbol = Mock()
         symbol.location = ((5 + i * 20, 5), (5 + i * 20, 15), (15 + i * 20, 15), (15 + i * 20, 5))
         symbol.data = "T" + str(i) * 5
         self.symbols.append(symbol)
         self.cards_count += 1
     # config symbol
     symbol = Mock()
     symbol.location = ((50, 50), (50, 60), (60, 60), (60, 50))
     self.board_id = 1
     symbol.data = "[%d,%d]" % (self.board_id, self.columns_count)
     self.symbols.append(symbol)
    def test_linked_problem(self):
        """
        Check to see if a peer grading module with a linked problem loads properly.
        """

        # Mock the linked problem descriptor.
        linked_descriptor = Mock()
        linked_descriptor.location = self.coe_location

        # Mock the peer grading descriptor.
        pg_descriptor = Mock()
        pg_descriptor.location = self.problem_location
        pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor]

        # Setup the proper field data for the peer grading module.
        field_data = DictFieldData(
            {
                "data": "<peergrading/>",
                "location": self.problem_location,
                "use_for_single_location": True,
                "link_to_location": self.coe_location,
            }
        )

        # Initialize the peer grading module.
        peer_grading = PeerGradingModule(
            pg_descriptor,
            self.test_system,
            field_data,
            ScopeIds(None, None, self.problem_location, self.problem_location),
        )

        # Ensure that it is properly setup.
        self.assertTrue(peer_grading.use_for_single_location)
Example #3
0
    def create(system, source_is_error_module=False):
        """
        return a dict of modules: the conditional with a single source and a single child.
        Keys are 'cond_module', 'source_module', and 'child_module'.

        if the source_is_error_module flag is set, create a real ErrorModule for the source.
        """
        descriptor_system = get_test_descriptor_system()

        # construct source descriptor and module:
        source_location = Location("edX", "conditional_test", "test_run", "problem", "SampleProblem", None)
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                "some random xml data",
                system,
                id_generator=CourseLocationManager(source_location.course_key),
                error_msg="random error message",
            )
        else:
            source_descriptor = Mock(name="source_descriptor")
            source_descriptor.location = source_location

        source_descriptor.runtime = descriptor_system
        source_descriptor.render = lambda view, context=None: descriptor_system.render(source_descriptor, view, context)

        # construct other descriptors:
        child_descriptor = Mock(name="child_descriptor")
        child_descriptor._xmodule.student_view.return_value.content = u"<p>This is a secret</p>"
        child_descriptor.student_view = child_descriptor._xmodule.student_view
        child_descriptor.displayable_items.return_value = [child_descriptor]
        child_descriptor.runtime = descriptor_system
        child_descriptor.xmodule_runtime = get_test_system()
        child_descriptor.render = lambda view, context=None: descriptor_system.render(child_descriptor, view, context)
        child_descriptor.location = source_location.replace(category="html", name="child")

        def load_item(usage_id, for_parent=None):  # pylint: disable=unused-argument
            """Test-only implementation of load_item that simply returns static xblocks."""
            return {child_descriptor.location: child_descriptor, source_location: source_descriptor}.get(usage_id)

        descriptor_system.load_item = load_item

        system.descriptor_runtime = descriptor_system

        # construct conditional module:
        cond_location = Location("edX", "conditional_test", "test_run", "conditional", "SampleConditional", None)
        field_data = DictFieldData(
            {"data": "<conditional/>", "xml_attributes": {"attempted": "true"}, "children": [child_descriptor.location]}
        )

        cond_descriptor = ConditionalDescriptor(
            descriptor_system, field_data, ScopeIds(None, None, cond_location, cond_location)
        )
        cond_descriptor.xmodule_runtime = system
        system.get_module = lambda desc: desc
        cond_descriptor.get_required_module_descriptors = Mock(return_value=[source_descriptor])

        # return dict:
        return {"cond_module": cond_descriptor, "source_module": source_descriptor, "child_module": child_descriptor}
Example #4
0
    def test_distance(self):
        from warlord.path import distance

        tileA = Mock()
        tileB = Mock()
        tileA.location = (0, 0)
        tileB.location = (0, 1)
        self.assertEquals(distance(tileA, tileB), 1)
def mock_descriptor(fields=[], lms_fields=[]):
    descriptor = Mock()
    descriptor.stores_state = True
    descriptor.location = location("def_id")
    descriptor.module_class.fields = fields
    descriptor.module_class.lms.fields = lms_fields
    return descriptor
def mock_descriptor(fields=[], lms_fields=[]):
    descriptor = Mock()
    descriptor.location = location("def_id")
    descriptor.module_class.fields = fields
    descriptor.module_class.lms.fields = lms_fields
    descriptor.module_class.__name__ = "MockProblemModule"
    return descriptor
def mock_descriptor(fields=[]):
    descriptor = Mock()
    descriptor.location = location("def_id")
    descriptor.module_class.fields.values.return_value = fields
    descriptor.fields.values.return_value = fields
    descriptor.module_class.__name__ = "MockProblemModule"
    return descriptor
Example #8
0
 def test_scanned_columns_count_is_equal_to_config_column_count(self):
     symbols = []
     symbol = Mock()
     symbol.location = ((50, 50), (50, 60), (60, 60), (60, 50))
     columns_count = 1
     symbol.data = "[1,%d]" % (columns_count)
     symbols.append(symbol)
     self.assertRaises(IOError, mapper.Mapper, (symbols))
Example #9
0
    def test_combat_raises_out_of_range_when_not_in_range(self):
        from warlord.combat import UnitOutOfRangeError, combat

        unitA = Mock()
        unitB = Mock()
        weapon = Mock()
        weapon.attack_range = [0]
        unitA.equipped_item = weapon
        tileA = Mock()
        tileA.location = (0, 0)
        tileA.unit = unitA
        unitA.tile = tileA
        tileB = Mock()
        tileB.location = (0, 2)
        tileB.unit = unitB
        unitB.tile = tileB
        self.assertRaises(UnitOutOfRangeError, combat, unitA, unitB)
Example #10
0
    def test_usingCopyAsParent(self):
        from niprov.commandline import Commandline

        self.dependencies.config.verbosity = "info"
        cmd = Commandline(self.dependencies)
        cmd.log = Mock()
        copy = Mock()
        copy.location = "moon:/copy/location"
        cmd.usingCopyAsParent(copy)
        cmd.log.assert_called_with("warning", "Used provenance from copy found at " + str(copy.location))
Example #11
0
    def create(system, source_is_error_module=False):
        """
        return a dict of modules: the conditional with a single source and a single child.
        Keys are 'cond_module', 'source_module', and 'child_module'.

        if the source_is_error_module flag is set, create a real ErrorModule for the source.
        """
        descriptor_system = get_test_descriptor_system()

        # construct source descriptor and module:
        source_location = Location(["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                "some random xml data",
                system,
                org=source_location.org,
                course=source_location.course,
                error_msg="random error message",
            )
        else:
            source_descriptor = Mock()
            source_descriptor.location = source_location

        source_descriptor.runtime = descriptor_system
        source_descriptor.render = lambda view, context=None: descriptor_system.render(source_descriptor, view, context)

        # construct other descriptors:
        child_descriptor = Mock()
        child_descriptor._xmodule.student_view.return_value.content = u"<p>This is a secret</p>"
        child_descriptor.student_view = child_descriptor._xmodule.student_view
        child_descriptor.displayable_items.return_value = [child_descriptor]
        child_descriptor.runtime = descriptor_system
        child_descriptor.xmodule_runtime = get_test_system()
        child_descriptor.render = lambda view, context=None: descriptor_system.render(child_descriptor, view, context)

        descriptor_system.load_item = {"child": child_descriptor, "source": source_descriptor}.get

        # construct conditional module:
        cond_location = Location(["i4x", "edX", "conditional_test", "conditional", "SampleConditional"])
        field_data = DictFieldData(
            {"data": "<conditional/>", "xml_attributes": {"attempted": "true"}, "children": ["child"]}
        )

        cond_descriptor = ConditionalDescriptor(
            descriptor_system, field_data, ScopeIds(None, None, cond_location, cond_location)
        )
        cond_descriptor.xmodule_runtime = system
        system.get_module = lambda desc: desc
        cond_descriptor.get_required_module_descriptors = Mock(return_value=[source_descriptor])

        # return dict:
        return {"cond_module": cond_descriptor, "source_module": source_descriptor, "child_module": child_descriptor}
Example #12
0
    def test_do_build_oserror(self):
        """Test running of do_build"""
        from unuo.docker import Docker_1_1_x

        with patch.object(Docker_1_1_x, "run_and_log") as run_and_log:
            run_and_log.side_effect = OSError(1, "oh no")
            logmanager = Mock()
            build = Mock()
            build.repo = "arepo"
            build.dockertag = "atag"
            build.location = "alocation"
            docker = Docker_1_1_x(logmanager)
            self.assertEquals("oh no", docker.do_build(build).next())
    def _create_peer_grading_with_linked_problem(self, location, valid_linked_descriptor=True):
        """
        Create a peer grading problem with a linked location.
        """

        # Mock the linked problem descriptor.
        linked_descriptor = Mock()
        linked_descriptor.location = location

        # Mock the peer grading descriptor.
        pg_descriptor = Mock()
        pg_descriptor.location = self.problem_location

        if valid_linked_descriptor:
            pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor]
        else:
            pg_descriptor.get_required_module_descriptors = lambda: []

        # Initialize the peer grading module.
        peer_grading = PeerGradingModule(pg_descriptor, self.test_system, self.field_data, self.scope_ids)

        return peer_grading
    def _create_peer_grading_with_linked_problem(self, location, valid_linked_descriptor=True):
        """
        Create a peer grading problem with a linked location.
        """

        # Mock the linked problem descriptor.
        linked_descriptor = Mock()
        linked_descriptor.location = location

        # Mock the peer grading descriptor.
        pg_descriptor = Mock()
        pg_descriptor.location = self.problem_location

        if valid_linked_descriptor:
            pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor]
        else:
            pg_descriptor.get_required_module_descriptors = lambda: []

        # Setup the proper field data for the peer grading module.
        field_data = DictFieldData(
            {
                "data": "<peergrading/>",
                "location": self.problem_location,
                "use_for_single_location": True,
                "link_to_location": self.coe_location.url(),
                "graded": True,
            }
        )

        # Initialize the peer grading module.
        peer_grading = PeerGradingModule(
            pg_descriptor,
            self.test_system,
            field_data,
            ScopeIds(None, None, self.problem_location, self.problem_location),
        )

        return peer_grading
    def create(system, source_is_error_module=False):
        """
        return a dict of modules: the conditional with a single source and a single child.
        Keys are 'cond_module', 'source_module', and 'child_module'.

        if the source_is_error_module flag is set, create a real ErrorModule for the source.
        """
        # construct source descriptor and module:
        source_location = Location(["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                "some random xml data",
                system,
                org=source_location.org,
                course=source_location.course,
                error_msg="random error message",
            )
            source_module = source_descriptor.xmodule(system)
        else:
            source_descriptor = Mock()
            source_descriptor.location = source_location
            source_module = Mock()

        # construct other descriptors:
        child_descriptor = Mock()
        cond_descriptor = Mock()
        cond_descriptor.runtime = system
        cond_descriptor.get_required_module_descriptors = lambda: [source_descriptor]
        cond_descriptor.get_children = lambda: [child_descriptor]
        cond_descriptor.xml_attributes = {"attempted": "true"}

        # create child module:
        child_module = Mock()
        child_module.runtime = system
        child_module.get_html.return_value = u"<p>This is a secret</p>"
        child_module.student_view.return_value = Fragment(child_module.get_html.return_value)
        child_module.displayable_items = lambda: [child_module]
        module_map = {source_descriptor: source_module, child_descriptor: child_module}
        system.get_module = lambda descriptor: module_map[descriptor]

        # construct conditional module:
        cond_location = Location(["i4x", "edX", "conditional_test", "conditional", "SampleConditional"])
        field_data = DictFieldData({"data": "<conditional/>", "location": cond_location})
        cond_module = ConditionalModule(
            cond_descriptor, system, field_data, ScopeIds(None, None, cond_location, cond_location)
        )

        # return dict:
        return {"cond_module": cond_module, "source_module": source_module, "child_module": child_module}
Example #16
0
    def test_do_build(self):
        """Test running of do_build"""
        from unuo.docker import Docker_1_1_x

        with patch.object(Docker_1_1_x, "run_and_log") as run_and_log:
            logmanager = Mock()
            build = Mock()
            build.repo = "arepo"
            build.dockertag = "atag"
            build.location = "alocation"
            build.push = True
            run_and_log.return_value = ["line1", "line2"]
            with patch("unuo.docker.shutil.rmtree") as rmtree:
                rmtree.return_value = None
                docker = Docker_1_1_x(logmanager)
                for line in docker.do_build(build):
                    pass
Example #17
0
    def test_do_build_shutil_errror(self):
        """Test running of do_build"""
        from unuo.docker import Docker_1_1_x

        with patch.object(Docker_1_1_x, "run_and_log") as run_and_log:
            with patch("unuo.docker.shutil.rmtree") as rmtree:
                rmtree.side_effect = Exception("noooo")
                run_and_log.return_value = ["pass"]
                logmanager = Mock()
                build = Mock()
                build.repo = "arepo"
                build.dockertag = "atag"
                build.location = "alocation"
                build.push = False
                docker = Docker_1_1_x(logmanager)
                g = docker.do_build(build)
                self.assertEquals("pass", g.next())
                self.assertEquals("pass", g.next())
                self.assertEquals("!! Unable to remove build folder", g.next())
def get_order_form(ready_by, order_method):
    site = Site.objects.all()[0]
    location = site.location_set.all()[0]
    request = Mock()
    request.site = site
    request.location = location
    form = OrderForm(
        {
            "name": "John Smith",
            "phone": "12345",
            "ready_by_0": ready_by.strftime("%I"),
            "ready_by_1": ready_by.strftime("%M"),
            "ready_by_2": ready_by.strftime("%p"),
            "method": order_method,
        },
        request=request,
    )
    form.total = "40.00"
    return form
Example #19
0
 def fileWithP(self, provenance, protocol=None):
     mfile = Mock()
     mfile.location = "afilename"
     mfile.getProvenance.return_value = provenance
     mfile.getProtocolFields.return_value = protocol
     return mfile
Example #20
0
    def test_that_it_correctly_fetches_the_item_geometry(self):
        mock_item = Mock()
        mock_item.location = "location"

        eq_("location", self.feed.item_geometry(mock_item))