~launchpad-pqm/launchpad/devel

7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
4
"""Tests for feature flag change log."""
5
6
7
__metaclass__ = type
8
9
from datetime import datetime
10
11
import pytz
12
14550.1.1 by Steve Kowalik
Run format-imports over lib/lp and lib/canonical/launchpad
13
from lp.services.features.changelog import ChangeLog
7675.1052.8 by Curtis Hovey
Renamed FeatureFlagChange to FeatureFlagChangelogEntry.
14
from lp.services.features.model import FeatureFlagChangelogEntry
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
15
from lp.testing import TestCaseWithFactory
14612.2.1 by William Grant
format-imports on lib/. So many imports.
16
from lp.testing.layers import DatabaseFunctionalLayer
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
17
18
19
diff = (
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
20
    "-bugs.new_feature team:testers 10 on\n"
21
    "+bugs.new_feature team:testers 10 off")
22
23
24
class TestFeatureFlagChangelogEntry(TestCaseWithFactory):
7675.1052.8 by Curtis Hovey
Renamed FeatureFlagChange to FeatureFlagChangelogEntry.
25
    """Test the FeatureFlagChangelogEntry data."""
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
26
27
    layer = DatabaseFunctionalLayer
28
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
29
    def test_FeatureFlagChangelogEntry_creation(self):
7675.1052.8 by Curtis Hovey
Renamed FeatureFlagChange to FeatureFlagChangelogEntry.
30
        # A FeatureFlagChangelogEntry has a diff and a date of change.
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
31
        person = self.factory.makePerson()
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
32
        before = datetime.now(pytz.timezone('UTC'))
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
33
        feature_flag_change = FeatureFlagChangelogEntry(
34
            diff, u'comment', person)
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
35
        after = datetime.now(pytz.timezone('UTC'))
36
        self.assertEqual(
37
            diff, feature_flag_change.diff)
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
38
        self.assertEqual(
39
            u'comment', feature_flag_change.comment)
40
        self.assertEqual(
41
            person, feature_flag_change.person)
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
42
        self.assertBetween(
43
            before, feature_flag_change.date_changed, after)
44
45
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
46
class TestChangeLog(TestCaseWithFactory):
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
47
    """Test the feature flag ChangeLog utility."""
48
49
    layer = DatabaseFunctionalLayer
50
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
51
    def setUp(self):
52
        super(TestChangeLog, self).setUp()
53
        self.person = self.factory.makePerson()
54
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
55
    def test_ChangeLog_append(self):
7675.1052.8 by Curtis Hovey
Renamed FeatureFlagChange to FeatureFlagChangelogEntry.
56
        # The append() method creates a FeatureFlagChangelogEntry.
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
57
        feature_flag_change = ChangeLog.append(diff, 'comment', self.person)
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
58
        self.assertEqual(
59
            diff, feature_flag_change.diff)
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
60
        self.assertEqual(
61
            'comment', feature_flag_change.comment)
62
        self.assertEqual(
63
            self.person, feature_flag_change.person)
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
64
65
    def test_ChangeLog_get(self):
66
        # The get() method returns an iterator of FeatureFlagChanges from
67
        # newest to oldest.
7675.1052.9 by Curtis Hovey
Added comment and person to FeatureFlagChangelogEntry.
68
        feature_flag_change_1 = ChangeLog.append(diff, 'comment', self.person)
69
        feature_flag_change_2 = ChangeLog.append(diff, 'comment', self.person)
7675.1052.2 by Curtis Hovey
Added a model and a utility to work with featur flag changes records.
70
        results = ChangeLog.get()
71
        self.assertEqual(
72
            [feature_flag_change_2, feature_flag_change_1], list(results))