• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NaturalHistoryMuseum / data-importer / #12

07 Aug 2025 10:46AM UTC coverage: 79.133% (-0.1%) from 79.237%
#12

push

coveralls-python

web-flow
Merge dd79f4361 into edec251d1

196 of 294 new or added lines in 26 files covered. (66.67%)

5 existing lines in 2 files now uncovered.

1259 of 1591 relevant lines covered (79.13%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/dataimporter/cli/view.py
1
import click
×
2

3
from dataimporter.cli.utils import console, with_config
×
4
from dataimporter.importer import use_importer
×
5
from dataimporter.lib.config import Config
×
6

7

NEW
8
@click.group('view')
×
9
def view_group():
×
10
    pass
×
11

12

NEW
13
@view_group.command('list')
×
14
@with_config()
×
15
def list_views(config: Config):
×
16
    """
17
    List the name of all the views in current use.
18
    """
19
    with use_importer(config) as importer:
×
NEW
20
        console.log(', '.join(view.name for view in importer.views))
×
21

22

NEW
23
@view_group.command('flush')
×
NEW
24
@click.argument('view', type=str)
×
25
@with_config()
×
26
def flush(view: str, config: Config):
×
27
    """
28
    Flushes the given view's queue.
29

30
    For non-published views this should always be safe to do (but maybe think about it
31
    first, just to make sure) but for published views you should make sure you know what
32
    you're doing.
33
    """
34
    with use_importer(config) as importer:
×
35
        view = importer.get_view(view)
×
36
        console.log(
×
37
            f'Flushing {view.name} view queue, currently has', view.count(), 'IDs in it'
38
        )
39
        view.flush()
×
NEW
40
        console.log(f'{view.name} flushed')
×
41

42

NEW
43
@view_group.command('ingest')
×
NEW
44
@click.argument('view', type=str)
×
UNCOV
45
@click.option(
×
46
    '--everything',
47
    is_flag=True,
48
    show_default=True,
49
    default=False,
50
    help='Add all records to MongoDB regardless of whether they have changed. This is '
51
    "primarily useful when a change has been made to a view's filters or "
52
    'representation',
53
)
54
@with_config()
×
55
def ingest(view: str, config: Config, everything: bool = False):
×
56
    """
57
    On the given view, updates MongoDB with any queued EMu changes and flushes its
58
    queue.
59
    """
60
    with use_importer(config) as importer:
×
NEW
61
        console.log(f'Adding changes from {view} view to mongo')
×
62
        importer.add_to_mongo(view, everything=everything)
×
NEW
63
        console.log(f'Added changes from {view} view to mongo')
×
64

65

NEW
66
@view_group.command('sync')
×
NEW
67
@click.argument('view', type=str)
×
UNCOV
68
@click.option(
×
69
    '--resync',
70
    is_flag=True,
71
    show_default=True,
72
    default=False,
73
    help='Resynchronise all data in Elasticsearch with MongoDB for this view, not just '
74
    'the records that have changed.',
75
)
76
@with_config()
×
77
def sync(view: str, config: Config, resync: bool = False):
×
78
    """
79
    Updates Elasticsearch with the changes in MongoDB for the given view.
80
    """
81
    with use_importer(config) as importer:
×
NEW
82
        console.log(f'Syncing changes from {view} view to elasticsearch')
×
83
        importer.sync_to_elasticsearch(view, resync=resync)
×
NEW
84
        console.log(f'Finished with {view}')
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc