File: test_data.py

package info (click to toggle)
bugwarrior 1.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,008 kB
  • sloc: python: 7,762; makefile: 153
file content (41 lines) | stat: -rw-r--r-- 1,157 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
import os
import json
import configparser

from bugwarrior import data

from .base import ConfigTest


class TestData(ConfigTest):
    def setUp(self):
        super(TestData, self).setUp()
        config = configparser.RawConfigParser()
        config.add_section('general')
        self.data = data.BugwarriorData(self.lists_path)

    def assert0600(self):
        permissions = oct(os.stat(self.data.datafile).st_mode & 0o777)
        # python2 -> 0600, python3 -> 0o600
        self.assertIn(permissions, ['0600', '0o600'])

    def test_get_set(self):
        # "touch" data file.
        with open(self.data.datafile, 'w+') as handle:
            json.dump({'old': 'stuff'}, handle)

        self.data.set('key', 'value')

        self.assertEqual(self.data.get('key'), 'value')
        self.assertEqual(
            self.data.get_data(), {'old': 'stuff', 'key': 'value'})
        self.assert0600()

    def test_set_first_time(self):
        self.data.set('key', 'value')

        self.assertEqual(self.data.get('key'), 'value')
        self.assert0600()

    def test_path_attribute(self):
        self.assertEqual(self.data.path, self.lists_path)