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

Unified Diff: appengine/auth_service/importer_test.py

Issue 1148073005: Use luci-config for infrequently changing settings, part 2. (Closed) Base URL: git@github.com:luci/luci-py@master
Patch Set: fix pylint (??!) Created 5 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/auth_service/importer.py ('k') | appengine/auth_service/proto/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/auth_service/importer_test.py
diff --git a/appengine/auth_service/importer_test.py b/appengine/auth_service/importer_test.py
index 09a1df1517513bfe6d86c34f5092bf085e24cdef..91ab55a57c1f1fc9c293b4bad4a5b8f391c2e569 100755
--- a/appengine/auth_service/importer_test.py
+++ b/appengine/auth_service/importer_test.py
@@ -11,6 +11,7 @@ import StringIO
import sys
import tarfile
import tempfile
+import textwrap
import unittest
APP_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -25,6 +26,10 @@ from components import auth_testing
from components.auth import model
from test_support import test_case
+# Must be after 'components' import, since they add it to sys.path.
+from google import protobuf
+
+from proto import config_pb2
import importer
@@ -69,6 +74,13 @@ def fetch_groups():
return {x.key.id(): x.to_dict() for x in model.AuthGroup.query()}
+def put_config(config_proto, config):
+ importer.GroupImporterConfig(
+ key=importer.config_key(),
+ config_proto=config_proto,
+ config=config).put()
+
+
class ImporterTest(test_case.TestCase):
def setUp(self):
super(ImporterTest, self).setUp()
@@ -223,30 +235,26 @@ class ImporterTest(test_case.TestCase):
service_id = auth.Identity.from_bytes('service:some-service')
self.mock(auth, 'get_service_self_identity', lambda: service_id)
- importer.write_config([
- {
- 'domain': 'example.com',
- 'format': 'tarball',
- 'groups': ['ldap/new'],
- 'oauth_scopes': ['scope'],
- 'systems': ['ldap'],
- 'url': 'https://fake_tarball',
- },
- {
- 'format': 'plainlist',
- 'group': 'external_1',
- 'oauth_scopes': ['scope'],
- 'url': 'https://fake_external_1',
- },
- {
- 'description': 'Some external group',
- 'domain': 'example.com',
- 'format': 'plainlist',
- 'group': 'external_2',
- 'oauth_scopes': ['scope'],
- 'url': 'https://fake_external_2',
- },
- ])
+ importer.write_config_text("""
+ tarball {
+ domain: "example.com"
+ groups: "ldap/new"
+ oauth_scopes: "scope"
+ systems: "ldap"
+ url: "https://fake_tarball"
+ }
+ plainlist {
+ group: "external_1"
+ oauth_scopes: "scope"
+ url: "https://fake_external_1"
+ }
+ plainlist {
+ domain: "example.com"
+ group: "external_2"
+ oauth_scopes: "scope"
+ url: "https://fake_external_2"
+ }
+ """)
self.mock_urlfetch({
'https://fake_tarball': build_tar_gz({
@@ -303,6 +311,64 @@ class ImporterTest(test_case.TestCase):
}
self.assertEqual(expected_groups, fetch_groups())
+ def test_read_config_text(self):
+ # Empty.
+ put_config('', '')
+ self.assertEqual('', importer.read_config_text())
+ # Good.
+ put_config('tarball{}', '')
+ self.assertEqual('tarball{}', importer.read_config_text())
+ # Legacy.
+ put_config('', '[{"url":"12"}]')
+ self.assertEqual('tarball {\n url: "12"\n}\n', importer.read_config_text())
+
+ def test_write_config_text(self):
+ put_config('', 'legacy')
+ importer.write_config_text('tarball{url:"12"\nsystems:"12"}')
+ e = importer.config_key().get()
+ self.assertEqual('legacy', e.config)
+ self.assertEqual('tarball{url:"12"\nsystems:"12"}', e.config_proto)
+
+ def test_legacy_json_config_to_proto(self):
+ msg = importer.legacy_json_config_to_proto("""
+ [
+ {
+ "url": "https://example.com/all_users",
+ "group": "plain-list",
+ "format": "plainlist"
+ },
+ {
+ "url": "https://example.com/tarball.tar.gz",
+ "domain": "example.com",
+ "oauth_scopes": [
+ "oauth-scope"
+ ],
+ "systems": [
+ "ldap"
+ ],
+ "groups": [
+ "ldap/a",
+ "ldap/b"
+ ]
+ }
+ ]
+ """)
+ expected = textwrap.dedent("""
+ tarball {
+ url: "https://example.com/tarball.tar.gz"
+ oauth_scopes: "oauth-scope"
+ domain: "example.com"
+ systems: "ldap"
+ groups: "ldap/a"
+ groups: "ldap/b"
+ }
+ plainlist {
+ url: "https://example.com/all_users"
+ group: "plain-list"
+ }
+ """.lstrip('\n'))
+ self.assertEqual(expected, protobuf.text_format.MessageToString(msg))
+
if __name__ == '__main__':
if '-v' in sys.argv:
« no previous file with comments | « appengine/auth_service/importer.py ('k') | appengine/auth_service/proto/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698