1 # ==================================================================================
2 # Copyright (c) 2019 Nokia
3 # Copyright (c) 2018-2019 AT&T Intellectual Property.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
20 from rmr.rmr_mocks import rmr_mocks
27 def test_get_mapping_dict(monkeypatch, fake_consts, expected_states):
29 test getting mapping string
32 def fake_rmr_get_consts():
33 return json.dumps(fake_consts).encode("utf-8")
35 monkeypatch.setattr("rmr.rmr._rmr_const", fake_rmr_get_consts)
36 assert rmr._get_mapping_dict() == expected_states
37 # do again, trigger cache line coverage
38 assert rmr._get_mapping_dict() == expected_states
40 assert rmr._state_to_status(0) == "RMR_OK"
41 assert rmr._state_to_status(12) == "RMR_ERR_TIMEOUT"
42 assert rmr._state_to_status(666) == "UNKNOWN STATE"
45 def test_meid_prettify(monkeypatch):
46 rmr_mocks.patch_rmr(monkeypatch)
48 # here we re-monkey get_meid
49 monkeypatch.setattr("rmr.rmr.get_meid", lambda _: "yoooo")
50 sbuf = rmr.rmr_alloc_msg(MRC, SIZE)
51 summary = rmr.message_summary(sbuf)
52 assert summary["meid"] == "yoooo"
55 monkeypatch.setattr("rmr.rmr.get_meid", lambda _: b"\x01\x00f\x80")
56 sbuf = rmr.rmr_alloc_msg(MRC, SIZE)
57 summary = rmr.message_summary(sbuf)
58 assert summary["meid"] == b"\x01\x00f\x80"
60 # test the cleanup of null bytes
63 lambda _: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
65 sbuf = rmr.rmr_alloc_msg(MRC, SIZE)
66 summary = rmr.message_summary(sbuf)
67 assert summary["meid"] == None