File: test_stream.py

package info (click to toggle)
python-snapcast 2.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 184 kB
  • sloc: python: 1,564; makefile: 9
file content (92 lines) | stat: -rw-r--r-- 2,885 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
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
import unittest
from snapcast.control.stream import Snapstream


class TestSnapstream(unittest.TestCase):

    def setUp(self):
        data_meta = {
            'id': 'test',
            'status': 'playing',
            'uri': {
                'query': {
                    'name': ''
                }
            },
            'meta': {
                'TITLE': 'Happy!',
            }
        }
        data = {
            'id': 'test',
            'status': 'playing',
            'uri': {
                'path': '/tmp/snapfifo',
                'query': {
                    'name': ''
                }
            },
            'properties': {
                'canControl': False,
                'metadata': {
                    'title': 'Happy!',
                }
            }
        }
        self.stream_meta = Snapstream(data_meta)
        self.stream = Snapstream(data)

    def test_init(self):
        self.assertEqual(self.stream.identifier, 'test')
        self.assertEqual(self.stream.status, 'playing')
        self.assertEqual(self.stream.name, '')
        self.assertEqual(self.stream.friendly_name, 'test')
        self.assertEqual(self.stream.path, '/tmp/snapfifo')
        self.assertDictEqual(self.stream_meta.meta, {'TITLE': 'Happy!'})
        self.assertDictEqual(self.stream.properties['metadata'], {'title': 'Happy!'})
        self.assertDictEqual(self.stream.properties,
                             {'canControl': False, 'metadata': {'title': 'Happy!'}})
        self.assertDictEqual(self.stream.metadata, {'title': 'Happy!'})

    def test_update(self):
        self.stream.update({
            'id': 'test',
            'status': 'idle'
        })
        self.assertEqual(self.stream.status, 'idle')

    def test_update_meta(self):
        self.stream_meta.update_meta({
            'TITLE': 'Unhappy!'
        })
        self.assertDictEqual(self.stream_meta.meta, {
            'TITLE': 'Unhappy!'
        })
        # Verify that other attributes are still present
        self.assertEqual(self.stream.status, 'playing')

    def test_update_metadata(self):
        self.stream.update_metadata({
            'title': 'Unhappy!'
        })
        self.assertDictEqual(self.stream.metadata, {
            'title': 'Unhappy!'
        })
        # Verify that other attributes are still present
        self.assertEqual(self.stream.status, 'playing')

    def test_update_properties(self):
        self.stream.update_properties({
            'canControl': True,
            'metadata': {
                'title': 'Unhappy!',
            }
        })
        self.assertDictEqual(self.stream.properties, {
            'canControl': True,
            'metadata': {
                'title': 'Unhappy!',
            }
        })
        # Verify that other attributes are still present
        self.assertEqual(self.stream.status, 'playing')