def test_single_pool(self): product = 'product1' pools = [create_pool(product, product, quantity=10, consumed=5)] results = merge_pools(pools) self.assertEquals(1, len(results.values())) result = results.values()[0] self.assertEquals(product, result.product_id)
def test_single_pool(self): product = "product1" pools = [create_pool(product, product, quantity=10, consumed=5)] results = merge_pools(pools) self.assertEquals(1, len(results.values())) result = results.values()[0] self.assertEquals(product, result.product_id)
def test_sorter_adds_group_for_non_stackable_entitlement(self): pool = self._create_pool("test-prod-1", "Test Prod 1") merged = merge_pools([pool]) pools = merged.values() sorter = MergedPoolsStackingGroupSorter(pools) self.assertEquals(1, len(sorter.groups)) group = sorter.groups[0] self.assertEquals("", group.name) self.assertEquals(1, len(group.entitlements)) self.assertEquals(pools[0], group.entitlements[0])
def test_sorter_adds_multiple_entitlements_to_group_when_same_stacking_id(self): expected_stacking_id = 1234 pool1 = self._create_pool("test-prod-1", "Test Prod 1", expected_stacking_id) pool2 = self._create_pool("test-prod-2", "Test Prod 2", expected_stacking_id) merged = merge_pools([pool1, pool2]) pools = merged.values() sorter = MergedPoolsStackingGroupSorter(pools) self.assertEquals(1, len(sorter.groups)) group = sorter.groups[0] self.assertEquals("Test Prod 2", group.name) self.assertEquals(2, len(group.entitlements)) self.assertEquals(pools[0], group.entitlements[0]) self.assertEquals(pools[1], group.entitlements[1])
def test_sorter_adds_multiple_groups_for_non_stacking_entitlements(self): pool1 = self._create_pool("test-prod-1", "Test Prod 1") pool2 = self._create_pool("test-prod-2", "Test Prod 2") merged = merge_pools([pool1, pool2]) pools = merged.values() sorter = MergedPoolsStackingGroupSorter(pools) self.assertEquals(2, len(sorter.groups)) group1 = sorter.groups[0] group2 = sorter.groups[1] self.assertEquals("", group1.name) self.assertEquals(1, len(group1.entitlements)) self.assertEquals(pools[0], group1.entitlements[0]) self.assertEquals("", group2.name) self.assertEquals(1, len(group2.entitlements)) self.assertEquals(pools[1], group2.entitlements[0])
def test_stacking_and_non_stacking_groups_created(self): pool1 = self._create_pool("test-prod-1", "Test Prod 1") expected_stacking_id = 1234 pool2 = self._create_pool("test-prod-2", "Test Prod 2", expected_stacking_id) merged = merge_pools([pool1, pool2]) pools = merged.values() sorter = MergedPoolsStackingGroupSorter(pools) self.assertEquals(2, len(sorter.groups)) group1 = sorter.groups[0] group2 = sorter.groups[1] self.assertEquals("Test Prod 2", group1.name) self.assertEquals(1, len(group1.entitlements)) self.assertEquals(pools[0], group1.entitlements[0]) self.assertEquals("", group2.name) self.assertEquals(1, len(group2.entitlements)) self.assertEquals(pools[1], group2.entitlements[0])
def test_sorter_adds_multiple_entitlements_to_group_when_same_stacking_id( self): expected_stacking_id = 1234 pool1 = self._create_pool("test-prod-1", "Test Prod 1", expected_stacking_id) pool2 = self._create_pool("test-prod-2", "Test Prod 2", expected_stacking_id) merged = merge_pools([pool1, pool2]) pools = merged.values() sorter = MergedPoolsStackingGroupSorter(pools) self.assertEquals(1, len(sorter.groups)) group = sorter.groups[0] self.assertEquals("Test Prod 2", group.name) self.assertEquals(2, len(group.entitlements)) self.assertEquals(pools[0], group.entitlements[0]) self.assertEquals(pools[1], group.entitlements[1])
def test_multiple_pools(self): product1 = 'product1' product2 = 'product2' pools = [ create_pool(product1, product1, quantity=10, consumed=5), create_pool(product1, product1, quantity=55, consumed=20), create_pool(product2, product2, quantity=10, consumed=5), ] results = merge_pools(pools) self.assertEquals(2, len(results.values())) self.assertTrue(product1 in results) self.assertTrue(product2 in results) # Check product1: merged_pools = results[product1] self.assertEquals(product1, merged_pools.product_id) self.assertEquals(65, merged_pools.quantity) self.assertEquals(25, merged_pools.consumed) # Check product2: merged_pools = results[product2] self.assertEquals(product2, merged_pools.product_id) self.assertEquals(10, merged_pools.quantity) self.assertEquals(5, merged_pools.consumed)