Ejemplo n.º 1
0
 def test_push_analysis_object(self):
     """
     Test AnalysisObjects can be pushed to a redis list
     """
     flush_redis()
     ao = AnalysisObject(title='test', info=['foo', 'bar', 'baz'])
     push_object(ao, 'analysis_objects0')
     with RedisContext() as r:
         self.assertEqual(r.llen('analysis_objects0'), 1)
Ejemplo n.º 2
0
 def test_push_query_object(self):
     """
     Test QueryObjects can be pushed to a redis list
     """
     flush_redis()
     qo = QueryObject(title='test', url_query='https://www.example.com')
     push_object(qo, 'query_objects')
     with RedisContext() as r:
         self.assertEqual(r.llen('query_objects'), 1)
Ejemplo n.º 3
0
def get_test_data():
    # flush the database to remove old data
    if os.path.exists('analysis_objects0.pickle'):
        os.remove('analysis_objects0.pickle')
    flush_redis()
    # call the main function of get_data to populate analysis objects
    app.get_data.get_data_main()

    # pull the analysis data from the database
    aos = []
    while list_len('analysis_objects0') != 0:
        ao = pop_object(AnalysisObject, 'analysis_objects0')
        aos.append(ao)

    # write objects to pickle file
    with open('analysis_objects0.pickle', 'wb') as fl:
        pickle.dump(aos, fl)
Ejemplo n.º 4
0
 def setUp(self) -> None:
     flush_redis()
Ejemplo n.º 5
0
 def tearDown(self) -> None:
     flush_redis()
Ejemplo n.º 6
0
import pickle

from app.project_logging import logger
from app.database import push_object, flush_redis


"""
Import test data into redis
"""

file = os.path.join(os.path.dirname(__file__), 'analysis_objects0.pickle')
logger.info('Reading from %s', file)

with open(file, 'rb') as fl:
    data_in = pickle.loads(fl.read())


def main():
    start_count = len(data_in)
    end_count = 0
    while len(data_in) != 0:
        data = data_in.pop(0)
        push_object(data, 'analysis_objects0')
        end_count = end_count + 1
    logger.info('Imported %d out of %d', end_count, start_count)


if __name__ == '__main__':
    flush_redis()
    main()