Ejemplo n.º 1
0
 def test_7(self):
     cache_utils.store_figure(self.session_id, 'figure_json',
                              'display_control_json', self.cache)
     expected = cache_utils.compress_data('figure_json')
     self.assertEqual(self.cache.hget(self.session_id, 'figure_json'),
                      expected)
     expected = cache_utils.compress_data('display_control_json')
     self.assertEqual(
         self.cache.hget(self.session_id, 'display_control_json'), expected)
Ejemplo n.º 2
0
 def test_8(self):
     self.cache.hset(self.session_id, 'dummy_fname', 'sequence_data')
     self.cache.hset(self.session_id, 'hydrophobicity',
                     'seq_hydrophobicity')
     self.cache.hset(self.session_id, 'sequence',
                     cache_utils.compress_data('dummy_fname'))
     cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_1',
                             'contact')
     cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_2',
                             'disorder')
     cache_utils.store_figure(self.session_id, 'figure_json',
                              'display_control_json', self.cache)
     cache_utils.clear_cache(self.session_id, self.cache)
     expected = {b'id': cache_utils.compress_data(self.session_id)}
     self.assertDictEqual(expected, self.cache.hgetall(self.session_id))
Ejemplo n.º 3
0
    def test_4(self):
        cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_1',
                                'dummy_key')
        self.assertTrue(self.cache.hexists(self.session_id, 'dummy_key'))
        expected = cache_utils.compress_data(['dummy_fname_1'])
        self.assertEqual(self.cache.hget(self.session_id, 'dummy_key'),
                         expected)

        cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_2',
                                'dummy_key')
        expected = cache_utils.compress_data(
            ['dummy_fname_1', 'dummy_fname_2'])
        self.assertEqual(self.cache.hget(self.session_id, 'dummy_key'),
                         expected)
        self.cache.hdel(self.session_id, 'dummy_key')
Ejemplo n.º 4
0
    def test_3(self):
        expected_output = [
            components.SuccessLogoutAlert(),
            components.UserPortalCardBody(None)
        ]
        expected_output = [
            json.loads(json.dumps(x, cls=plotly.utils.PlotlyJSONEncoder))
            for x in expected_output
        ]
        expected_cache = {b'id': cache_utils.compress_data(self.session_id)}
        cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_1',
                                'contact')
        self.cache.hset(self.session_id, 'user', 'username')
        self.cache.hset(self.session_id, 'session_pkid', '123')

        test_log = logging.getLogger('test_3_log')
        output = app_utils.user_logout(self.session_id, self.cache, test_log)
        self.assertEqual(output[0], no_update)
        output = [
            json.loads(json.dumps(x, cls=plotly.utils.PlotlyJSONEncoder))
            for x in output[1:]
        ]
        self.assertListEqual(output, expected_output)
        self.assertDictEqual(expected_cache,
                             self.cache.hgetall(self.session_id))
Ejemplo n.º 5
0
    def test_5(self):
        self.assertIsNone(
            cache_utils.remove_fname(self.cache, self.session_id,
                                     'dummy_fname', 'dummy_key'))
        cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_1',
                                'dummy_key')
        cache_utils.store_fname(self.cache, self.session_id, 'dummy_fname_2',
                                'dummy_key')

        cache_utils.remove_fname(self.cache, self.session_id, 'dummy_fname_1',
                                 'dummy_key')
        expected = cache_utils.compress_data(['dummy_fname_2'])
        self.assertEqual(self.cache.hget(self.session_id, 'dummy_key'),
                         expected)

        cache_utils.remove_fname(self.cache, self.session_id, 'dummy_fname_2',
                                 'dummy_key')
        expected = cache_utils.compress_data([])
        self.assertEqual(self.cache.hget(self.session_id, 'dummy_key'),
                         expected)
        self.cache.hdel(self.session_id, 'dummy_key')
Ejemplo n.º 6
0
    def test_9(self):
        cachekey_1 = cache_utils.CacheKeys.CMAP_DENSITY.value.format(
            'fname_1', '2').encode()
        density_1 = [1, 2, 3, 3, 4, 5]
        cachekey_2 = cache_utils.CacheKeys.CMAP_DENSITY.value.format(
            'fname_2', '2').encode()
        density_2 = [5, 6, 7, 8, 9, 0]

        cache_utils.store_data(self.session_id, cachekey_1, density_1,
                               cache_utils.CacheKeys.CONTACT_DENSITY.value,
                               self.cache)
        cache_utils.store_data(self.session_id, cachekey_2, density_2,
                               cache_utils.CacheKeys.CONTACT_DENSITY.value,
                               self.cache)
        output = cache_utils.retrieve_data(self.session_id, cachekey_2,
                                           self.cache)
        self.assertListEqual(output, density_2)
        expected_cache = {b'id': cache_utils.compress_data(self.session_id)}
        cache_utils.remove_all(self.session_id,
                               cache_utils.CacheKeys.CONTACT_DENSITY.value,
                               self.cache)
        self.assertDictEqual(expected_cache,
                             self.cache.hgetall(self.session_id))
Ejemplo n.º 7
0
 def test_2(self):
     dummy_data = ['a' for x in range(0, 100)]
     compressed_data = cache_utils.compress_data(dummy_data)
     decompressed_data = cache_utils.decompress_data(compressed_data)
     self.assertListEqual(dummy_data, decompressed_data)
Ejemplo n.º 8
0
def compress_data(*args, **kwargs):
    from utils.cache_utils import compress_data

    return compress_data(*args, **kwargs)