File: magic_strings_integration.py

package info (click to toggle)
bundlewrap 4.24.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,216 kB
  • sloc: python: 20,299; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,439 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from os.path import join
from textwrap import dedent

from bundlewrap.utils.testing import make_repo, run

# Most of this is already tested in unit tests. Here, we only test that
# magic strings actually work inside nodes and groups.

def test_magic_string_in_node_file(tmpdir):
    make_repo(
        tmpdir,
        nodes={
            "node1": {
                "username": "!magic:dummy"
            },
        },
    )
    with open(join(tmpdir, "magic_strings.py"), 'w') as f:
        f.write(dedent("""
        @magic_string
        def magic(arg):
            return "converted magic string"
        """))

    stdout, stderr, rcode = run("bw nodes -a username", path=str(tmpdir))
    assert b"converted magic string" in stdout
    assert stderr == b""
    assert rcode == 0


def test_magic_string_in_group_file(tmpdir):
    make_repo(
        tmpdir,
        groups={
            "group1": {
                "username": "!magic:dummy"
            },
        },
        nodes={
            "node1": {
                "groups": ["group1"],
            },
        },
    )
    with open(join(tmpdir, "magic_strings.py"), 'w') as f:
        f.write(dedent("""
        @magic_string
        def magic(arg):
            return "converted magic string"
        """))

    stdout, stderr, rcode = run("bw nodes -a username", path=str(tmpdir))
    assert b"converted magic string" in stdout
    assert stderr == b""
    assert rcode == 0