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

Side by Side Diff: pkg/appengine/test/dart-python--datastore-compatibility/dart/bin/main.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files Created 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io';
6 import 'dart:convert';
7
8 import 'package:unittest/unittest.dart';
9
10 import 'package:appengine/src/protobuf_api/rpc/rpc_service_remote_api.dart';
11 import 'package:appengine/src/appengine_context.dart';
12 import 'package:appengine/src/api_impl/raw_datastore_v3_impl.dart';
13
14 import 'package:gcloud/db.dart';
15 import 'package:gcloud/db.dart' as db;
16
17
18 class AllDataTypesModelMixin {
19 @BoolProperty()
20 bool boolProp;
21
22 @IntProperty()
23 int intProp;
24
25 @StringProperty()
26 String stringProp;
27
28 @ModelKeyProperty()
29 Key keyProp;
30
31 @BlobProperty()
32 List<int> blobProp;
33
34 @DateTimeProperty()
35 DateTime dateProp;
36
37 @StringListProperty()
38 List<String> stringListProp;
39 }
40
41 @Kind()
42 class NormalModel extends Model with AllDataTypesModelMixin { }
43
44 @Kind()
45 class ExpandoModel extends db.ExpandoModel with AllDataTypesModelMixin { }
46
47
48 final DateTime EndOfYear = new DateTime.utc(2014, 12, 31);
49 customDate(int i) => EndOfYear.add(new Duration(hours: i));
50
51 void fillData(DatastoreDB db, AllDataTypesModelMixin model, int i) {
52 model.boolProp = i % 2 == 0;
53 model.intProp = i + 42;
54 model.stringProp = 'foobar $i';
55 model.keyProp = db.emptyKey.append(NormalModel, id: 10 + i);
56 model.blobProp = [1, 2, 3, 4]..addAll(UTF8.encode('$i'));
57 model.dateProp = customDate(i);
58 model.stringListProp = ['a$i', 'b$i', 'c$i'];
59 }
60
61 void verifyData(DatastoreDB db, AllDataTypesModelMixin model, int i) {
62 expect(model.boolProp, equals(i % 2 == 0));
63 expect(model.intProp, equals(i + 42));
64 expect(model.stringProp, equals('foobar $i'));
65 expect(model.keyProp, equals(db.emptyKey.append(NormalModel, id: 10 + i)));
66 expect(model.blobProp, equals(
67 [1, 2, 3, 4]..addAll(UTF8.encode('$i'))));
68 expect(model.dateProp, equals(customDate(i)));
69 expect(model.stringListProp, equals(['a$i', 'b$i', 'c$i']));
70 }
71
72 runTests(bool writingMode, DatastoreDB db) {
73 var key = db.emptyKey.append(NormalModel, id: 99);
74 var ekey = key.append(ExpandoModel, id: 102);
75
76 if (writingMode) {
77 test('writing-test', () {
78 var normalObj = new NormalModel();
79 var em = new ExpandoModel();
80
81 em.parentKey = key;
82
83 normalObj.id = 99;
84 em.id = 102;
85
86 fillData(db, normalObj, 1);
87 fillData(db, em, 5);
88
89 db.commit(inserts: [normalObj, em]).then(expectAsync((_) {
90 print('done');
91 }));
92 });
93 }
94
95 if (!writingMode) {
96 test('reading-test', () {
97 db.lookup([key, ekey])
98 .then(expectAsync((List<Model> models) {
99 expect(models, hasLength(2));
100
101 NormalModel model = models[0];
102 ExpandoModel emodel = models[1];
103
104 expect(model, isNotNull);
105 expect(emodel, isNotNull);
106
107 expect(model.id, equals(99));
108 expect(emodel.id, equals(102));
109
110 expect(model.parentKey, equals(db.emptyKey));
111 expect(emodel.parentKey, equals(key));
112
113 verifyData(db, model, 1);
114 verifyData(db, emodel, 5);
115 }));
116 });
117 }
118 }
119
120 void main(List<String> arguments) {
121 if (arguments.length != 1 || !['read', 'write'].contains(arguments[0])) {
122 print("Usage: main.dart <read|write>");
123 exit(1);
124 }
125 var writingMode = arguments[0] == 'write';
126
127 var rpcService = new RPCServiceRemoteApi('localhost', 4444);
128 var appengineContext = new AppengineContext(
129 'dev', 'test-application', 'test-version', null, null, null);
130 var datastore =
131 new DatastoreV3RpcImpl(rpcService, appengineContext, '<invalid-ticket>');
132
133 runTests(writingMode, new DatastoreDB(datastore));
134 }
135
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698