~ubuntu-branches/ubuntu/precise/landscape-client/precise-updates

« back to all changes in this revision

Viewing changes to landscape/ui/view/tests/test_configuration.py

  • Committer: Package Import Robot
  • Author(s): David Britton
  • Date: 2012-03-28 10:59:58 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20120328105958-jmz1nv5eyci7azna
Tags: 12.04.3-0ubuntu1
* Warn on unicode entry into settings UI (LP: #956612).
* Sanitise hostname field in settings UI (LP: #954507).
* Make it clear that the Landscape service is commercial (LP: #965850)
* Further internationalize the settings UI (LP: #962899)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
if got_gobject_introspection:
8
8
    from gi.repository import Gtk
9
 
    from landscape.ui.view.configuration import ClientSettingsDialog
 
9
    from landscape.ui.view.configuration import (
 
10
        ClientSettingsDialog, sanitise_host_name, is_valid_host_name)
10
11
    from landscape.ui.controller.configuration import ConfigController
11
12
    import landscape.ui.model.configuration.state
12
13
    from landscape.ui.model.configuration.state import (
16
17
from landscape.tests.helpers import LandscapeTest
17
18
 
18
19
 
 
20
class ViewFunctionsTest(LandscapeTest):
 
21
 
 
22
    def test_sanitise_host_name(self):
 
23
        """
 
24
        Test UI level host_name sanitation.
 
25
        """
 
26
        self.assertEqual("foo.bar", sanitise_host_name(" foo.bar"))
 
27
        self.assertEqual("foo.bar", sanitise_host_name("foo.bar "))
 
28
        self.assertEqual("foo.bar", sanitise_host_name(" foo.bar "))
 
29
 
 
30
    def test_is_valid_host_name_ok(self):
 
31
        """
 
32
        Test that valid host names cause L{is_valid_host_name} to return
 
33
        L{True}.
 
34
        """
 
35
        self.assertTrue(is_valid_host_name("a"))
 
36
        self.assertTrue(is_valid_host_name("a.b"))
 
37
        self.assertTrue(is_valid_host_name("a.b.c"))
 
38
        self.assertTrue(is_valid_host_name("stop-squark"))
 
39
        self.assertTrue(is_valid_host_name("stop-squark.teale.DE"))
 
40
        self.assertTrue(is_valid_host_name("a2.b3.c4"))
 
41
 
 
42
    def test_is_valid_host_name_bad(self):
 
43
        """
 
44
        Test that invalid host names cause L{is_valid_host_name} to return
 
45
        L{False}.
 
46
        """
 
47
        self.assertFalse(is_valid_host_name(".a"))
 
48
        self.assertFalse(is_valid_host_name("a."))
 
49
        self.assertFalse(is_valid_host_name("a b"))
 
50
        self.assertFalse(is_valid_host_name("a .b"))
 
51
        self.assertFalse(is_valid_host_name("a. b"))
 
52
 
 
53
    def test_is_valid_host_name_unicode(self):
 
54
        """
 
55
        Test that host names containing Unicode cause L{is_valid_host_name} to
 
56
        return L{False}.
 
57
        """
 
58
        self.assertFalse(is_valid_host_name(u"\xc3a"))
 
59
 
 
60
 
19
61
class ConfigurationViewTest(LandscapeTest):
20
62
 
21
63
    helpers = [ConfigurationProxyHelper]
210
252
        self.assertEqual("foo", dialog.hosted_account_name_entry.get_text())
211
253
        self.assertEqual("bar", dialog.hosted_password_entry.get_text())
212
254
 
 
255
    def test_check_local_landscape_host_name_entry_ok(self):
 
256
        """
 
257
        Test that L{check_local_landscape_host_name_entry} returns L{True} when
 
258
        the input is a valid host name.
 
259
        """
 
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())
 
264
 
 
265
    def test_check_local_landscape_host_name_entry_ok_not_recorded(self):
 
266
        """
 
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
 
269
        valid host name.
 
270
        """
 
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))
 
276
 
 
277
    def test_check_local_landscape_host_name_entry_bad_host_name(self):
 
278
        """
 
279
        Test that L{check_local_landscape_host_name_entry} returns L{False}
 
280
        when the input is not a valid host name.
 
281
        """
 
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())
 
286
 
 
287
    def test_check_local_landscape_host_name_entry_bad_recorded(self):
 
288
        """
 
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
 
291
        a valid host name.
 
292
        """
 
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))
 
298
 
 
299
    def test_check_local_landscape_host_name_entry_bad_error_type(self):
 
300
        """
 
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.
 
304
        """
 
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)
 
