Exemplo n.º 1
0
 def test_project_regex(self, utils):
     cmd = show_models.ReindexCommand('reindex')
     cmd.run([test_config, '--project-regex', '^test'])
     utils.chunked_find.assert_called_once_with(
         M.Project, {'shortname': {
             '$regex': '^test'
         }})
Exemplo n.º 2
0
    def test_post_add_artifacts_too_large(self, add_artifacts):
        def on_post(chunk, **kw):
            if len(chunk) > 1:
                e = pymongo.errors.InvalidDocument(
                    "BSON document too large (16906035 bytes) - the connected server supports BSON document sizes up to 16777216 bytes."
                )
                # ming injects a 2nd arg with the document, so we do too
                e.args = e.args + (
                    "doc:  {'task_name': 'allura.tasks.index_tasks.add_artifacts', ........",
                )
                raise e

        add_artifacts.post.side_effect = on_post
        cmd = show_models.ReindexCommand('reindex')
        cmd.options, args = cmd.parser.parse_args([])
        cmd._post_add_artifacts(range(5))
        kw = {'update_solr': cmd.options.solr, 'update_refs': cmd.options.refs}
        expected = [
            call([0, 1, 2, 3, 4], **kw),
            call([0, 1], **kw),
            call([0], **kw),
            call([1], **kw),
            call([2, 3, 4], **kw),
            call([2], **kw),
            call([3, 4], **kw),
            call([3], **kw),
            call([4], **kw)
        ]
        assert_equal(expected, add_artifacts.post.call_args_list)
Exemplo n.º 3
0
 def test_skip_solr_delete(self, g):
     cmd = show_models.ReindexCommand('reindex')
     cmd.run([test_config, '-p', 'test', '--solr'])
     assert g.solr.delete.called, 'solr.delete() must be called'
     g.solr.delete.reset_mock()
     cmd.run([test_config, '-p', 'test', '--solr', '--skip-solr-delete'])
     assert not g.solr.delete.called, 'solr.delete() must not be called'
Exemplo n.º 4
0
 def test_solr_hosts_1(self, Solr):
     cmd = show_models.ReindexCommand('reindex')
     cmd.options, args = cmd.parser.parse_args([
         '-p', 'test', '--solr', '--solr-hosts=http://blah.com/solr/forge'
     ])
     cmd._chunked_add_artifacts(list(range(10)))
     assert_equal(Solr.call_args[0][0], 'http://blah.com/solr/forge')
Exemplo n.º 5
0
 def test_post_add_artifacts_other_error(self, add_artifacts):
     def on_post(chunk, **kw):
         raise pymongo.errors.InvalidDocument("Cannot encode object...")
     add_artifacts.post.side_effect = on_post
     cmd = show_models.ReindexCommand('reindex')
     cmd.options = Mock(ming_config=None)
     with td.raises(pymongo.errors.InvalidDocument):
         cmd._post_add_artifacts(list(range(5)))
Exemplo n.º 6
0
 def test_chunked_add_artifacts(self, add_artifacts):
     cmd = show_models.ReindexCommand('reindex')
     cmd.options = Mock(tasks=True, max_chunk=10*1000, ming_config=None)
     ref_ids = list(range(10 * 1000 * 2 + 20))
     cmd._chunked_add_artifacts(ref_ids)
     assert_equal(len(add_artifacts.post.call_args_list), 3)
     assert_equal(len(add_artifacts.post.call_args_list[0][0][0]), 10 * 1000)
     assert_equal(len(add_artifacts.post.call_args_list[1][0][0]), 10 * 1000)
     assert_equal(len(add_artifacts.post.call_args_list[2][0][0]), 20)
Exemplo n.º 7
0
 def test_solr_hosts_list(self, Solr):
     cmd = show_models.ReindexCommand('reindex')
     cmd.options, args = cmd.parser.parse_args([
         '-p', 'test', '--solr', '--solr-hosts=http://blah.com/solr/forge,https://other.net/solr/forge'])
     cmd._chunked_add_artifacts(list(range(10)))
     # check constructors of first and second Solr() instantiations
     assert_equal(set([Solr.call_args_list[0][0][0], Solr.call_args_list[1][0][0]]),
                  set(['http://blah.com/solr/forge', 'https://other.net/solr/forge'])
                  )
Exemplo n.º 8
0
 def test_post_add_artifacts_too_large(self, add_artifacts):
     def on_post(chunk, **kw):
         if len(chunk) > 1:
             raise pymongo.errors.InvalidDocument(
                     "BSON document too large (16906035 bytes) - the connected server supports BSON document sizes up to 16777216 bytes.")
     add_artifacts.post.side_effect = on_post
     cmd = show_models.ReindexCommand('reindex')
     cmd.options, args = cmd.parser.parse_args([])
     cmd._post_add_artifacts(range(5))
     kw = {'update_solr': cmd.options.solr, 'update_refs': cmd.options.refs}
     expected = [
         call([0, 1, 2, 3, 4], **kw),
         call([0, 1], **kw),
         call([0], **kw),
         call([1], **kw),
         call([2, 3, 4], **kw),
         call([2], **kw),
         call([3, 4], **kw),
         call([3], **kw),
         call([4], **kw)
     ]
     assert_equal(expected, add_artifacts.post.call_args_list)
Exemplo n.º 9
0
 def test_ming_config(self):
     cmd = show_models.ReindexCommand('reindex')
     cmd.run([test_config, '-p', 'test', '--tasks', '--ming-config', 'test.ini'])