Ejemplo n.º 1
0
    def setUp(self):
        """ Initialises test by adding dummy log entries """
        from invenio_records.api import create_record
        from invenio_records.models import Record

        self.__transaction = db.session.begin_nested()
        for i in range(10):
            rec = Record(id=i + 1)
            db.session.add(rec)
            create_record({'recid': i + 1})

        from inspire.modules.citations.tasks import update_citations_log
        data = u'[[1, 2, 1, "added", "2013-04-25 04:20:30"],[2, 3, 1, "added", "2013-04-25 04:20:30"],[3, 5, 1, "added", "2013-04-25 04:20:30"],[4, 4, 2, "added", "2013-04-25 04:20:30"],[5, 5, 2, "added", "2013-04-25 04:20:30"],[6, 6, 2, "added", "2013-04-25 04:20:30"],[7, 10, 4, "added", "2013-04-25 04:20:30"],[8, 5, 1, "removed", "2013-04-25 04:20:30"],[9, 5, 4, "added", "2013-04-25 04:20:30"],[10, 6, 4, "added", "2013-04-25 04:20:30"],[11, 3, 4, "added", "2013-04-25 04:20:31"],[12, 8, 5, "added", "2013-04-25 04:20:31"],[13, 10, 4, "removed", "2013-04-25 04:20:31"],[14, 7, 6, "added", "2013-04-25 04:20:31"],[15, 9, 6, "added", "2013-04-25 04:20:31"],[16, 10, 6, "added", "2013-04-25 04:20:31"],[17, 1, 7, "added", "2013-04-25 04:20:31"],[18, 8, 7, "added", "2013-04-25 04:20:31"],[19, 10, 7, "added", "2013-04-25 04:20:31"],[20, 3, 8, "added", "2013-04-25 04:20:31"],[21, 10, 9, "added", "2013-04-25 04:20:31"],[22, 3, 9, "added", "2013-04-25 04:20:31"],[23, 3, 8, "removed", "2013-04-25 04:20:31"],[24, 1, 10, "added", "2013-04-25 04:20:31"],[25, 2, 10, "added", "2013-04-25 04:20:31"],[26, 3, 10, "added", "2013-04-25 04:20:31"]]'
        # Mocks two responses. The first one contains the dummy data and the second an empty list
        # to force update_citations_log() to terminate.
        httpretty.register_uri(
            httpretty.GET,
            cfg.get("CITATIONS_FETCH_LEGACY_URL"),
            responses=[
                httpretty.Response(body=data, status=200),
                httpretty.Response(body='[]', status=200),
            ]
        )
        Citation.query.delete()
        Citation_Log.query.delete()
        update_citations_log()
Ejemplo n.º 2
0
 def setUp(self):
     """ Initialises test by adding dummy log entries """
     from inspire.modules.citations.tasks import update_citations_log
     data = u'[[1, 2, 1, "added", "2013-04-25 04:20:30"],[2, 3, 1, "added", "2013-04-25 04:20:30"],[3, 5, 1, "added", "2013-04-25 04:20:30"],[4, 4, 2, "added", "2013-04-25 04:20:30"],[5, 5, 2, "added", "2013-04-25 04:20:30"],[6, 6, 2, "added", "2013-04-25 04:20:30"],[7, 10, 4, "added", "2013-04-25 04:20:30"],[8, 5, 1, "removed", "2013-04-25 04:20:30"],[9, 5, 4, "added", "2013-04-25 04:20:30"],[10, 6, 4, "added", "2013-04-25 04:20:30"],[11, 3, 4, "added", "2013-04-25 04:20:31"],[12, 8, 5, "added", "2013-04-25 04:20:31"],[13, 10, 4, "removed", "2013-04-25 04:20:31"],[14, 7, 6, "added", "2013-04-25 04:20:31"],[15, 9, 6, "added", "2013-04-25 04:20:31"],[16, 10, 6, "added", "2013-04-25 04:20:31"],[17, 1, 7, "added", "2013-04-25 04:20:31"],[18, 8, 7, "added", "2013-04-25 04:20:31"],[19, 10, 7, "added", "2013-04-25 04:20:31"],[20, 3, 8, "added", "2013-04-25 04:20:31"],[21, 10, 9, "added", "2013-04-25 04:20:31"],[22, 3, 9, "added", "2013-04-25 04:20:31"],[23, 3, 8, "removed", "2013-04-25 04:20:31"],[24, 1, 10, "added", "2013-04-25 04:20:31"],[25, 2, 10, "added", "2013-04-25 04:20:31"],[26, 3, 10, "added", "2013-04-25 04:20:31"]]'
     # Mocks two responses. The first one contains the dummy data and the second an empty list
     # to force update_citations_log() to terminate.
     httpretty.register_uri(
         httpretty.GET,
         cfg.get("CITATIONS_FETCH_LEGACY_URL"),
         responses=[
             httpretty.Response(body=data, status=200),
             httpretty.Response(body='[]', status=200),
         ]
     )
     if self.setup_flag:
         self.citations_dump = Citation.query.all()
         self.citations_log_dump = Citation_Log.query.all()
         self.setup_flag = False
     Citation.query.delete()
     Citation_Log.query.delete()
     update_citations_log()