311
 
 
312
    def test_check_local_landscape_host_name_entry_unicode_in_host_name(self):
 
313
        """
 
314
        Test that L{check_local_landscape_host_name_entry} returns L{False}
 
315
        when the input contains Unicode.
 
316
        """
 
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())
 
321
 
 
322
    def test_check_local_landscape_host_name_entry_unicode_recorded(self):
 
323
        """
 
324
        Test that L{check_local_landscape_host_name_entry} does add the
 
325
        entry to L{ClientSettingsDialog._errored_entries} when the input
 
326
        contains Unicode.
 
327
        """
 
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))
 
333
 
 
334
    def test_check_local_landscape_host_name_entry_unicode_error_type(self):
 
335
        """
 
336
        Test that L{check_local_landscape_host_name_entry} adds the correct
 
337
        error type to L{ClientSettingsDialog._validation_errors} when the input
 
338
        contains Unicode.
 
339
        """
 
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()
 
344
        self.assertEqual(
 
345
            set([dialog.INVALID_HOST_NAME, dialog.UNICODE_IN_ENTRY]),
 
346
            dialog._validation_errors)
 
347
 
 
348
    def test_check_entry_ok(self):
 
349
        """
 
350
        Test that we return L{True} when the text of a L{Gtk.Entry} is valid
 
351
        input.
 
352
        """
 
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))
 
359
 
 
360
    def test_check_entry_doesnt_record_entry_when_ok(self):
 
361
        """
 
362
        Test that, when the text of a L{Gtk.Entry} is valid nothing is added to
 
363
        L{ClientSettingsDialog._errored_entries}.
 
364
        """
 
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))
 
372
 
 
373
    def test_check_entry_non_ascii(self):
 
374
        """
 
375
        Test that we return L{False} when the text of a L{Gtk.Entry} contains
 
376
        Unicode input.
 
377
        """
 
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))
 
384
 
 
385
    def test_check_entry_records_entry_when_non_ascii(self):
 
386
        """
 
387
        Test that, when the text of a L{Gtk.Entry} contains Unicode it is
 
388
        added to L{ClientSettingsDialog._errored_entries}.
 
389
        """
 
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))
 
397
 
 
398
    def test_dismiss_validation_errors_local(self):
 
399
        """
 
400
        Test that dismissing the validation errors tidies up indicators that
 
401
        have been set against local settings.
 
402
        """
 
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))
 
421
        self.assertNotEqual(
 
422
            Gtk.STOCK_DIALOG_WARNING,
 
423
            entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
 
424
        self.assertNotEqual(
 
425
            Gtk.STOCK_DIALOG_WARNING,
 
426
            entry2.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
 
427
 
 
428
    def test_dismiss_validation_errors_hosted(self):
 
429
        """
 
430
        Test that dismissing the validation errors tidies up indicators that
 
431
        have been set against hosted fields.
 
432
        """
 
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))
 
448
        self.assertNotEqual(
 
449
            Gtk.STOCK_DIALOG_WARNING,
 
450
            entry1.get_icon_stock(Gtk.EntryIconPosition.PRIMARY))
 
451
 
 
452
    def test_validity_check_disabled(self):
 
453
        """
 
454
        Test that the L{validity_check} returns True when we disable landscape
 
455
        client.
 
456
        """
 
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())
 
462
 
 
463
    def test_validity_check_hosted(self):
 
464
        """
 
465
        Test that the L{validity_check} returns True when the hosted fields are
 
466
        valid.
 
467
        """
 
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())
 
475
 
 
476
    def test_validity_check_hosted_unicode(self):
 
477
        """
 
478
        Test that the L{validity_check} returns False when the hosted fields
 
479
        contain Unicode.
 
480
        """
 
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())
 
487
 
 
488
    def test_validity_check_local_ok(self):
 
489
        """
 
490
        Test that the L{validity_check} returns True when the local fields
 
491
        are valid.
 
492
        """
 
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())
 
500
 
 
501
    def test_validity_check_local_sanitisable(self):
 
502
        """
 
503
        Test that the L{validity_check} returns True when the local fields
 
504
        are valid after sanitation.
 
505
        """
 
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())
 
515
 
 
516
    def test_validity_check_local_invalid_host_name(self):
 
517
        """
 
518
        Test that the L{validity_check} returns False when the host name is
 
519
        invalid.
 
520
        """
 
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())
 
527
 
 
528
    def test_validity_check_local_unicode(self):
 
529
        """
 
530
        Test that the L{validity_check} returns False when the host name
 
531
        contains Unicode.
 
532
        """
 
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())
 
539
 
213
540
    if not got_gobject_introspection:
214
541
        skip = gobject_skip_message
215
542