def test_update(self): area = CellAreaFactory(radio=Radio.gsm, num_cells=1) area.region = None CellAreaFactory(radio=Radio.gsm, region='DE', num_cells=1) CellAreaFactory(radio=Radio.gsm, region='DE', num_cells=2) CellAreaFactory(radio=Radio.gsm, region='CA', num_cells=2) CellAreaFactory(radio=Radio.wcdma, region='DE', num_cells=3) CellAreaFactory(radio=Radio.lte, region='CA', num_cells=4) WifiShardFactory.create_batch(5, region='DE') WifiShardFactory.create_batch(6, region='US') wifi = WifiShardFactory() wifi.region = None self.session.add(RegionStat(region='US', wifi=2)) self.session.add(RegionStat(region='TW', wifi=1)) self.session.flush() update_statregion.delay().get() stats = self.session.query(RegionStat).all() self.assertEqual(len(stats), 3) for stat in stats: values = (stat.gsm, stat.wcdma, stat.lte, stat.wifi) if stat.region == 'DE': self.assertEqual(values, (3, 3, 0, 5)) elif stat.region == 'CA': self.assertEqual(values, (2, 0, 4, 0)) elif stat.region == 'US': self.assertEqual(values, (0, 0, 0, 6))
def test_update(self, celery, session): area = CellAreaFactory(radio=Radio.gsm, num_cells=1) area.region = None BlueShardFactory.create_batch(2, region='CA') BlueShardFactory.create_batch(3, region='GB') CellAreaFactory(radio=Radio.gsm, region='DE', num_cells=1) CellAreaFactory(radio=Radio.gsm, region='DE', num_cells=2) CellAreaFactory(radio=Radio.gsm, region='CA', num_cells=2) CellAreaFactory(radio=Radio.wcdma, region='DE', num_cells=3) CellAreaFactory(radio=Radio.lte, region='CA', num_cells=4) WifiShardFactory.create_batch(5, region='DE') WifiShardFactory.create_batch(6, region='US') wifi = WifiShardFactory() wifi.region = None session.add(RegionStat(region='US', blue=1, wifi=2)) session.add(RegionStat(region='TW', wifi=1)) session.flush() update_statregion.delay().get() stats = session.query(RegionStat).all() assert len(stats) == 4 for stat in stats: values = (stat.gsm, stat.wcdma, stat.lte, stat.blue, stat.wifi) if stat.region == 'DE': assert values == (3, 3, 0, 0, 5) elif stat.region == 'CA': assert values == (2, 0, 4, 2, 0) elif stat.region == 'GB': assert values == (0, 0, 0, 3, 0) elif stat.region == 'US': assert values == (0, 0, 0, 0, 6)