@@ -0,0 +1,1712 @@
+# Copyright (C) 2017 Google Inc.%0A# Licensed under http://www.apache.org/licenses/LICENSE-2.0 %3Csee LICENSE file%3E%0A%0A%0Aimport mock%0Afrom collections import defaultdict%0A%0Afrom ddt import data, ddt%0A%0Afrom ggrc.converters import base_block%0Afrom ggrc import models%0A%0Afrom integration.ggrc import TestCase%0Afrom integration.ggrc.models import factories%0A%0A%0A@ddt%0Aclass TestBaseBlock(TestCase):%0A%0A  @staticmethod%0A  def dd_to_dict(ddict):%0A    return %7Bk: dict(v) for k, v in ddict.items()%7D%0A%0A  @data(0, 1, 2, 4)%0A  def test_create_mapping_cache(self, count):%0A    regulations = %5Bfactories.RegulationFactory() for _ in range(count)%5D%0A    markets = %5Bfactories.MarketFactory() for _ in range(count)%5D%0A    controls = %5Bfactories.ControlFactory() for _ in range(count)%5D%0A%0A    expected_cache = defaultdict(lambda: defaultdict(list))%0A    for i in range(count):%0A      for j in range(i):%0A        factories.RelationshipFactory(%0A            source=regulations%5Bj%5D if i %25 2 == 0 else markets%5Bi%5D,%0A            destination=regulations%5Bj%5D if i %25 2 == 1 else markets%5Bi%5D,%0A        )%0A        factories.RelationshipFactory(%0A            source=regulations%5Bj%5D if i %25 2 == 0 else controls%5Bi%5D,%0A            destination=regulations%5Bj%5D if i %25 2 == 1 else controls%5Bi%5D,%0A        )%0A        expected_cache%5Bregulations%5Bj%5D.id%5D%5B%22Control%22%5D.append(%0A            controls%5Bi%5D.slug%0A        )%0A        expected_cache%5Bregulations%5Bj%5D.id%5D%5B%22Market%22%5D.append(%0A            markets%5Bi%5D.slug%0A        )%0A    block = base_block.BlockConverter(mock.MagicMock())%0A    block.object_class = models.Regulation%0A    block.object_ids = %5Br.id for r in regulations%5D%0A%0A    cache = block._create_mapping_cache()%0A    self.assertEqual(%0A        self.dd_to_dict(cache),%0A        self.dd_to_dict(expected_cache),%0A    )%0A

Add export mapping cache tests