Пример #1
0
 def _test(cnt_type, parent_repr_name, children_repr_name):
     entity = create_entity()
     mb = MyEntityMember.create_from_entity(entity)
     mp_reg = get_mapping_registry(cnt_type)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     de = mp.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     self.assert_true(prx.get_data_element() is de)
     self.assert_equal(prx.id, 0)
     self.assert_equal(prx.text, 'TEXT')
     self.assert_equal(prx.number, 1)
     # The parent and children attributes are links.
     self.assert_true(isinstance(getattr(prx, parent_repr_name),
                                 LinkedDataElement))
     children_el = getattr(prx, children_repr_name)
     if cnt_type is XmlMime:
         self.assert_is_none(children_el)
     else:
         self.assert_true(isinstance(children_el, LinkedDataElement))
     # Nonexisting attribute raises error.
     self.assert_raises(AttributeError, getattr, prx, 'foo')
     self.assert_raises(AttributeError, setattr, prx, 'foo', 'murks')
     # Set terminal attribute.
     prx.id = 1
     self.assert_equal(prx.id, 1)
     # Set nested attribute.
     setattr(prx, parent_repr_name, None)
     self.assert_is_none(getattr(prx, parent_repr_name))
     self.assert_raises(ValueError, setattr, prx, parent_repr_name,
                        1)
Пример #2
0
 def _test(mb, cnt_type, parent_repr_name, children_repr_name):
     mp_reg = get_mapping_registry(cnt_type)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     de = mp.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     assert prx.get_data_element() is de
     assert prx.id == 0
     assert prx.text == 'TEXT'
     assert prx.number == 1
     if cnt_type is XmlMime:
         # The parent attribute is a link.
         assert isinstance(getattr(prx, parent_repr_name),
                           LinkedDataElement)
         with pytest.raises(AttributeError):
             dummy = getattr(prx, children_repr_name)
     else:
         assert isinstance(getattr(prx, parent_repr_name),
                           DataElementAttributeProxy)
         children_el = getattr(prx, children_repr_name)
         assert isinstance(children_el, LinkedDataElement)
     # Nonexisting attribute raises error.
     with pytest.raises(AttributeError):
         dummy = getattr(prx, 'foo')
     with pytest.raises(AttributeError):
         setattr(prx, 'foo', 'murks')
     # Set terminal attribute.
     prx.id = 1
     assert prx.id == 1
     # Set nested attribute.
     setattr(prx, parent_repr_name, None)
     assert getattr(prx, parent_repr_name) is None
     with pytest.raises(ValueError):
         setattr(prx, parent_repr_name, 1)
Пример #3
0
 def _test(cnt_type, parent_repr_name, children_repr_name):
     entity = create_entity()
     mb = MyEntityMember.create_from_entity(entity)
     mp_reg = get_mapping_registry(cnt_type)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     de = mp.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     self.assert_true(prx.get_data_element() is de)
     self.assert_equal(prx.id, 0)
     self.assert_equal(prx.text, 'TEXT')
     self.assert_equal(prx.number, 1)
     # The parent and children attributes are links.
     self.assert_true(
         isinstance(getattr(prx, parent_repr_name), LinkedDataElement))
     children_el = getattr(prx, children_repr_name)
     if cnt_type is XmlMime:
         self.assert_is_none(children_el)
     else:
         self.assert_true(isinstance(children_el, LinkedDataElement))
     # Nonexisting attribute raises error.
     self.assert_raises(AttributeError, getattr, prx, 'foo')
     self.assert_raises(AttributeError, setattr, prx, 'foo', 'murks')
     # Set terminal attribute.
     prx.id = 1
     self.assert_equal(prx.id, 1)
     # Set nested attribute.
     setattr(prx, parent_repr_name, None)
     self.assert_is_none(getattr(prx, parent_repr_name))
     self.assert_raises(ValueError, setattr, prx, parent_repr_name, 1)
