210
252
self.assertEqual("foo", dialog.hosted_account_name_entry.get_text())
211
253
self.assertEqual("bar", dialog.hosted_password_entry.get_text())
255
def test_check_local_landscape_host_name_entry_ok(self):
257
Test that L{check_local_landscape_host_name_entry} returns L{True} when
258
the input is a valid host name.
260
dialog = ClientSettingsDialog(self.controller)
261
dialog.use_type_combobox.set_active(2)
262
dialog.local_landscape_host_entry.set_text("foo.bar")
263
self.assertTrue(dialog.check_local_landscape_host_name_entry())
265
def test_check_local_landscape_host_name_entry_ok_not_recorded(self):
267
Test that L{check_local_landscape_host_name_entry} does not add the
268
entry to L{ClientSettingsDialog._errored_entries} when the input is a
271
dialog = ClientSettingsDialog(self.controller)
272
dialog.use_type_combobox.set_active(2)
273
dialog.local_landscape_host_entry.set_text("foo.bar")
274
dialog.check_local_landscape_host_name_entry()
275
self.assertEqual(0, len(dialog._errored_entries))
277
def test_check_local_landscape_host_name_entry_bad_host_name(self):
279
Test that L{check_local_landscape_host_name_entry} returns L{False}
280
when the input is not a valid host name.
282
dialog = ClientSettingsDialog(self.controller)
283
dialog.use_type_combobox.set_active(2)
284
dialog.local_landscape_host_entry.set_text("foo bar")
285
self.assertFalse(dialog.check_local_landscape_host_name_entry())
287
def test_check_local_landscape_host_name_entry_bad_recorded(self):
289
Test that L{check_local_landscape_host_name_entry} does add the
290
entry to L{ClientSettingsDialog._errored_entries} when the input is not
293
dialog = ClientSettingsDialog(self.controller)
294
dialog.use_type_combobox.set_active(2)
295
dialog.local_landscape_host_entry.set_text("foo bar")
296
dialog.check_local_landscape_host_name_entry()
297
self.assertEqual(1, len(dialog._errored_entries))
299
def test_check_local_landscape_host_name_entry_bad_error_type(self):
301
Test that L{check_local_landscape_host_name_entry} adds the correct
302
error type to L{ClientSettingsDialog._validation_errors} when the input
303
is not a valid host name.
305
dialog = ClientSettingsDialog(self.controller)
306
dialog.use_type_combobox.set_active(2)
307
dialog.local_landscape_host_entry.set_text("foo bar")
308
dialog.check_local_landscape_host_name_entry()
309
self.assertEqual(set([dialog.INVALID_HOST_NAME]),
310
dialog._validation_errors)
312
def test_check_local_landscape_host_name_entry_unicode_in_host_name(self):
314
Test that L{check_local_landscape_host_name_entry} returns L{False}
315
when the input contains Unicode.
317
dialog = ClientSettingsDialog(self.controller)
318
dialog.use_type_combobox.set_active(2)
319
dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
320
self.assertFalse(dialog.check_local_landscape_host_name_entry())
322
def test_check_local_landscape_host_name_entry_unicode_recorded(self):
324
Test that L{check_local_landscape_host_name_entry} does add the
325
entry to L{ClientSettingsDialog._errored_entries} when the input
328
dialog = ClientSettingsDialog(self.controller)
329
dialog.use_type_combobox.set_active(2)
330
dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
331
dialog.check_local_landscape_host_name_entry()
332
self.assertEqual(1, len(dialog._errored_entries))
334
def test_check_local_landscape_host_name_entry_unicode_error_type(self):
336
Test that L{check_local_landscape_host_name_entry} adds the correct
337
error type to L{ClientSettingsDialog._validation_errors} when the input
340
dialog = ClientSettingsDialog(self.controller)
341
dialog.use_type_combobox.set_active(2)
342
dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
343
dialog.check_local_landscape_host_name_entry()
345
set([dialog.INVALID_HOST_NAME, dialog.UNICODE_IN_ENTRY]),
346
dialog._validation_errors)
348
def test_check_entry_ok(self):
350
Test that we return L{True} when the text of a L{Gtk.Entry} is valid
353
dialog = ClientSettingsDialog(self.controller)
354
self.run_gtk_eventloop()
355
dialog.use_type_combobox.set_active(1)
356
self.run_gtk_eventloop()
357
dialog.hosted_account_name_entry.set_text("Toodleoo")
358
self.assertTrue(dialog.check_entry(dialog.hosted_account_name_entry))
360
def test_check_entry_doesnt_record_entry_when_ok(self):
362
Test that, when the text of a L{Gtk.Entry} is valid nothing is added to
363
L{ClientSettingsDialog._errored_entries}.
365
dialog = ClientSettingsDialog(self.controller)
366
self.run_gtk_eventloop()
367
dialog.use_type_combobox.set_active(1)
368
self.run_gtk_eventloop()
369
dialog.hosted_account_name_entry.set_text("Toodleoo")
370
dialog.check_entry(dialog.hosted_account_name_entry)
371
self.assertEqual(0, len(dialog._errored_entries))
373
def test_check_entry_non_ascii(self):
375
Test that we return L{False} when the text of a L{Gtk.Entry} contains
378
dialog = ClientSettingsDialog(self.controller)
379
self.run_gtk_eventloop()
380
dialog.use_type_combobox.set_active(1)
381
self.run_gtk_eventloop()
382
dialog.hosted_account_name_entry.set_text(u"T\xc3dle\xc4")
383
self.assertFalse(dialog.check_entry(dialog.hosted_account_name_entry))
385
def test_check_entry_records_entry_when_non_ascii(self):
387
Test that, when the text of a L{Gtk.Entry} contains Unicode it is
388
added to L{ClientSettingsDialog._errored_entries}.
390
dialog = ClientSettingsDialog(self.controller)
391
self.run_gtk_eventloop()
392
dialog.use_type_combobox.set_active(1)
393
self.run_gtk_eventloop()
394
dialog.hosted_account_name_entry.set_text(u"T\xc3dle\xc4")
395
dialog.check_entry(dialog.hosted_account_name_entry)
396
self.assertEqual(1, len(dialog._errored_entries))
398
def test_dismiss_validation_errors_local(self):
400
Test that dismissing the validation errors tidies up indicators that
401
have been set against local settings.
403
dialog = ClientSettingsDialog(self.controller)
404
self.run_gtk_eventloop()
405
dialog.use_type_combobox.set_active(1)
406
self.run_gtk_eventloop()
407
dialog.hosted_account_name_entry.set_text(u"T\xc3dle\xc4")
408
dialog.hosted_password_entry.set_text(u"T\xc3dle\xc4")
409
self.run_gtk_eventloop()
410
dialog.validity_check()
411
self.run_gtk_eventloop()
412
self.assertEqual(2, len(dialog._errored_entries))
413
[entry1, entry2] = dialog._errored_entries
414
self.assertEqual(Gtk.STOCK_DIALOG_WARNING,
415
entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
416
self.assertEqual(Gtk.STOCK_DIALOG_WARNING,
417
entry2.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
418
dialog.dismiss_infobar(None)
419
self.run_gtk_eventloop()
420
self.assertEqual(0, len(dialog._errored_entries))
422
Gtk.STOCK_DIALOG_WARNING,
423
entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
425
Gtk.STOCK_DIALOG_WARNING,
426
entry2.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
428
def test_dismiss_validation_errors_hosted(self):
430
Test that dismissing the validation errors tidies up indicators that
431
have been set against hosted fields.
433
dialog = ClientSettingsDialog(self.controller)
434
self.run_gtk_eventloop()
435
dialog.use_type_combobox.set_active(2)
436
self.run_gtk_eventloop()
437
dialog.local_landscape_host_entry.set_text("dodgy as hell")
438
self.run_gtk_eventloop()
439
dialog.validity_check()
440
self.run_gtk_eventloop()
441
self.assertEqual(1, len(dialog._errored_entries))
442
[entry1] = dialog._errored_entries
443
self.assertEqual(Gtk.STOCK_DIALOG_WARNING,
444
entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
445
dialog.dismiss_infobar(None)
446
self.run_gtk_eventloop()
447
self.assertEqual(0, len(dialog._errored_entries))
449
Gtk.STOCK_DIALOG_WARNING,
450
entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
452
def test_validity_check_disabled(self):
454
Test that the L{validity_check} returns True when we disable landscape
457
dialog = ClientSettingsDialog(self.controller)
458
self.run_gtk_eventloop()
459
dialog.use_type_combobox.set_active(0)
460
self.run_gtk_eventloop()
461
self.assertTrue(dialog.validity_check())
463
def test_validity_check_hosted(self):
465
Test that the L{validity_check} returns True when the hosted fields are
468
dialog = ClientSettingsDialog(self.controller)
469
self.run_gtk_eventloop()
470
dialog.use_type_combobox.set_active(1)
471
dialog.hosted_account_name_entry.set_text("Bob")
472
dialog.hosted_password_entry.set_text("the builder")
473
self.run_gtk_eventloop()
474
self.assertTrue(dialog.validity_check())
476
def test_validity_check_hosted_unicode(self):
478
Test that the L{validity_check} returns False when the hosted fields
481
dialog = ClientSettingsDialog(self.controller)
482
self.run_gtk_eventloop()
483
dialog.use_type_combobox.set_active(1)
484
dialog.hosted_account_name_entry.set_text(u"B\xc3b")
485
self.run_gtk_eventloop()
486
self.assertFalse(dialog.validity_check())
488
def test_validity_check_local_ok(self):
490
Test that the L{validity_check} returns True when the local fields
493
dialog = ClientSettingsDialog(self.controller)
494
self.run_gtk_eventloop()
495
dialog.use_type_combobox.set_active(2)
496
self.run_gtk_eventloop()
497
dialog.local_landscape_host_entry.set_text("foo.bar")
498
self.run_gtk_eventloop()
499
self.assertTrue(dialog.validity_check())
501
def test_validity_check_local_sanitisable(self):
503
Test that the L{validity_check} returns True when the local fields
504
are valid after sanitation.
506
dialog = ClientSettingsDialog(self.controller)
507
self.run_gtk_eventloop()
508
dialog.use_type_combobox.set_active(2)
509
dialog.local_landscape_host_entry.set_text(" foo.bar")
510
self.run_gtk_eventloop()
511
self.assertTrue(dialog.validity_check())
512
dialog.local_landscape_host_entry.set_text("foo.bar ")
513
self.run_gtk_eventloop()
514
self.assertTrue(dialog.validity_check())
516
def test_validity_check_local_invalid_host_name(self):
518
Test that the L{validity_check} returns False when the host name is
521
dialog = ClientSettingsDialog(self.controller)
522
self.run_gtk_eventloop()
523
dialog.use_type_combobox.set_active(2)
524
dialog.local_landscape_host_entry.set_text("foo bar")
525
self.run_gtk_eventloop()
526
self.assertFalse(dialog.validity_check())
528
def test_validity_check_local_unicode(self):
530
Test that the L{validity_check} returns False when the host name
533
dialog = ClientSettingsDialog(self.controller)
534
self.run_gtk_eventloop()
535
dialog.use_type_combobox.set_active(2)
536
dialog.local_landscape_host_entry.set_text(u"f\xc3.bar")
537
self.run_gtk_eventloop()
538
self.assertFalse(dialog.validity_check())
213
540
if not got_gobject_introspection:
214
541
skip = gobject_skip_message