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

cnobile2012 / CheckMeIn / 17899760591

21 Sep 2025 10:26PM UTC coverage: 98.009% (+0.09%) from 97.917%
17899760591

push

github

cnobile2012
Finished tests for the checkMeIn.CheckMeIn class, and cleaned up some other code also.

48 of 53 new or added lines in 5 files covered. (90.57%)

2461 of 2511 relevant lines covered (98.01%)

0.98 hits per line

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

95.77
/src/web_base.py
1
# -*- coding: utf-8 -*-
2
#
3
# src/web_base.py
4
#
5

6
import re
1✔
7
import datetime
1✔
8
import cherrypy
1✔
9

10
from mako import exceptions
1✔
11

12
from . import AppConfig
1✔
13
from .accounts import Role
1✔
14

15

16
class Cookie:
1✔
17
    """
18
    Set and get cookies.
19

20
    1. f"/teams?team_id={team_id}"
21
    2. f"/certifications/team?team_id={team_id}"
22
    """
23

24
    def __init__(self, name):
1✔
25
        self._name = name
1✔
26

27
    def get(self, default=''):
1✔
28
        result = cherrypy.session.get(self._name)
1✔
29

30
        if not result:
1✔
31
            self.set(default)
1✔
32
            result = default
1✔
33

34
        return result
1✔
35

36
    def set(self, value):
1✔
37
        cherrypy.session[self._name] = value
1✔
38
        return value
1✔
39

40
    def delete(self):
1✔
41
        cherrypy.session.pop(self._name, None)
1✔
42

43

44
class WebBase:
1✔
45

46
    def __init__(self, lookup, engine, *args, **kwargs):
1✔
47
        super().__init__(*args, **kwargs)
1✔
48
        self.lookup = lookup
1✔
49
        self.engine = engine
1✔
50
        self._log = AppConfig().log
1✔
51

52
    def _get_barcode_no_login(self):
1✔
53
        return Cookie('barcode').get(None)
1✔
54

55
    def template(self, template, **kwargs):
1✔
56
        barcode = self._get_barcode_no_login()
1✔
57
        logo_link = f'/links/?barcode={barcode}' if barcode else '/links/'
1✔
58

59
        try:
1✔
60
            return self.lookup.get_template(template).render(
1✔
61
                logo_link=logo_link, **kwargs)
NEW
62
        except Exception:
×
63
            # Print the nice traceback to console (or logs)
NEW
64
            self._log.error(exceptions.text_error_template().render())
×
65
            # Re-raise so CherryPy still returns an error
NEW
66
            raise
×
67

68
    def has_permissions_no_login(self, role_check):
1✔
69
        role = Role(Cookie('role').get(0))
1✔
70
        return role.cookie_value & role_check
1✔
71

72
    def check_permissions(self, role_check, source):
1✔
73
        if not self.has_permissions_no_login(role_check):
1✔
74
            Cookie('source').set(source)
1✔
75
            raise cherrypy.HTTPRedirect("/profile/login")
1✔
76

77
    def _get_cookie(self, cookie, source):
1✔
78
        value = Cookie(cookie).get('')
1✔
79

80
        if not value:
1✔
81
            Cookie('source').set(source)
1✔
82
            raise cherrypy.HTTPRedirect("/profile/login")
1✔
83

84
        return value
1✔
85

86
    def get_barcode(self, source):
1✔
87
        return self._get_cookie('barcode', source)
1✔
88

89
    def get_user(self, source):
1✔
90
        return self._get_cookie('username', source)
1✔
91

92
    def get_role(self, source):
1✔
93
        return Role(self._get_cookie('role', source))
1✔
94

95
    @staticmethod
1✔
96
    def date_from_string(input_str, date=False):
1✔
97
        """
98
        Return the date portion of the ISO string.
99

100
        :param str input_str: An ISO date and time string.
101
        :returns: The date portion of the ISO input string as a
102
                  datetime object.
103
        :rtype: datetime.datetime
104
        """
105
        dt = re.split(r'T| ', input_str)
1✔
106
        date_str = re.sub(r'\.|/', '-', dt[0])
1✔
107
        ds = date_str.split('-')
1✔
108
        date_str = f"{ds[0]:>04s}-{ds[1]:>02s}-{ds[2]:>02s}"
1✔
109

110
        if date:
1✔
111
            ret = datetime.date.fromisoformat(date_str)
1✔
112
        else:
113
            ret = datetime.datetime.fromisoformat(date_str)
1✔
114

115
        return ret
1✔
116

117
    @staticmethod
1✔
118
    def time_from_string(input_str):
1✔
119
        """
120
        Return the time portion of the ISO string.
121

122
        :param str input_str: An ISO date and time string.
123
        :returns: The time portion of the ISO input string as a
124
                  datetime object.
125
        :rtype: datetime.time
126
        """
127
        dt = re.split(r'T| ', input_str)
1✔
128
        ts = dt[0].split(':') if len(dt) == 1 else dt[1].split(':')
1✔
129
        time_str = f"{ts[0]:>02s}:{ts[1]:>02s}:{ts[2]:>02s}"
1✔
130
        return datetime.time.fromisoformat(time_str)
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