Пример #4
0
 def _test(mb, cnt_type, parent_repr_name, children_repr_name):
     mp_reg = get_mapping_registry(cnt_type)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     de = mp.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     assert prx.get_data_element() is de
     assert prx.id == 0
     assert prx.text == 'TEXT'
     assert prx.number == 1
     if cnt_type is XmlMime:
         # The parent attribute is a link.
         assert isinstance(getattr(prx, parent_repr_name),
                           LinkedDataElement)
         with pytest.raises(AttributeError):
             dummy = getattr(prx, children_repr_name)
     else:
         assert isinstance(getattr(prx, parent_repr_name),
                           DataElementAttributeProxy)
         children_el = getattr(prx, children_repr_name)
         assert isinstance(children_el, LinkedDataElement)
     # Nonexisting attribute raises error.
     with pytest.raises(AttributeError):
         dummy = getattr(prx, 'foo')
     with pytest.raises(AttributeError):
         setattr(prx, 'foo', 'murks')
     # Set terminal attribute.
     prx.id = 1
     assert prx.id == 1
     # Set nested attribute.
     setattr(prx, parent_repr_name, None)
     assert getattr(prx, parent_repr_name) is None
     with pytest.raises(ValueError):
         setattr(prx, parent_repr_name, 1)
Пример #5
0
 def test_map_to_data_element_with_collection(self, resource_repo):
     entity = create_entity()
     coll = resource_repo.get_collection(IMyEntity)
     mb = coll.create_member(entity)
     assert len(entity.children) == 1
     assert len(mb.children) == 1
     mb_child = next(iter(mb.children))
     assert len(mb_child.children) == 1
     mp_reg = get_mapping_registry(CsvMime)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     mp1 = mp.clone(
         attribute_options={
             ('children', ): {
                 IGNORE_OPTION: False,
                 WRITE_AS_LINK_OPTION: False
             },
             ('children', 'children'): {
                 IGNORE_OPTION: False,
                 WRITE_AS_LINK_OPTION: False
             }
         })
     de = mp1.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     assert len(prx.children) == 1
     assert len(prx.children[0].children) == 1
Пример #6
0
 def update(self, data):
     if not IEntity.providedBy(data):  # pylint: disable=E1101
         prx = DataElementAttributeProxy(data)
         try:
             new_owner = prx.owner
         except AttributeError:
             pass
         else:
             if new_owner != self.owner:
                 #                current_owner = None if self.owner == '' else self.owner
                 self.__process_change_owner(new_owner)
         try:
             new_delivery_date = prx.delivery_date
         except AttributeError:
             pass
         else:
             self.delivery_date = new_delivery_date
         try:
             jobs = prx.jobs
         except AttributeError:
             pass
         else:
             self.__process_iso_jobs(jobs)
         try:
             isos = prx.isos
         except AttributeError:
             pass
         else:
             self.__process_isos(isos)
Пример #7
0
 def test_map_to_data_element_with_member(self):
     entity = create_entity()
     mb = MyEntityMember.create_from_entity(entity)
     mp_reg = get_mapping_registry(CsvMime)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     mp1 = mp.clone(attribute_options={
         ('parent', ): {
             WRITE_AS_LINK_OPTION: False
         },
     })
     de = mp1.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     self.assert_is_not_none(prx.parent)
     #
     entity.parent = None
     de1 = mp1.map_to_data_element(mb)
     prx1 = DataElementAttributeProxy(de1)
     self.assert_is_none(prx1.parent)
Пример #8
0
 def update(self, data):
     if IDataElement.providedBy(data):  # pylint: disable=E1101
         # FIXME: This really should be a PATCH operation.
         prx = DataElementAttributeProxy(data)
         self_entity = self.get_entity()
         changed_num_reps = prx.number_replicates != self.number_replicates
         emt_id = prx.experiment_metadata_type.get('id')
         changed_em_type = emt_id != self.experiment_metadata_type.id
         if changed_em_type or changed_num_reps:
             if changed_num_reps:
                 self_entity.number_replicates = prx.number_replicates
             if changed_em_type:
                 self_entity.experiment_metadata_type = \
                             get_experiment_metadata_type(emt_id)
             if not self_entity.experiment_design is None:
                 # invalidate data to force a fresh upload of the XLS file
                 self_entity.experiment_design.experiment_design_racks = []
                 self_entity.experiment_design.worklist_series = None
             if not self_entity.lab_iso_request is None:
                 shape = self_entity.lab_iso_request.rack_layout.shape
                 new_layout = RackLayout(shape=shape)
                 self_entity.lab_iso_request.rack_layout = new_layout
                 self_entity.lab_iso_request.owner = ''
         changed_sp = self_entity.subproject.id != prx.subproject.get('id')
         if changed_sp:
             new_sp = \
                 url_to_resource(prx.subproject.get('href')).get_entity()
             self_entity.subproject = new_sp
         self_entity.label = prx.label
         # Perform appropriate Trac updates.
         if not self_entity.lab_iso_request is None:
             if self.iso_request.owner == STOCKMANAGEMENT_USER:
                 ticket_activator = IsoRequestTicketActivator(
                     experiment_metadata=self_entity)
                 self.__run_trac_tool(ticket_activator,
                                      'Could not update the ticket: %s.')
             else:
                 if changed_em_type or changed_num_reps:
                     trac_updater = IsoRequestTicketDescriptionRemover(
                         experiment_metadata=self_entity,
                         changed_num_replicates=changed_num_reps,
                         changed_em_type=changed_em_type)
                 else:
                     url = 'http://thelma/public//LOUICe.html#' \
                           + self.path
                     iso_url = 'http://thelma/public//LOUICe.html#' \
                               + self.iso_request.path
                     trac_updater = IsoRequestTicketDescriptionUpdater(
                         experiment_metadata=self_entity,
                         experiment_metadata_link=url,
                         iso_request_link=iso_url)
                 self.__run_trac_tool(trac_updater,
                                      'Could not update the ticket: %s.')
     else:
         Member.update(self, data)
