| 1 |
import os |
| 2 |
import json |
| 3 |
from six.moves import configparser |
| 4 |
|
| 5 |
from bugwarrior import data |
| 6 |
|
| 7 |
from .base import ConfigTest |
| 8 |
|
| 9 |
|
| 10 |
class TestData(ConfigTest): |
| 11 |
def setUp(self): |
| 12 |
super(TestData, self).setUp() |
| 13 |
config = configparser.RawConfigParser() |
| 14 |
config.add_section('general') |
| 15 |
self.data = data.BugwarriorData(self.lists_path) |
| 16 |
|
| 17 |
def assert0600(self): |
| 18 |
permissions = oct(os.stat(self.data.datafile).st_mode & 0o777) |
| 19 |
# python2 -> 0600, python3 -> 0o600 |
| 20 |
self.assertIn(permissions, ['0600', '0o600']) |
| 21 |
|
| 22 |
def test_get_set(self): |
| 23 |
# "touch" data file. |
| 24 |
with open(self.data.datafile, 'w+') as handle: |
| 25 |
json.dump({'old': 'stuff'}, handle) |
| 26 |
|
| 27 |
self.data.set('key', 'value') |
| 28 |
|
| 29 |
self.assertEqual(self.data.get('key'), 'value') |
| 30 |
self.assertEqual( |
| 31 |
self.data.get_data(), {'old': 'stuff', 'key': 'value'}) |
| 32 |
self.assert0600() |
| 33 |
|
| 34 |
def test_set_first_time(self): |
| 35 |
self.data.set('key', 'value') |
| 36 |
|
| 37 |
self.assertEqual(self.data.get('key'), 'value') |
| 38 |
self.assert0600() |
| 39 |
|
| 40 |
def test_path_attribute(self): |
| 41 |
self.assertEqual(self.data.path, self.lists_path) |