def test_get_project__returns_project(self): # given entity_map = EntityMap() project_entity = Entity('project', 'project_0', {}) entity_map.add_entity(project_entity) # when output = entity_map.get_project() # then self.assertEqual(output, project_entity)
def test_submit_linked_entity(self, submission_constructor): # given: 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], is_reference=False, is_linking_reference=False) project = Entity('project', 'id', {}, is_reference=False, is_linking_reference=False) entity_map.add_entity(linked_product) entity_map.add_entity(project) # when: submitter = IngestSubmitter(self.ingest_api) submitter.add_entity = MagicMock() submitter.link_submission_to_project = MagicMock() submitter.PROGRESS_CTR = 1 submitter.add_entities(entity_map, submission_url='url') # then: submission_constructor.assert_called_with(self.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)
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())