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

blues / note-python / 17302629308

28 Aug 2025 04:57PM UTC coverage: 94.118% (+0.7%) from 93.407%
17302629308

push

github

web-flow
Merge pull request #115 from blues/alex-add-schema-generation

feat: build fluent API from Notecard JSON schema

733 of 733 new or added lines in 15 files covered. (100.0%)

3 existing lines in 2 files now uncovered.

2880 of 3060 relevant lines covered (94.12%)

4.7 hits per line

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

92.59
/test/fluent_api/conftest.py
1
import sys
5✔
2
import os
5✔
3
import pytest
5✔
4
from unittest.mock import MagicMock
5✔
5

6
sys.path.insert(0,
5✔
7
                os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
8

9
import notecard  # noqa: E402
5✔
10

11

12
@pytest.fixture
5✔
13
def run_fluent_api_notecard_api_mapping_test():
5✔
14
    def _run_test(fluent_api, notecard_api_name, req_params, rename_key_map=None, rename_value_map=None):
5✔
15
        card = notecard.Notecard()
5✔
16
        card.Transaction = MagicMock()
5✔
17

18
        fluent_api(card, **req_params)
5✔
19
        expected_notecard_api_req = {'req': notecard_api_name, **req_params}
5✔
20

21
        # There are certain fluent APIs that have keyword arguments that don't
22
        # map exactly onto the Notecard API. For example, note.changes takes a
23
        # 'maximum' parameter, but in the JSON request that gets sent to the
24
        # Notecard, it's sent as 'max'. The rename_key_map allows a test to specify
25
        # how a fluent API's keyword args map to Notecard API args, in cases
26
        # where they differ.
27
        if rename_key_map is not None:
5✔
28
            for old_key, new_key in rename_key_map.items():
5✔
29
                expected_notecard_api_req[new_key] = expected_notecard_api_req.pop(old_key)
5✔
30

31
        # Additionally, some Notecard API args have values that are not directly
32
        # mapped, but are instead derived from the value of another arg. For
33
        # example, note.template takes a 'compact' parameter, but the value of
34
        # that parameter is actually derived from the value of the 'format'
35
        # parameter. The rename_value_map allows a test to specify how a fluent
36
        # API's keyword args map to Notecard API args, in cases where the value
37
        # of one arg is derived from the value of another arg.
38
        if rename_value_map is not None:
5✔
UNCOV
39
            for key, new_value in rename_value_map.items():
×
UNCOV
40
                expected_notecard_api_req[key] = new_value
×
41

42
        card.Transaction.assert_called_once_with(expected_notecard_api_req)
5✔
43

44
    return _run_test
5✔
45

46

47
@pytest.fixture
5✔
48
def run_fluent_api_invalid_notecard_test():
5✔
49
    def _run_test(fluent_api, req_params, rename_key_map=None, rename_value_map=None):
5✔
50
        with pytest.raises(Exception, match='Notecard object required'):
5✔
51
            # Call with None instead of a valid Notecard object.
52
            fluent_api(None, **req_params)
5✔
53

54
    return _run_test
5✔
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

© 2025 Coveralls, Inc