Пример #9
0
 def test_map_to_data_element_with_member(self, resource_repo):
     entity = create_entity()
     coll = resource_repo.get_collection(IMyEntity)
     mb = coll.create_member(entity)
     mp_reg = get_mapping_registry(CsvMime)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     mp1 = mp.clone(attribute_options={
         ('parent', ): {
             WRITE_AS_LINK_OPTION: False
         },
     })
     de = mp1.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     assert not prx.parent is None
     #
     entity.parent = None
     de1 = mp1.map_to_data_element(mb)
     prx1 = DataElementAttributeProxy(de1)
     with pytest.raises(AttributeError):
         dummy = getattr(prx1, 'parent')
Пример #10
0
 def update(self, data):
     if IDataElement.providedBy(data):  # pylint: disable=E1101
         prx = DataElementAttributeProxy(data)
         loc = self.get_entity()
         try:
             rack = prx.rack
         except AttributeError:
             loc.checkout_rack()
         else:
             loc.checkin_rack(rack.get_entity())
     else:
         Member.update(self, data)
Пример #11
0
 def test_linked_collection_data_element(self, collection):
     agg = collection.get_aggregate()
     with pytest.raises(ValueError):
         CsvLinkedDataElement.create_from_resource(agg)
     data_el = CsvLinkedDataElement.create_from_resource(collection)
     assert data_el.get_title() == 'Collection of MyEntityMember'
     assert data_el.get_url().find('/my-entities/') != -1
     assert data_el.get_kind() == RESOURCE_KINDS.COLLECTION
     assert data_el.get_relation() == 'http://test.org/myentity-collection'
     # Can not use data element attribute proxy with a link.
     with pytest.raises(ValueError):
         DataElementAttributeProxy(data_el)
     assert str(data_el).startswith(data_el.__class__.__name__)
Пример #12
0
 def update(self, data):
     if IDataElement.providedBy(data):  # pylint: disable=E1101
         prx = DataElementAttributeProxy(data)
         try:
             exp_nodes = prx.experiments
         except AttributeError:
             pass
         else:
             for exp_node in exp_nodes:
                 exp_id = exp_node.id
                 try:
                     exp_rack_nodes = exp_node.experiment_racks
                 except AttributeError:
                     pass
                 else:
                     if len(exp_rack_nodes) > 0:
                         self.__update_experiment_racks(
                             exp_rack_nodes, exp_id)
     else:
         JobMember.update(self, data)
Пример #13
0
 def test_map_to_data_element_with_collection(self):
     entity = create_entity()
     mb = MyEntityMember.create_from_entity(entity)
     mp_reg = get_mapping_registry(CsvMime)
     mp = mp_reg.find_or_create_mapping(MyEntityMember)
     mp1 = mp.clone(
         attribute_options={
             ('children', ): {
                 IGNORE_ON_WRITE_OPTION: False,
                 WRITE_AS_LINK_OPTION: False
             },
             ('children', 'children'): {
                 IGNORE_ON_WRITE_OPTION: False,
                 WRITE_AS_LINK_OPTION: False
             }
         })
     de = mp1.map_to_data_element(mb)
     prx = DataElementAttributeProxy(de)
     self.assert_equal(len(prx.children), 1)
     self.assert_equal(len(prx.children[0].children), 1)