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

Side by Side Diff: generated/googleapis_beta/test/oslogin/v1alpha_test.dart

Issue 2973303002: Api-Roll 51: 2017-07-10 (Closed)
Patch Set: Created 3 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 library googleapis_beta.oslogin.v1alpha.test;
2
3 import "dart:core" as core;
4 import "dart:collection" as collection;
5 import "dart:async" as async;
6 import "dart:convert" as convert;
7
8 import 'package:http/http.dart' as http;
9 import 'package:http/testing.dart' as http_testing;
10 import 'package:test/test.dart' as unittest;
11
12 import 'package:googleapis_beta/oslogin/v1alpha.dart' as api;
13
14 class HttpServerMock extends http.BaseClient {
15 core.Function _callback;
16 core.bool _expectJson;
17
18 void register(core.Function callback, core.bool expectJson) {
19 _callback = callback;
20 _expectJson = expectJson;
21 }
22
23 async.Future<http.StreamedResponse> send(http.BaseRequest request) {
24 if (_expectJson) {
25 return request.finalize()
26 .transform(convert.UTF8.decoder)
27 .join('')
28 .then((core.String jsonString) {
29 if (jsonString.isEmpty) {
30 return _callback(request, null);
31 } else {
32 return _callback(request, convert.JSON.decode(jsonString));
33 }
34 });
35 } else {
36 var stream = request.finalize();
37 if (stream == null) {
38 return _callback(request, []);
39 } else {
40 return stream.toBytes().then((data) {
41 return _callback(request, data);
42 });
43 }
44 }
45 }
46 }
47
48 http.StreamedResponse stringResponse(
49 core.int status, core.Map<core.String, core.String> headers, core.String bod y) {
50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]);
51 return new http.StreamedResponse(stream, status, headers: headers);
52 }
53
54 core.int buildCounterEmpty = 0;
55 buildEmpty() {
56 var o = new api.Empty();
57 buildCounterEmpty++;
58 if (buildCounterEmpty < 3) {
59 }
60 buildCounterEmpty--;
61 return o;
62 }
63
64 checkEmpty(api.Empty o) {
65 buildCounterEmpty++;
66 if (buildCounterEmpty < 3) {
67 }
68 buildCounterEmpty--;
69 }
70
71 core.int buildCounterImportSshPublicKeyResponse = 0;
72 buildImportSshPublicKeyResponse() {
73 var o = new api.ImportSshPublicKeyResponse();
74 buildCounterImportSshPublicKeyResponse++;
75 if (buildCounterImportSshPublicKeyResponse < 3) {
76 o.loginProfile = buildLoginProfile();
77 }
78 buildCounterImportSshPublicKeyResponse--;
79 return o;
80 }
81
82 checkImportSshPublicKeyResponse(api.ImportSshPublicKeyResponse o) {
83 buildCounterImportSshPublicKeyResponse++;
84 if (buildCounterImportSshPublicKeyResponse < 3) {
85 checkLoginProfile(o.loginProfile);
86 }
87 buildCounterImportSshPublicKeyResponse--;
88 }
89
90 buildUnnamed3395() {
91 var o = new core.List<api.PosixAccount>();
92 o.add(buildPosixAccount());
93 o.add(buildPosixAccount());
94 return o;
95 }
96
97 checkUnnamed3395(core.List<api.PosixAccount> o) {
98 unittest.expect(o, unittest.hasLength(2));
99 checkPosixAccount(o[0]);
100 checkPosixAccount(o[1]);
101 }
102
103 buildUnnamed3396() {
104 var o = new core.Map<core.String, api.SshPublicKey>();
105 o["x"] = buildSshPublicKey();
106 o["y"] = buildSshPublicKey();
107 return o;
108 }
109
110 checkUnnamed3396(core.Map<core.String, api.SshPublicKey> o) {
111 unittest.expect(o, unittest.hasLength(2));
112 checkSshPublicKey(o["x"]);
113 checkSshPublicKey(o["y"]);
114 }
115
116 core.int buildCounterLoginProfile = 0;
117 buildLoginProfile() {
118 var o = new api.LoginProfile();
119 buildCounterLoginProfile++;
120 if (buildCounterLoginProfile < 3) {
121 o.name = "foo";
122 o.posixAccounts = buildUnnamed3395();
123 o.sshPublicKeys = buildUnnamed3396();
124 o.suspended = true;
125 }
126 buildCounterLoginProfile--;
127 return o;
128 }
129
130 checkLoginProfile(api.LoginProfile o) {
131 buildCounterLoginProfile++;
132 if (buildCounterLoginProfile < 3) {
133 unittest.expect(o.name, unittest.equals('foo'));
134 checkUnnamed3395(o.posixAccounts);
135 checkUnnamed3396(o.sshPublicKeys);
136 unittest.expect(o.suspended, unittest.isTrue);
137 }
138 buildCounterLoginProfile--;
139 }
140
141 core.int buildCounterPosixAccount = 0;
142 buildPosixAccount() {
143 var o = new api.PosixAccount();
144 buildCounterPosixAccount++;
145 if (buildCounterPosixAccount < 3) {
146 o.gecos = "foo";
147 o.gid = 42;
148 o.homeDirectory = "foo";
149 o.primary = true;
150 o.shell = "foo";
151 o.systemId = "foo";
152 o.uid = 42;
153 o.username = "foo";
154 }
155 buildCounterPosixAccount--;
156 return o;
157 }
158
159 checkPosixAccount(api.PosixAccount o) {
160 buildCounterPosixAccount++;
161 if (buildCounterPosixAccount < 3) {
162 unittest.expect(o.gecos, unittest.equals('foo'));
163 unittest.expect(o.gid, unittest.equals(42));
164 unittest.expect(o.homeDirectory, unittest.equals('foo'));
165 unittest.expect(o.primary, unittest.isTrue);
166 unittest.expect(o.shell, unittest.equals('foo'));
167 unittest.expect(o.systemId, unittest.equals('foo'));
168 unittest.expect(o.uid, unittest.equals(42));
169 unittest.expect(o.username, unittest.equals('foo'));
170 }
171 buildCounterPosixAccount--;
172 }
173
174 core.int buildCounterSshPublicKey = 0;
175 buildSshPublicKey() {
176 var o = new api.SshPublicKey();
177 buildCounterSshPublicKey++;
178 if (buildCounterSshPublicKey < 3) {
179 o.expirationTimeUsec = "foo";
180 o.fingerprint = "foo";
181 o.key = "foo";
182 }
183 buildCounterSshPublicKey--;
184 return o;
185 }
186
187 checkSshPublicKey(api.SshPublicKey o) {
188 buildCounterSshPublicKey++;
189 if (buildCounterSshPublicKey < 3) {
190 unittest.expect(o.expirationTimeUsec, unittest.equals('foo'));
191 unittest.expect(o.fingerprint, unittest.equals('foo'));
192 unittest.expect(o.key, unittest.equals('foo'));
193 }
194 buildCounterSshPublicKey--;
195 }
196
197
198 main() {
199 unittest.group("obj-schema-Empty", () {
200 unittest.test("to-json--from-json", () {
201 var o = buildEmpty();
202 var od = new api.Empty.fromJson(o.toJson());
203 checkEmpty(od);
204 });
205 });
206
207
208 unittest.group("obj-schema-ImportSshPublicKeyResponse", () {
209 unittest.test("to-json--from-json", () {
210 var o = buildImportSshPublicKeyResponse();
211 var od = new api.ImportSshPublicKeyResponse.fromJson(o.toJson());
212 checkImportSshPublicKeyResponse(od);
213 });
214 });
215
216
217 unittest.group("obj-schema-LoginProfile", () {
218 unittest.test("to-json--from-json", () {
219 var o = buildLoginProfile();
220 var od = new api.LoginProfile.fromJson(o.toJson());
221 checkLoginProfile(od);
222 });
223 });
224
225
226 unittest.group("obj-schema-PosixAccount", () {
227 unittest.test("to-json--from-json", () {
228 var o = buildPosixAccount();
229 var od = new api.PosixAccount.fromJson(o.toJson());
230 checkPosixAccount(od);
231 });
232 });
233
234
235 unittest.group("obj-schema-SshPublicKey", () {
236 unittest.test("to-json--from-json", () {
237 var o = buildSshPublicKey();
238 var od = new api.SshPublicKey.fromJson(o.toJson());
239 checkSshPublicKey(od);
240 });
241 });
242
243
244 unittest.group("resource-UsersResourceApi", () {
245 unittest.test("method--getLoginProfile", () {
246
247 var mock = new HttpServerMock();
248 api.UsersResourceApi res = new api.OsloginApi(mock).users;
249 var arg_name = "foo";
250 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
251 var path = (req.url).path;
252 var pathOffset = 0;
253 var index;
254 var subPart;
255 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
256 pathOffset += 1;
257 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ als("v1alpha/"));
258 pathOffset += 8;
259 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
260
261 var query = (req.url).query;
262 var queryOffset = 0;
263 var queryMap = {};
264 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
265 parseBool(n) {
266 if (n == "true") return true;
267 if (n == "false") return false;
268 if (n == null) return null;
269 throw new core.ArgumentError("Invalid boolean: $n");
270 }
271 if (query.length > 0) {
272 for (var part in query.split("&")) {
273 var keyvalue = part.split("=");
274 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
275 }
276 }
277
278
279 var h = {
280 "content-type" : "application/json; charset=utf-8",
281 };
282 var resp = convert.JSON.encode(buildLoginProfile());
283 return new async.Future.value(stringResponse(200, h, resp));
284 }), true);
285 res.getLoginProfile(arg_name).then(unittest.expectAsync1(((api.LoginProfil e response) {
286 checkLoginProfile(response);
287 })));
288 });
289
290 unittest.test("method--importSshPublicKey", () {
291
292 var mock = new HttpServerMock();
293 api.UsersResourceApi res = new api.OsloginApi(mock).users;
294 var arg_request = buildSshPublicKey();
295 var arg_parent = "foo";
296 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
297 var obj = new api.SshPublicKey.fromJson(json);
298 checkSshPublicKey(obj);
299
300 var path = (req.url).path;
301 var pathOffset = 0;
302 var index;
303 var subPart;
304 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
305 pathOffset += 1;
306 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ als("v1alpha/"));
307 pathOffset += 8;
308 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
309
310 var query = (req.url).query;
311 var queryOffset = 0;
312 var queryMap = {};
313 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
314 parseBool(n) {
315 if (n == "true") return true;
316 if (n == "false") return false;
317 if (n == null) return null;
318 throw new core.ArgumentError("Invalid boolean: $n");
319 }
320 if (query.length > 0) {
321 for (var part in query.split("&")) {
322 var keyvalue = part.split("=");
323 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
324 }
325 }
326
327
328 var h = {
329 "content-type" : "application/json; charset=utf-8",
330 };
331 var resp = convert.JSON.encode(buildImportSshPublicKeyResponse());
332 return new async.Future.value(stringResponse(200, h, resp));
333 }), true);
334 res.importSshPublicKey(arg_request, arg_parent).then(unittest.expectAsync1 (((api.ImportSshPublicKeyResponse response) {
335 checkImportSshPublicKeyResponse(response);
336 })));
337 });
338
339 });
340
341
342 unittest.group("resource-UsersSshPublicKeysResourceApi", () {
343 unittest.test("method--delete", () {
344
345 var mock = new HttpServerMock();
346 api.UsersSshPublicKeysResourceApi res = new api.OsloginApi(mock).users.ssh PublicKeys;
347 var arg_name = "foo";
348 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
349 var path = (req.url).path;
350 var pathOffset = 0;
351 var index;
352 var subPart;
353 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
354 pathOffset += 1;
355 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ als("v1alpha/"));
356 pathOffset += 8;
357 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
358
359 var query = (req.url).query;
360 var queryOffset = 0;
361 var queryMap = {};
362 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
363 parseBool(n) {
364 if (n == "true") return true;
365 if (n == "false") return false;
366 if (n == null) return null;
367 throw new core.ArgumentError("Invalid boolean: $n");
368 }
369 if (query.length > 0) {
370 for (var part in query.split("&")) {
371 var keyvalue = part.split("=");
372 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
373 }
374 }
375
376
377 var h = {
378 "content-type" : "application/json; charset=utf-8",
379 };
380 var resp = convert.JSON.encode(buildEmpty());
381 return new async.Future.value(stringResponse(200, h, resp));
382 }), true);
383 res.delete(arg_name).then(unittest.expectAsync1(((api.Empty response) {
384 checkEmpty(response);
385 })));
386 });
387
388 unittest.test("method--get", () {
389
390 var mock = new HttpServerMock();
391 api.UsersSshPublicKeysResourceApi res = new api.OsloginApi(mock).users.ssh PublicKeys;
392 var arg_name = "foo";
393 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
394 var path = (req.url).path;
395 var pathOffset = 0;
396 var index;
397 var subPart;
398 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
399 pathOffset += 1;
400 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ als("v1alpha/"));
401 pathOffset += 8;
402 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
403
404 var query = (req.url).query;
405 var queryOffset = 0;
406 var queryMap = {};
407 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
408 parseBool(n) {
409 if (n == "true") return true;
410 if (n == "false") return false;
411 if (n == null) return null;
412 throw new core.ArgumentError("Invalid boolean: $n");
413 }
414 if (query.length > 0) {
415 for (var part in query.split("&")) {
416 var keyvalue = part.split("=");
417 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
418 }
419 }
420
421
422 var h = {
423 "content-type" : "application/json; charset=utf-8",
424 };
425 var resp = convert.JSON.encode(buildSshPublicKey());
426 return new async.Future.value(stringResponse(200, h, resp));
427 }), true);
428 res.get(arg_name).then(unittest.expectAsync1(((api.SshPublicKey response) {
429 checkSshPublicKey(response);
430 })));
431 });
432
433 unittest.test("method--patch", () {
434
435 var mock = new HttpServerMock();
436 api.UsersSshPublicKeysResourceApi res = new api.OsloginApi(mock).users.ssh PublicKeys;
437 var arg_request = buildSshPublicKey();
438 var arg_name = "foo";
439 var arg_updateMask = "foo";
440 mock.register(unittest.expectAsync2((http.BaseRequest req, json) {
441 var obj = new api.SshPublicKey.fromJson(json);
442 checkSshPublicKey(obj);
443
444 var path = (req.url).path;
445 var pathOffset = 0;
446 var index;
447 var subPart;
448 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ als("/"));
449 pathOffset += 1;
450 unittest.expect(path.substring(pathOffset, pathOffset + 8), unittest.equ als("v1alpha/"));
451 pathOffset += 8;
452 // NOTE: We cannot test reserved expansions due to the inability to reve rse the operation;
453
454 var query = (req.url).query;
455 var queryOffset = 0;
456 var queryMap = {};
457 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v);
458 parseBool(n) {
459 if (n == "true") return true;
460 if (n == "false") return false;
461 if (n == null) return null;
462 throw new core.ArgumentError("Invalid boolean: $n");
463 }
464 if (query.length > 0) {
465 for (var part in query.split("&")) {
466 var keyvalue = part.split("=");
467 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d ecodeQueryComponent(keyvalue[1]));
468 }
469 }
470 unittest.expect(queryMap["updateMask"].first, unittest.equals(arg_update Mask));
471
472
473 var h = {
474 "content-type" : "application/json; charset=utf-8",
475 };
476 var resp = convert.JSON.encode(buildSshPublicKey());
477 return new async.Future.value(stringResponse(200, h, resp));
478 }), true);
479 res.patch(arg_request, arg_name, updateMask: arg_updateMask).then(unittest .expectAsync1(((api.SshPublicKey response) {
480 checkSshPublicKey(response);
481 })));
482 });
483
484 });
485
486
487 }
488
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698