def test_submit_linked_entity(self, submission_constructor): # given: ingest_api = MagicMock('ingest_api') ingest_api.getSubmissionEnvelope = MagicMock() ingest_api.patch = MagicMock() ingest_api.get_link_from_resource = MagicMock() submission = self._mock_submission(submission_constructor) # and: user = Entity('user', 'user_1', {}) entity_map = EntityMap(user) # and: link_to_user = { 'entity': 'user', 'id': 'user_1', 'relationship': 'wish_list' } linked_product = Entity('product', 'product_1', {}, direct_links=[link_to_user]) project = Entity('project', 'id', {}) entity_map.add_entity(linked_product) entity_map.add_entity(project) # when: submitter = IngestSubmitter(ingest_api) submitter.PROGRESS_CTR = 1 submitter.submit(entity_map, submission_url='url') # then: submission_constructor.assert_called_with(ingest_api, 'url') submission.define_manifest.assert_called_with(entity_map) submission.add_entity.assert_has_calls([call(user), call(linked_product)], any_order=True) submission.link_entity.assert_called_with(linked_product, user, relationship='wish_list') ingest_api.patch.assert_called_once()
def test_count_links(self): entity_map = EntityMap() # no element self.assertEqual(entity_map.count_links(), 0) # has 1 element without links entity_map.add_entity(Entity('product', 'product_0', {})) self.assertEqual(entity_map.count_links(), 0) # has 1 element with links entity_map.add_entity(Entity('product', 'product_1', {}, direct_links=[{}, {}, {}])) self.assertEqual(entity_map.count_links(), 3) # has many element with links entity_map.add_entity(Entity('product', 'product_2', {}, direct_links=[{}, {}, {}, {}])) self.assertEqual(entity_map.count_links(), 7)
def test_count_total(self): # given: zero_map = EntityMap() # and: one_map = EntityMap() one_map.add_entity(Entity('product', 'product_1', {})) # and: three_map = EntityMap() three_map.add_entity(Entity('profile', 'profile_1', {})) for product_id in range(0, 2): three_map.add_entity(Entity('product', f'product_{product_id}', {})) # expect: self.assertEqual(0, zero_map.count_total()) self.assertEqual(1, one_map.count_total()) self.assertEqual(3, three_map.count_total())