summaryrefslogtreecommitdiff
path: root/test/test_api.py
blob: 9f5736479b6a96b6518c9048e4ca2a03c81e3a73 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from obsapi import ObsApi
from lxml import etree

api = ObsApi(apiurl='https://api.opensuse.org')

prj = 'home:sbahling:obsapi:test'
pkg = 'suse-hello-1.0'
repo = 'SLE_12_SP3'
arch = 'x86_64'


def test_get_project_meta():
    response = api.get_meta(prj=prj).strip()
    assert response[:9] == '<project '
    assert response[-10:] == '</project>'


def test_get_package_meta():
    response = api.get_meta(prj=prj, pkg=pkg).strip()
    assert response[:9] == '<package '
    assert response[-10:] == '</package>'


def test_ls_prj():
    assert api.ls(prj=prj) == ['suse-hello-1.0']


def test_ls_pkg():
    files = ['COPYING', 'suse-hello-1.0.tar.bz2',
             'suse-hello.changes', 'suse-hello.spec',
             ]
    directory, listing = api.ls(prj=prj, pkg=pkg)
    assert directory.name == 'suse-hello-1.0'
    items = [i.name for i in listing]
    for f in files:
        assert f in items


def test_ls_binaries():
    files = ['_statistics', 'rpmlint.log', 'suse-hello-1.0-1.1.src.rpm',
             'suse-hello-kmp-default-1.0_k4.4.73_5-1.1.x86_64.rpm',
             ]
    listing = api.ls(prj=prj, pkg=pkg, repo=repo, arch=arch)
    items = [i.filename for i in listing]
    for f in files:
        assert f in items


def test_binaries_ls():
    files = ['_statistics', 'rpmlint.log', 'suse-hello-1.0-1.1.src.rpm',
             'suse-hello-kmp-default-1.0_k4.4.73_5-1.1.x86_64.rpm',
             ]
    listing = api.binaries_ls(prj=prj, pkg=pkg, repo=repo, arch=arch)
    items = [i.filename for i in listing]
    for f in files:
        assert f in items


def test_binaries_ls_project():
    files = ['suse-hello-debugsource.rpm',
             'suse-hello-kmp-default.rpm',
             'suse-hello-kmp-default-debuginfo.rpm',
             ]
    listing = api.binaries_ls(prj=prj, pkg=None, repo=repo, arch=arch)
    items = [i.filename for i in listing]
    for f in files:
        assert f in items


def test_get_project_repos():
    repos = api.get_project_repos(prj)
    assert 'SLE_12_SP3' in repos


def test_get_vendor():
    assert api.get_vendor(prj=prj) == u'Test:obsapi'


def test_source_info():
    sinfo = api.get_source_info(prj, pkg)
    assert sinfo.package == 'suse-hello-1.0'
    assert sinfo.rev == '1'
    assert sinfo.vrev == '1'
    assert sinfo.srcmd5 == '7054c47fb2ebde13fc62ee64d0a3b1bc'
    assert sinfo.verifymd5 == '7054c47fb2ebde13fc62ee64d0a3b1bc'


def test_get_binary_fileinfo():
    binary = 'suse-hello-kmp-default-1.0_k4.4.73_5-1.1.x86_64.rpm'
    bfinfo = api.get_binary_fileinfo(prj, pkg, repo, arch, binary)
    assert bfinfo.filename == binary
    assert bfinfo.size == '6709'
    assert bfinfo.mtime == '1507137122'
    assert bfinfo.arch == 'x86_64'
    assert bfinfo.version == '1.0_k4.4.73_5'
    assert bfinfo.release == '1.1'
    assert bfinfo.summary == 'Sample Kernel Module Package'
    assert bfinfo.description == 'This package contains the hello.ko module.'
    assert bfinfo.source == 'suse-hello'
    binary = '_statistics'
    bfinfo = api.get_binary_fileinfo(prj, pkg, repo, arch, binary)


def check_get_repo_flags(flag_type, prj, pkg, expected):
    repo_flags = api.get_repo_flags(flag_type, prj, pkg)
    assert repo_flags.flag_type == flag_type
    assert len(list(repo_flags.flags)) == expected


def test_get_repo_build_flags():
    xml = api.get_meta(prj)
    check_get_repo_flags('build', prj, None, 0)
    xml = api.get_meta(prj, pkg)
    meta = etree.fromstring(xml)
    build = meta.find('build')
    check_get_repo_flags('build', prj, pkg, len(build))


def test_lock_project():
    api.lock(prj)
    xml = api.get_meta(prj)
    meta = etree.fromstring(xml)
    lock = meta.find('lock')
    assert lock is not None
    assert lock.find('enable') is not None


def test_unlock_project():
    api.unlock(prj)
    meta = etree.fromstring(api.get_meta(prj))
    lock = meta.find('lock')
    assert lock is None


def test_project_locked():
    api.lock(prj)
    assert api.locked(prj) is True
    api.unlock(prj)
    assert api.locked(prj) is False


def test_get_users():
    users = api.get_users(prj)
    assert len(users) > 0


def test_get_groups():
    groups = api.get_groups(prj)
    assert groups == []


def test_get_spec_files():
    for specfile in api.get_spec_files(prj, pkg):
        assert 'Name:' in specfile
        assert 'Summary:' in specfile
        assert '%description' in specfile
        assert '%setup' in specfile