Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: appengine/findit/model/test/versioned_config_test.py

Issue 1499583002: [Findit] Add a model to provide versioning and also a verioned config model. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Add versioned config model. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | appengine/findit/model/test/versioned_model_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from google.appengine.ext import ndb
6
7 from testing_utils import testing
8
9 from model.versioned_config import VersionedConfig
10
11
12 class _Config(VersionedConfig):
13 a = ndb.IntegerProperty(indexed=False, default=0)
14
15
16 class VersionedConfigTest(testing.AppengineTestCase):
17 def _CreateFirstVersion(self):
18 config = _Config.Get()
19 config.Update(a=1)
20
21 def testGetWhenNoConfigCreatedYet(self):
22 config = _Config.Get()
23 self.assertIsNotNone(config)
24 self.assertEqual(0, config.a)
25
26 def testNonAdminCanNotUpdate(self):
27 config = _Config.Get()
28 with self.assertRaises(Exception):
29 config.Update()
30
31 def testUpdateWhenChanged(self):
32 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
33 self._CreateFirstVersion()
34 config = _Config.Get()
35 self.assertIsNotNone(config)
36 self.assertTrue(config.Update(a=2))
37
38 config = _Config.Get()
39 self.assertIsNotNone(config)
40 self.assertEqual(2, config.version)
41 self.assertEqual(2, config.a)
42
43 def testNotUpdateWhenNotChanged(self):
44 self.mock_current_user(user_email='test@chromium.org', is_admin=True)
45 self._CreateFirstVersion()
46 config = _Config.Get()
47 self.assertIsNotNone(config)
48 self.assertFalse(config.Update(a=1))
49
50 config = _Config.Get()
51 self.assertIsNotNone(config)
52 self.assertEqual(1, config.version)
53 self.assertEqual(1, config.a)
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/model/test/versioned_model_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698