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

HEPData / hepdata / 12163548050

04 Dec 2024 03:58PM UTC coverage: 83.629% (+0.2%) from 83.45%
12163548050

push

github

ItIsJordan
Fix bug in search_test.py

Fixes a bug where testing for MadAnalysis was checking against the database entry and not the document dictionary (as it should have been)

4572 of 5467 relevant lines covered (83.63%)

0.84 hits per line

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

86.36
/hepdata/modules/records/subscribers/api.py
1
#
2
# This file is part of HEPData.
3
# Copyright (C) 2016 CERN.
4
#
5
# HEPData is free software; you can redistribute it
6
# and/or modify it under the terms of the GNU General Public License as
7
# published by the Free Software Foundation; either version 2 of the
8
# License, or (at your option) any later version.
9
#
10
# HEPData is distributed in the hope that it will be
11
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with HEPData; if not, write to the
17
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18
# MA 02111-1307, USA.
19
#
20
# In applying this license, CERN does not
21
# waive the privileges and immunities granted to it by virtue of its status
22
# as an Intergovernmental Organization or submit itself to any jurisdiction.
23

24
"""HEPData Subscribers API."""
25
from functools import partial
1✔
26
from operator import is_not
1✔
27

28
from flask_login import current_user
1✔
29

30
from hepdata.modules.records.utils.common import get_record_contents
1✔
31
from .models import Subscribers
1✔
32

33

34
def is_current_user_subscribed_to_record(recid, user=None):
1✔
35
    if not user:
1✔
36
        user = current_user
1✔
37
        if not current_user.is_authenticated:
1✔
38
            return False
1✔
39

40
    return Subscribers.query.filter(Subscribers.publication_recid == recid,
1✔
41
                                    Subscribers.subscribers.contains(user)).count() > 0
42

43

44
def get_users_subscribed_to_record(recid):
1✔
45
    subscribers = Subscribers.query.filter_by(publication_recid=recid).first()
1✔
46

47
    if subscribers:
1✔
48
        return [{'email': x.email, 'id': x.id} for x in subscribers.subscribers]
×
49
    else:
50
        return []
1✔
51

52

53
def get_records_subscribed_by_user(user):
1✔
54
    subscriptions = Subscribers.query.filter(Subscribers.subscribers.contains(user)).all()
1✔
55
    if subscriptions:
1✔
56
        records = [get_record_contents(x.publication_recid) for x in subscriptions]
×
57
        return list(filter(partial(is_not, None), records))
×
58

59
    else:
60
        return []
1✔
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