Erik Grinaker is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

erikg / Revelation

Revelation is a password manager for the GNOME desktop, released under the GNU GPL license. It stores all your accounts and passwords in a single, secure place, and gives you access to it through a user-friendly graphical interface.

Clone this repository (size: 2.1 MB): HTTPS / SSH
hg clone https://bitbucket.org/erikg/revelation
hg clone ssh://hg@bitbucket.org/erikg/revelation

Revelation / test / ui.py

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
#!/usr/bin/env python

#
# Revelation 0.4.0 - a password manager for GNOME 2
# http://oss.codepoet.no/revelation/
# $Id$
#
# Unit tests for ui module
#
#
# Copyright (c) 2003-2005 Erik Grinaker
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

import gobject, gtk, unittest

from revelation import config, data, entry, ui



class attrs(unittest.TestCase):
        "ui attributes"

        def test_entry_icons(self):
                "ui module has required entry stock icons"

                self.assertEquals(hasattr(ui, "STOCK_ENTRY_FOLDER"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_FOLDER_OPEN"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_CREDITCARD"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_CRYPTOKEY"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_DATABASE"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_DOOR"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_EMAIL"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_FTP"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_GENERIC"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_PHONE"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_SHELL"), True)
                self.assertEquals(hasattr(ui, "STOCK_ENTRY_WEBSITE"), True)


        def test_icon_sizes(self):
                "ui module has required icon sizes"

                self.assertEquals(hasattr(ui, "ICON_SIZE_DATAVIEW"), True)
                self.assertEquals(hasattr(ui, "ICON_SIZE_DROPDOWN"), True)
                self.assertEquals(hasattr(ui, "ICON_SIZE_LOGO"), True)
                self.assertEquals(hasattr(ui, "ICON_SIZE_TREEVIEW"), True)

                self.assertEquals(gtk.icon_size_lookup(ui.ICON_SIZE_DATAVIEW), (24, 24))
                self.assertEquals(gtk.icon_size_lookup(ui.ICON_SIZE_DROPDOWN), (18, 18))
                self.assertEquals(gtk.icon_size_lookup(ui.ICON_SIZE_LOGO), (32, 32))
                self.assertEquals(gtk.icon_size_lookup(ui.ICON_SIZE_TREEVIEW), (18, 18))



        def test_stock_items(self):
                "ui module has required stock items"

                self.assertEquals(hasattr(ui, "STOCK_ADD"), True)
                self.assertEquals(hasattr(ui, "STOCK_DISCARD"), True)
                self.assertEquals(hasattr(ui, "STOCK_EDIT"), True)
                self.assertEquals(hasattr(ui, "STOCK_EXPORT"), True)
                self.assertEquals(hasattr(ui, "STOCK_GENERATE"), True)
                self.assertEquals(hasattr(ui, "STOCK_GOTO"), True)
                self.assertEquals(hasattr(ui, "STOCK_IMPORT"), True)
                self.assertEquals(hasattr(ui, "STOCK_LOCK"), True)
                self.assertEquals(hasattr(ui, "STOCK_NEXT"), True)
                self.assertEquals(hasattr(ui, "STOCK_OVERWRITE"), True)
                self.assertEquals(hasattr(ui, "STOCK_PASSWORD_CHANGE"), True)
                self.assertEquals(hasattr(ui, "STOCK_PREVIOUS"), True)
                self.assertEquals(hasattr(ui, "STOCK_REMOVE"), True)
                self.assertEquals(hasattr(ui, "STOCK_REVELATION"), True)



class config_bind(unittest.TestCase):
        "config_bind()"

        def setUp(self):
                "sets up common facilities for the test"

                self.config = config.Config()


        def test_check(self):
                "config_bind() handles check items correctly"

                self.config.set("view/searchbar", True)

                # test initial state
                check = ui.CheckButton("Test")
                ui.config_bind(self.config, "view/searchbar", check)
                gtk_run()
                self.assertEquals(check.get_active(), True)

                # test config value change
                self.config.set("view/searchbar", False)
                gtk_run()
                self.assertEquals(check.get_active(), False)

                # test widget change
                check.set_active(True)
                gtk_run()
                self.assertEquals(self.config.get("view/searchbar"), True)


        def test_entry(self):
                "config_bind() handles entries correctly"

                self.config.set("file/autoload_file", "test123")

                # test initial state
                entry = ui.Entry()
                ui.config_bind(self.config, "file/autoload_file", entry)
                gtk_run()
                self.assertEquals(entry.get_text(), "test123")

                # test config value change
                self.config.set("file/autoload_file", "test again")
                gtk_run()
                self.assertEquals(entry.get_text(), "test again")

                # test widget change
                entry.set_text("")
                gtk_run()
                self.assertEquals(self.config.get("file/autoload_file"), "")


        def test_return(self):
                "config_bind() returns the id of the callback"

                check = ui.CheckButton("test")
                id = ui.config_bind(self.config, "view/searchbar", check)
                self.assertEquals(self.config.callbacks.has_key(id), True)


        def test_spin(self):
                "config_bind() handles spin entries correctly"

                self.config.set("view/pane-position", 500)

                # test initial state
                spin = ui.SpinEntry()
                ui.config_bind(self.config, "view/pane-position", spin)
                gtk_run()
                self.assertEquals(spin.get_value(), 500)

                # test config value change
                self.config.set("view/pane-position", 200)
                gtk_run()
                self.assertEquals(spin.get_value(), 200)

                # test widget change
                spin.set_value(300)
                gtk_run()
                self.assertEquals(self.config.get("view/pane-position"), 300)


        def test_unrealize(self):
                "config_bind() removes the callback when the widget is destroyed"

                check = ui.CheckButton()
                id = ui.config_bind(self.config, "view/searchbar", check)
                self.assertEquals(self.config.callbacks.has_key(id), True)

                hbox = ui.HBox()
                hbox.pack_start(check)
                hbox.destroy()
                gtk_run()

                self.assertEquals(self.config.callbacks.has_key(id), False)



class generate_field_display_widget(unittest.TestCase):
        "generate_field_display_widget()"

        def test_value(self):
                "generate_field_display_widget() sets field value on widget"

                for field in entry.FIELDLIST:
                        field = field()
                        field.value = "test123"

                        widget = ui.generate_field_display_widget(field)
                        self.assertEquals(widget.get_text(), "test123")


        def test_widgets(self):
                "generate_field_display_widget() generates correct widgets"

                for field in entry.FIELDLIST:
                        field = field()
                        widget = ui.generate_field_display_widget(field)

                        if field.datatype in ( entry.DATATYPE_EMAIL, entry.DATATYPE_URL ):
                                self.assertEquals(type(widget), ui.LinkButton)

                        elif field.datatype == entry.DATATYPE_PASSWORD:
                                self.assertEquals(type(widget), ui.PasswordLabel)

                        else:
                                self.assertEquals(type(widget), ui.Label)



class generate_field_edit_widget(unittest.TestCase):
        "generate_field_display_widget()"

        def test_value(self):
                "generate_field_edit_widget() sets the field value in the widget"

                for field in entry.FIELDLIST:
                        field = field()
                        field.value = "test123"

                        widget = ui.generate_field_edit_widget(field)

                        if type(widget) != ui.FileEntry:
                                self.assertEquals(widget.get_text(), "test123")


        def test_widgets(self):
                "generate_field_edit_widget() generates correct widgets"

                for field in entry.FIELDLIST:
                        field = field()
                        widget = ui.generate_field_edit_widget(field)

                        if type(field) == entry.PasswordField:
                                self.assertEquals(type(widget), ui.PasswordEntryGenerate)

                        elif type(field) == entry.UsernameField:
                                self.assertEquals(type(widget), ui.ComboBoxEntry)

                        elif field.datatype == entry.DATATYPE_FILE:
                                self.assertEquals(type(widget), ui.FileEntry)

                        elif field.datatype == entry.DATATYPE_PASSWORD:
                                self.assertEquals(type(widget), ui.PasswordEntry)

                        else:
                                self.assertEquals(type(widget), ui.Entry)



class Button(unittest.TestCase):
        "Button"

        def test_callback(self):
                "Button attaches callback from arg"

                global foo
                foo = False

                def cb(widget, data = None):
                        global foo
                        foo = True

                b = ui.Button("test", cb)
                b.clicked()
                gtk_run()

                self.assertEquals(foo, True)


        def test_label(self):
                "Button sets label text from arg"

                self.assertEquals(ui.Button("test123").get_label(), "test123")


        def test_stock(self):
                "Button uses stock items if given"

                self.assertEquals(ui.Button("test").get_use_stock(), True)


        def test_subclass(self):
                "Button is subclass of gtk.Button"

                self.assertEquals(isinstance(ui.Button("test"), gtk.Button), True)



class CheckButton(unittest.TestCase):
        "CheckButton"

        def test_subclass(self):
                "CheckButton is subclass of gtk.CheckButton"

                self.assertEquals(isinstance(ui.CheckButton(), gtk.CheckButton), True)



class ComboBoxEntry(unittest.TestCase):
        "ComboBoxEntry"

        def test_activates_default(self):
                "ComboBoxEntry activates default dialog response by default"

                self.assertEquals(ui.ComboBoxEntry().child.get_activates_default(), True)


        def test_completion(self):
                "ComboBoxEntry sets up an EntryCompletion"

                e = ui.ComboBoxEntry()
                self.assertEquals(e.completion.get_model() is e.model, True)
                self.assertEquals(e.child.get_completion() is e.completion, True)


        def test_model(self):
                "ComboBoxEntry sets up text liststore"

                e = ui.ComboBoxEntry()

                self.assertEquals(hasattr(e, "model"), True)
                self.assertEquals(e.model.get_n_columns(), 1)
                self.assertEquals(e.model.get_column_type(0), gobject.TYPE_STRING)
                self.assertEquals(e.get_text_column(), 0)


        def test_subclass(self):
                "ComboBoxEntry is subclass of gtk.ComboBoxEntry"

                self.assertEquals(isinstance(ui.ComboBoxEntry(), gtk.ComboBoxEntry), True)


        def test_values(self):
                "ComboBoxEntry takes values as arg"

                e = ui.ComboBoxEntry([ "a", "b", "c" ])

                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 0), 0), "a")
                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 1), 0), "b")
                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 2), 0), "c")



class ComboBoxEntry_get_text(unittest.TestCase):
        "ComboBoxEntry.get_text()"

        def test_text(self):
                "ComboBoxEntry.get_text() returns contents of child entry"

                e = ui.ComboBoxEntry("test123")
                self.assertEquals(e.get_text(), e.child.get_text())



class ComboBoxEntry_set_values(unittest.TestCase):
        "ComboBoxEntry.set_values()"

        def test_clear(self):
                "ComboBoxEntry.set_values() replaces existing values"

                e = ui.ComboBoxEntry()
                e.set_values([ "test1", "test2" ])
                e.set_values([ "a", "b", "c" ])

                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 0), 0), "a")
                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 1), 0), "b")
                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 2), 0), "c")


        def test_values(self):
                "ComboBoxEntry.set_values() sets dropdown values"

                e = ui.ComboBoxEntry()
                e.set_values([ "a", "b", "c" ])

                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 0), 0), "a")
                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 1), 0), "b")
                self.assertEquals(e.model.get_value(e.model.iter_nth_child(None, 2), 0), "c")



class ComboBoxEntry_set_text(unittest.TestCase):
        "ComboBoxEntry.set_text()"

        def test_none(self):
                "ComboBoxEntry.set_text() clears entry on None"

                e = ui.ComboBoxEntry()
                e.set_text("test123")
                e.set_text(None)
                self.assertEquals(e.get_text(), "")


        def test_text(self):
                "ComboBoxEntry.set_text() sets entry text"

                e = ui.ComboBoxEntry()
                e.set_text("test123")
                self.assertEquals(e.get_text(), "test123")



class DropDown(unittest.TestCase):
        "DropDown"

        def test_model(self):
                "DropDown model can store text, stock-icon and data"

                d = ui.DropDown()
                self.assertEquals(d.model.get_n_columns(), 3)
                self.assertEquals(d.model.get_column_type(0), gobject.TYPE_STRING)
                self.assertEquals(d.model.get_column_type(1), gobject.TYPE_STRING)
                self.assertEquals(d.model.get_column_type(2), gobject.TYPE_PYOBJECT)


        def test_subclass(self):
                "DropDown is subclass of gtk.ComboBox"

                self.assertEquals(isinstance(ui.DropDown(), gtk.ComboBox), True)



class DropDown_append_item(unittest.TestCase):
        "DropDown.append_item"

        def test_append(self):
                "DropDown.append_item() appends item to model"

                d = ui.DropDown()

                d.append_item("test")
                self.assertEquals(d.model.iter_n_children(None), 1)
                self.assertEquals(d.get_item(0), ( "test", None, None))

                d.append_item("test123")
                self.assertEquals(d.model.iter_n_children(None), 2)
                self.assertEquals(d.get_item(1), ( "test123", None, None))


        def test_data(self):
                "DropDown.append_item() stores all data"

                d = ui.DropDown()
                d.append_item("test", ui.STOCK_REVELATION, {} )
                self.assertEquals(d.get_item(0), ( "test", ui.STOCK_REVELATION, {} ))



class DropDown_delete_item(unittest.TestCase):
        "DropDown.delete_item()"

        def test_delete(self):
                "DropDown.delete_item() deletes item"

                d = ui.DropDown()
                d.append_item("test1")
                d.append_item("test2")
                d.append_item("test3")

                d.delete_item(1)
                self.assertEquals(d.get_item(0), ( "test1", None, None ))
                self.assertEquals(d.get_item(1), ( "test3", None, None ))
                self.assertEquals(d.model.iter_n_children(None), 2)



class DropDown_get_active_item(unittest.TestCase):
        "DropDown.get_active_item()"

        def test_active(self):
                "DropDown.get_active_item() returns data for the active item"

                d = ui.DropDown()
                d.append_item("test1")
                d.append_item("test2")
                d.append_item("test3")

                d.set_active(0)
                self.assertEquals(d.get_active_item(), ( "test1", None, None ))

                d.set_active(2)
                self.assertEquals(d.get_active_item(), ( "test3", None, None ))


        def test_data(self):
                "DropDown.get_active_item() returns all data"

                d = ui.DropDown()
                d.append_item("test", ui.STOCK_REVELATION, {})
                d.set_active(0)
                self.assertEquals(d.get_active_item(), ( "test", ui.STOCK_REVELATION, {} ))



class DropDown_get_item(unittest.TestCase):
        "DropDown.get_item()"

        def test_data(self):
                "DropDown.get_item() returns all data"

                d = ui.DropDown()
                d.append_item("test", ui.STOCK_REVELATION, {})
                self.assertEquals(d.get_item(0), ( "test", ui.STOCK_REVELATION, {} ))



class DropDown_insert_item(unittest.TestCase):
        "DropDown.insert_item()"

        def test_data(self):
                "DropDown.insert_item() stores all data"

                d = ui.DropDown()
                d.append_item("test1")
                d.insert_item(0, "test2", ui.STOCK_REVELATION, {})

                self.assertEquals(d.get_item(0), ( "test2", ui.STOCK_REVELATION, {} ))


        def test_position(self):
                "DropDown.insert_item() stores item at correct position"

                d = ui.DropDown()
                d.append_item("test1")
                d.append_item("test2")
                d.insert_item(1, "test3")

                self.assertEquals(d.get_item(0), ( "test1", None, None ))
                self.assertEquals(d.get_item(1), ( "test3", None, None ))
                self.assertEquals(d.get_item(2), ( "test2", None, None ))



class Entry(unittest.TestCase):
        "Entry"

        def test_activates_default(self):
                "Entry activates default dialog response by default"

                self.assertEquals(ui.Entry().get_activates_default(), True)


        def test_subclass(self):
                "Entry is subclass of gtk.Entry"

                self.assertEquals(isinstance(ui.Entry(), gtk.Entry), True)


        def test_text(self):
                "Entry takes text as arg"

                self.assertEquals(ui.Entry("test123").get_text(), "test123")



class Entry_set_text(unittest.TestCase):
        "Entry.set_text()"

        def test_none(self):
                "Entry.set_text() blanks entry on None"

                e = ui.Entry("test")
                e.set_text(None)
                self.assertEquals(e.get_text(), "")


        def test_text(self):
                "Entry.set_text() sets text correctly"

                e = ui.Entry()
                e.set_text("test")
                self.assertEquals(e.get_text(), "test")



class EventBox(unittest.TestCase):
        "EventBox"

        def test_child(self):
                "EventBox takes child as argument"

                label = ui.Label("test")
                eventbox = ui.EventBox(label)
                self.assertEquals(eventbox.get_child() is label, True)


        def test_subclass(self):
                "EventBox is subclass of gtk.EventBox"

                self.assertEquals(isinstance(ui.EventBox(), gtk.EventBox), True)



class EntryDropDown(unittest.TestCase):
        "EntryDropDown"

        def test_data(self):
                "EntryDropDown stores correct data"

                d = ui.EntryDropDown()
                name, stock, e = d.get_item(0)
                self.assertEquals(e.typename, name)
                self.assertEquals(e.icon, stock)


        def test_entries(self):
                "EntryDropDown stores all entries"

                entries = entry.ENTRYLIST[:]
                d = ui.EntryDropDown()

                for index in range(d.model.iter_n_children(None)):
                        name, stock, e = d.get_item(index)
                        self.assertEquals(e in entries, True)
                        entries.remove(e)

                self.assertEquals(entries, [])


        def test_subclass(self):
                "EntryDropDown is subclass of DropDown"

                self.assertEquals(isinstance(ui.EntryDropDown(), ui.DropDown), True)



class EntryDropDown_get_active_type(unittest.TestCase):
        "EntryDropDown.get_active_type()"

        def test_active(self):
                "EntryDropDown.get_active_type() returns active type"

                d = ui.EntryDropDown()
                d.set_active(3)

                self.assertEquals(d.get_item(3)[2], d.get_active_type())



class EntryDropDown_set_active_type(unittest.TestCase):
        "EntryDropDown.set_active_type()"

        def test_active(self):
                "EntryDropDown.set_active_type() sets active type"

                d = ui.EntryDropDown()
                d.set_active_type(entry.GenericEntry)
                self.assertEquals(d.get_active_type(), entry.GenericEntry)



class FileEntry(unittest.TestCase):
        "FileEntry"

        def test_button(self):
                "FileEntry has Button as button attribute"

                self.assertEquals(isinstance(ui.FileEntry().button, ui.Button), True)


        def test_entry(self):
                "FileEntry has Entry as entry attribute"

                self.assertEquals(isinstance(ui.FileEntry().entry, ui.Entry), True)


        def test_file(self):
                "FileEntry takes file as argument"

                e = ui.FileEntry(None, "/bin/ls")
                self.assertEquals(e.get_filename(), "/bin/ls")


        def test_layout(self):
                "FileEntry is HBox with Entry and Button"

                e = ui.FileEntry()
                self.assertEquals(isinstance(e, ui.HBox), True)
                self.assertEquals(len(e.get_children()), 2)
                self.assertEquals(e.get_children()[0] is e.entry, True)
                self.assertEquals(e.get_children()[1] is e.button, True)


        def test_title(self):
                "FileEntry takes file selector title as argument"

                self.assertEquals(ui.FileEntry("test").title, "test")



class FileEntry_get_filename(unittest.TestCase):
        "FileEntry.get_filename()"

        def test_filename(self):
                "FileEntry.get_filename() returns entry contents"

                e = ui.FileEntry(None, "/bin/ls")
                self.assertEquals(e.get_filename(), "/bin/ls")



class FileEntry_get_text(unittest.TestCase):
        "FileEntry.get_text()"

        def test_filename(self):
                "FileEntry.get_text() returns entry contents"

                e = ui.FileEntry(None, "/bin/ls")
                self.assertEquals(e.get_text(), "/bin/ls")



class FileEntry_set_filename(unittest.TestCase):
        "FileEntry.set_filename()"

        def test_filename(self):
                "FileEntry.set_filename() sets filename in entry"

                e = ui.FileEntry()
                e.set_filename("/bin/ls")
                self.assertEquals(e.get_filename(), "/bin/ls")


        def test_normpath(self):
                "FileEntry.set_filename() applies io.file_normpath()"

                e = ui.FileEntry()
                e.set_filename("/home/../bin/./ls")
                self.assertEquals(e.get_filename(), "/bin/ls")



class FileEntry_set_text(unittest.TestCase):
        "FileEntry.set_text()"

        def test_text(self):
                "FileEntry.set_text() sets text in entry"

                e = ui.FileEntry()
                e.set_text("test")
                self.assertEquals(e.get_text(), "test")



class HBox(unittest.TestCase):
        "HBox"

        def test_children(self):
                "HBox accepts children as arguments"

                hbox = ui.HBox(ui.Label("a"), ui.Label("b"), ui.Label("c"))

                self.assertEquals(len(hbox.get_children()), 3)
                self.assertEquals(hbox.get_children()[0].get_text(), "a")
                self.assertEquals(hbox.get_children()[1].get_text(), "b")
                self.assertEquals(hbox.get_children()[2].get_text(), "c")


        def test_hig(self):
                "HBox conforms to the HIG"

                hbox = ui.HBox()
                self.assertEquals(hbox.get_spacing(), 6)
                self.assertEquals(hbox.get_border_width(), 0)


        def test_parent(self):
                "HBox is subclass of gtk.HBox"

                self.assertEquals(isinstance(ui.HBox(), gtk.HBox), True)



class HPaned(unittest.TestCase):
        "HPaned"

        def test_children(self):
                "HPaned accepts children as arguments"

                hpaned = ui.HPaned(ui.Label("a"), ui.Label("b"))

                self.assertEquals(hpaned.get_child1().get_text(), "a")
                self.assertEquals(hpaned.get_child2().get_text(), "b")


        def test_subclass(self):
                "HPaned is subclass of gtk.HPaned"

                self.assertEquals(isinstance(ui.HPaned(), gtk.HPaned), True)



class Image(unittest.TestCase):
        "Image"

        def test_stock(self):
                "Image takes stock and size as arguments"

                image = ui.Image(ui.STOCK_REVELATION, ui.ICON_SIZE_LOGO)
                self.assertEquals(image.get_stock(), ( ui.STOCK_REVELATION, ui.ICON_SIZE_LOGO ))


        def test_subclass(self):
                "Image is subclass of gtk.Image"

                self.assertEquals(isinstance(ui.Image(), gtk.Image), True)



class ImageLabel(unittest.TestCase):
        "ImageLabel"

        def setUp(self):
                "sets up common facilities"

                self.imagelabel = ui.ImageLabel("Test", ui.STOCK_REVELATION, ui.ICON_SIZE_LOGO)


        def test_hig(self):
                "ImageLabel conforms to the HIG"

                self.assertEquals(self.imagelabel.hbox.get_spacing(), 6)


        def test_image(self):
                "ImageLabel sets image correctly"

                self.assertEquals(self.imagelabel.image.get_stock(), ( ui.STOCK_REVELATION, ui.ICON_SIZE_LOGO ))


        def test_label(self):
                "ImageLabel sets label correctly"

                self.assertEquals(self.imagelabel.label.get_text(), "Test")



class ImageLabel_set_stock(unittest.TestCase):
        "ImageLabel.set_stock()"

        def test_stock(self):
                "ImageLabel.set_stock() sets image correctly"

                imagelabel = ui.ImageLabel("Test", ui.STOCK_REVELATION, ui.ICON_SIZE_LOGO)

                imagelabel.set_stock(ui.STOCK_ENTRY_FOLDER, ui.ICON_SIZE_DATAVIEW)
                self.assertEquals(imagelabel.image.get_stock(), ( ui.STOCK_ENTRY_FOLDER, ui.ICON_SIZE_DATAVIEW ))



class ImageLabel_set_text(unittest.TestCase):
        "ImageLabel.set_text()"

        def test_text(self):
                "ImageLabel.set_text() sets text correctly"

                imagelabel = ui.ImageLabel("Test", ui.STOCK_REVELATION, ui.ICON_SIZE_LOGO)

                imagelabel.set_text("test123")
                self.assertEquals(imagelabel.label.get_text(), "test123")



class ImageMenuItem(unittest.TestCase):
        "ImageMenuItem"

        def test_image(self):
                "ImageMenuItem makes image available as image attribute"

                i = ui.ImageMenuItem(gtk.STOCK_ADD, "test")
                self.assertEquals(isinstance(i.image, gtk.Image), True)
                self.assertEquals(i.image is i.get_children()[1], True)


        def test_label(self):
                "ImageMenuItem makes label available as label attribute"

                i = ui.ImageMenuItem(gtk.STOCK_ADD, "test")
                self.assertEquals(isinstance(i.label, gtk.Label), True)
                self.assertEquals(i.label is i.get_children()[0], True)


        def test_stock(self):
                "ImageMenuItem sets image stock from arg"

                i = ui.ImageMenuItem(gtk.STOCK_ADD)
                self.assertEquals(i.image.get_stock(), ( gtk.STOCK_ADD, gtk.ICON_SIZE_MENU ))


        def test_subclass(self):
                "ImageMenuItem is subclass of gtk.ImageMenuItem"

                self.assertEquals(isinstance(ui.ImageMenuItem(gtk.STOCK_ADD), gtk.ImageMenuItem), True)


        def test_text(self):
                "ImageMenuItem sets label text from arg"

                i = ui.ImageMenuItem(gtk.STOCK_ADD, "test")
                self.assertEquals(i.label.get_text(), "test")



class ImageMenuItem_set_stock(unittest.TestCase):
        "ImageMenuItem.set_stock()"

        def test_stock(self):
                "ImageMenuItem.set_stock() sets the stock image"

                i = ui.ImageMenuItem(gtk.STOCK_ADD)
                i.set_stock(gtk.STOCK_REMOVE)
                self.assertEquals(i.image.get_stock(), ( gtk.STOCK_REMOVE, gtk.ICON_SIZE_MENU ))



class ImageMenuItem_set_text(unittest.TestCase):
        "ImageMenuItem.set_text()"

        def test_text(self):
                "ImageMenuItem.set_text() sets label text"

                i = ui.ImageMenuItem(gtk.STOCK_ADD)
                i.set_text("test123")
                self.assertEquals(i.label.get_text(), "test123")



class InputSection(unittest.TestCase):
        "InputSection"

        def test_description(self):
                "InputSection creates description label correctly"

                sect = ui.InputSection("Title", "Description")
                self.assertEquals(len(sect.get_children()), 2)
                self.assertEquals(type(sect.get_children()[1]), ui.Label)
                self.assertEquals(sect.get_children()[1].get_text(), "Description")


        def test_hig(self):
                "InputSection conforms to the HIG"

                sect = ui.InputSection()
                self.assertEquals(sect.get_spacing(), 6)


        def test_sizegroup(self):
                "InputSection uses sizegroup correctly"

                sizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
                sect = ui.InputSection("Title", "Description", sizegroup)
                self.assertEquals(sect.sizegroup is sizegroup, True)


        def test_sizegroup_default(self):
                "InputSection sets up horizontal sizegroup by default"

                sect = ui.InputSection()
                self.assertEquals(type(sect.sizegroup), gtk.SizeGroup)
                self.assertEquals(sect.sizegroup.get_mode(), gtk.SIZE_GROUP_HORIZONTAL)


        def test_subclass(self):
                "InputSection is subclass of gtk.VBox"

                self.assertEquals(isinstance(ui.InputSection(), gtk.VBox), True)


        def test_title(self):
                "InputSection creates title label correctly"

                sect = ui.InputSection("Title")
                self.assertEquals(len(sect.get_children()), 1)
                self.assertEquals(type(sect.get_children()[0]), ui.Label)
                self.assertEquals(sect.get_children()[0].get_text(), "Title")



class InputSection_append_widget(unittest.TestCase):
        "InputSection.append_widget()"

        def test_hig(self):
                "InputSection.append_widget() conforms to the HIG"

                sect = ui.InputSection()
                sect.append_widget("Test", ui.Entry())

                row = sect.get_children()[0]
                self.assertEquals(row.get_spacing(), 12)
                self.assertEquals(row.get_children()[0].get_text(), "Test:")


        def test_label_none(self):
                "InputSection.append_widget() expands widget to max width on None label"

                sect = ui.InputSection()
                entry = ui.Entry()
                sect.append_widget(None, entry)

                row = sect.get_children()[0]
                self.assertEquals(len(row.get_children()), 1)
                self.assertEquals(row.get_children()[0] is entry, True)


        def test_pair(self):
                "InputSection.append_widget() generates a label/widget pair"

                sect = ui.InputSection()
                entry = ui.Entry()
                sect.append_widget("Test", entry)

                row = sect.get_children()[0]
                self.assertEquals(type(row.get_children()[0]), ui.Label)
                self.assertEquals(row.get_children()[0].get_text(), "Test:")

                self.assertEquals(row.get_children()[1] is entry, True)



class InputSection_clear(unittest.TestCase):
        "InputSection.clear()"

        def test_clear(self):
                "InputSection.clear() clears the section"

                sect = ui.InputSection()
                sect.append_widget("Test", ui.Entry())
                sect.append_widget("Test2", ui.Entry())
                self.assertEquals(len(sect.get_children()), 2)

                sect.clear()
                self.assertEquals(len(sect.get_children()), 0)


        def test_title_description(self):
                "InputSection.clear() preserves title and description labels"

                sect = ui.InputSection("Title", "Description")
                sect.append_widget("Test", ui.Entry())
                sect.append_widget("Test2", ui.Entry())
                self.assertEquals(len(sect.get_children()), 4)

                sect.clear()
                self.assertEquals(len(sect.get_children()), 2)
                self.assertEquals(sect.get_children()[0].get_text(), "Title")
                self.assertEquals(sect.get_children()[1].get_text(), "Description")



class Label(unittest.TestCase):
        "Label"

        def test_subclass(self):
                "Label is subclass of gtk.Label"

                self.assertEquals(isinstance(ui.Label(), gtk.Label), True)


        def test_justify(self):
                "Label sets justify from args"

                self.assertEquals(ui.Label("Test", gtk.JUSTIFY_LEFT).get_justify(), gtk.JUSTIFY_LEFT)
                self.assertEquals(ui.Label("Test", gtk.JUSTIFY_CENTER).get_justify(), gtk.JUSTIFY_CENTER)
                self.assertEquals(ui.Label("Test", gtk.JUSTIFY_RIGHT).get_justify(), gtk.JUSTIFY_RIGHT)


        def test_justify_alignment(self):
                "Label justify argument affects label alignment as well"

                self.assertEquals(ui.Label("Test", gtk.JUSTIFY_LEFT).get_alignment()[0], 0)
                self.assertEquals(ui.Label("Test", gtk.JUSTIFY_CENTER).get_alignment()[0], 0.5)
                self.assertEquals(ui.Label("Test", gtk.JUSTIFY_RIGHT).get_alignment()[0], 1)


        def test_line_wrap(self):
                "Label enables line-wrapping by default"

                self.assertEquals(ui.Label().get_line_wrap(), True)


        def test_markup(self):
                "Label enables markup by default"

                self.assertEquals(ui.Label().get_use_markup(), True)
                self.assertEquals(ui.Label("<span weight=\"bold\">Test</span>").get_text(), "Test")


        def test_text(self):
                "Label sets text correctly from args"

                self.assertEquals(ui.Label("Test").get_text(), "Test")


        def test_text_none(self):
                "Label has no text when given None as text"

                self.assertEquals(ui.Label(None).get_text(), "")



class Label_set_text(unittest.TestCase):
        "Label.set_text()"

        def test_markup(self):
                "Label.set_text() handles markup"

                label = ui.Label()
                label.set_text("<span weight=\"bold\">test</span>")
                self.assertEquals(label.get_text(), "test")


        def test_none(self):
                "Label.set_text() clears label contents when given None"

                label = ui.Label("Test")
                label.set_text(None)
                self.assertEquals(label.get_text(), "")


        def test_text(self):
                "Label.set_text() sets text correctly"

                label = ui.Label("Test")
                label.set_text("test123")
                self.assertEquals(label.get_text(), "test123")



class Notebook(unittest.TestCase):
        "Notebook"

        def test_subclass(self):
                "Notebook is subclass of gtk.Notebook"

                self.assertEquals(isinstance(ui.Notebook(), gtk.Notebook), True)



class Notebook_create_page(unittest.TestCase):
        "Notebook.create_page()"

        def test_create(self):
                "Notebook.create_page() creates a notebook page"

                notebook = ui.Notebook()
                notebook.create_page("test1")
                notebook.create_page("test2")

                self.assertEquals(notebook.get_n_pages(), 2)


        def test_label(self):
                "Notebook.create_page() creates a tab label for the page"

                notebook = ui.Notebook()
                page = notebook.create_page("test")
                self.assertEquals(notebook.get_tab_label(page).get_text(), "test")


        def test_return(self):
                "Notebook.create_page() returns the created page"

                notebook = ui.Notebook()
                page = notebook.create_page("test")

                self.assertEquals(type(page), ui.NotebookPage)



class NotebookPage(unittest.TestCase):
        "NotebookPage"

        def test_hig(self):
                "NotebookPage conforms to the HIG"

                page = ui.NotebookPage()
                self.assertEquals(page.get_spacing(), 18)
                self.assertEquals(page.get_border_width(), 12)


        def test_subclass(self):
                "NotebookPage is subclass of ui.VBox"

                self.assertEquals(isinstance(ui.NotebookPage(), ui.VBox), True)



class NotebookPage_add_section(unittest.TestCase):
        "NotebookPage.add_section()"

        def test_create(self):
                "NotebookPage.add_section() adds an InputSection"

                page = ui.NotebookPage()
                page.add_section("Test")

                self.assertEquals(len(page.get_children()), 1)
                self.assertEquals(type(page.get_children()[0]), ui.InputSection)


        def test_return(self):
                "NotebookPage.add_section() returns InputSection"

                page = ui.NotebookPage()
                section = page.add_section("Test")

                self.assertEquals(type(section), ui.InputSection)
                self.assertEquals(section is page.get_children()[0], True)


        def test_sizegroup(self):
                "NotebookPage.add_section() uses common sizegroup for all sections"

                page = ui.NotebookPage()
                sect1 = page.add_section("Test1")
                sect2 = page.add_section("Test2")

                self.assertEquals(sect1.sizegroup is page.sizegroup, True)
                self.assertEquals(sect2.sizegroup is page.sizegroup, True)



class PasswordEntry(unittest.TestCase):
        "PasswordEntry"

        def test_config(self):
                "PasswordEntry sets visibility based on config value"

                c = config.Config()
                c.set("view/passwords", False)

                e = ui.PasswordEntry(c)
                gtk_run()
                self.assertEquals(e.get_visibility(), False)

                c.set("view/passwords", True)
                gtk_run()
                self.assertEquals(e.get_visibility(), True)


        def test_config_none(self):
                "PasswordEntry accepts None as config"

                ui.PasswordEntry(None)


        def test_password(self):
                "PasswordEntry takes password as arg"

                self.assertEquals(ui.PasswordEntry(None, "test123").get_text(), "test123")


        def test_subclass(self):
                "PasswordEntry is subclass of Entry"

                self.assertEquals(isinstance(ui.PasswordEntry(), ui.Entry), True)



class PasswordEntryGenerate(unittest.TestCase):
        "PasswordEntryGenerate"

        def test_button(self):
                "PasswordEntryGenerate has button attribute"

                self.assertEquals(isinstance(ui.PasswordEntryGenerate(config.Config()).button, ui.Button), True)


        def test_entry(self):
                "PasswordEntryGenerate has child PasswordEntry as entry attribute"

                self.assertEquals(isinstance(ui.PasswordEntryGenerate(config.Config()).entry, ui.PasswordEntry), True)


        def test_generate(self):
                "PasswordEntryGenerate generates password on button click"

                e = ui.PasswordEntryGenerate(config.Config())
                e.button.clicked()
                gtk_run()
                self.assertNotEqual(e.entry.get_text(), "")


        def test_layout(self):
                "PasswordEntryGenerate has entry and button as children"

                e = ui.PasswordEntryGenerate(config.Config())
                self.assertEquals(len(e.get_children()), 2)
                self.assertEquals(e.get_children()[0] is e.entry, True)
                self.assertEquals(e.get_children()[1] is e.button, True)


        def test_password(self):
                "PasswordEntryGenerate takes password as arg"

                self.assertEquals(ui.PasswordEntryGenerate(config.Config(), "test123").entry.get_text(), "test123")



class PasswordEntryGenerate_generate(unittest.TestCase):
        "PasswordEntryGenerate.generate()"

        def test_generate(self):
                "PasswordEntryGenerate.generates() generates password in entry"

                e = ui.PasswordEntryGenerate(config.Config())
                e.generate()
                self.assertNotEqual(e.entry.get_text(), "")



class PasswordEntryGenerate_get_text(unittest.TestCase):
        "PasswordEntryGenerate.get_text()"

        def test_text(self):
                "PasswordEntryGenerate.get_text() returns entry contents"

                self.assertEquals(ui.PasswordEntryGenerate(config.Config(), "test123").get_text(), "test123")



class PasswordEntryGenerate_set_text(unittest.TestCase):
        "PasswordEntryGenerate.set_text()"

        def test_text(self):
                "PasswordEntryGenerate.set_text() sets entry contents"

                e = ui.PasswordEntryGenerate(config.Config())
                e.set_text("test123")
                self.assertEquals(e.get_text(), "test123")



class PasswordLabel(unittest.TestCase):
        "PasswordLabel"

        def test_config(self):
                "PasswordLabel follows the view/passwords setting"

                c = config.Config()
                c.set("view/passwords", True)
                gtk_run()

                label = ui.PasswordLabel("Test123", c)
                self.assertEquals(label.get_text(), "Test123")

                c.set("view/passwords", False)
                gtk_run()
                self.assertEquals(label.get_text(), "******")

                keep_timeout = False
                gtk_run()


        def test_password(self):
                "PasswordLabel sets password from password arg"

                label = ui.PasswordLabel("test123")
                self.assertEquals(label.get_text(), "test123")
                self.assertEquals(label.password, "test123")


        def test_selectable(self):
                "PasswordLabel has selectable text"

                self.assertEquals(ui.PasswordLabel("test").get_selectable(), True)


        def test_subclass(self):
                "PasswordLabel is subclass of Label"

                self.assertEquals(isinstance(ui.PasswordLabel(), ui.Label), True)



class PasswordLabel_show_password(unittest.TestCase):
        "PasswordLabel.show_password()"

        def test_show(self):
                "PasswordLabel.show_password() works as expected"

                label = ui.PasswordLabel("test123")

                label.show_password(True)
                self.assertEquals(label.get_text(), "test123")

                label.show_password(False)
                self.assertEquals(label.get_text(), "******")



class ScrolledWindow(unittest.TestCase):
        "ScrolledWindow"

        def test_content(self):
                "ScrolledWindow sets contents from argument"

                tree = ui.TreeView(gtk.TreeStore(str))
                s = ui.ScrolledWindow(tree)

                self.assertEquals(s.get_child() is tree, True)


        def test_policy(self):
                "ScrolledWindow uses automatic scrollbar display by default"

                s = ui.ScrolledWindow()
                self.assertEquals(s.get_policy(), ( gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC ))


        def test_subclass(self):
                "ScrolledWindow is subclass of gtk.ScrolledWindow"

                self.assertEquals(isinstance(ui.ScrolledWindow(), gtk.ScrolledWindow), True)



class SpinEntry(unittest.TestCase):
        "SpinEntry"

        def test_increments(self):
                "SpinEntry uses 1 and 5 as increments"

                self.assertEquals(ui.SpinEntry().get_increments(), (1, 5))


        def test_numeric(self):
                "SpinEntry is numeric only"

                self.assertEquals(ui.SpinEntry().get_numeric(), True)


        def test_subclass(self):
                "SpinEntry is subclass of gtk.SpinButton"

                self.assertEquals(isinstance(ui.SpinEntry(), gtk.SpinButton), True)



class TextView(unittest.TestCase):
        "TextView"

        def test_buffer(self):
                "TextView takes buffer as argument"

                buffer = gtk.TextBuffer()
                buffer.set_text("test123")
                self.assertEquals(ui.TextView(buffer).get_buffer() is buffer, True)


        def test_cursor(self):
                "TextView has hidden cursor by default"

                self.assertEquals(ui.TextView().get_cursor_visible(), False)


        def test_editable(self):
                "TextView is not editable by default"

                self.assertEquals(ui.TextView().get_editable(), False)


        def test_font(self):
                "TextView uses Monospace font by default"

                # TODO fix this
                #self.assertEquals(ui.TextView().get_pango_context().get_font_description().get_family(), "Monospace")
                pass


        def test_subclass(self):
                "TextView is subclass of gtk.TextView"

                self.assertEquals(isinstance(ui.TextView(), gtk.TextView), True)


        def test_text(self):
                "TextView takes text contents as argument"

                t = ui.TextView(None, "test123")
                b = t.get_buffer()
                self.assertEquals(b.get_text(b.get_start_iter(), b.get_end_iter()), "test123")


        def test_wrap(self):
                "TextView doesn't wrap by default"

                self.assertEquals(ui.TextView().get_wrap_mode(), gtk.WRAP_NONE)



# TODO fix tests for internal callbacks (keyboard handling, drag/drop etc)
class TreeView(unittest.TestCase):
        "TreeView"

        def test_headers_visible(self):
                "TreeView disables tree headers by default"

                self.assertEquals(ui.TreeView(data.EntryStore()).get_headers_visible(), False)


        def test_selection(self):
                "TreeView makes selection available through selection attribute"

                t = ui.TreeView(data.EntryStore())
                self.assertEquals(t.selection is t.get_selection(), True)


        def test_subclass(self):
                "TreeView is subclass of gtk.TreeView"

                self.assertEquals(isinstance(ui.TreeView(data.EntryStore()), gtk.TreeView), True)



class TreeView_collapse_row(unittest.TestCase):
        "TreeView.collapse_row()"

        def test_collapse(self):
                "TreeView.collapse_row() collapses row"

                e = data.EntryStore()
                fiter = e.add_entry(entry.FolderEntry())
                iter = e.add_entry(entry.GenericEntry(), fiter)

                t = ui.TreeView(e)
                t.expand_row(fiter)
                t.collapse_row(fiter)

                self.assertEquals(t.row_expanded(( 0, )), False)


        def test_iter(self):
                "TreeView.collapse_row() takes iter instead of path"

                e = data.EntryStore()
                iter = e.add_entry(entry.GenericEntry())

                t = ui.TreeView(e)
                t.collapse_row(iter)
                self.assertRaises(TypeError, t.collapse_row, ( 0, ))



class Toolbar(unittest.TestCase):
        "Toolbar"

        def test_subclass(self):
                "Toolbar is subclass of gtk.Toolbar"

                self.assertEquals(isinstance(ui.Toolbar(), gtk.Toolbar), True)



class Toolbar_append_widget(unittest.TestCase):
        "Toolbar.append_widget()"

        def test_append(self):
                "Toolbar.append_widget() appends a widget"

                label = ui.Label("test")
                toolbar = ui.Toolbar()
                toolbar.append_widget(label)

                self.assertEquals(len(toolbar.get_children()), 1)
                self.assertEquals(toolbar.get_children()[0].get_child() is label, True)



class VBox(unittest.TestCase):
        "VBox"

        def test_children(self):
                "VBox accepts children as arguments"

                vbox = ui.VBox(ui.Label("a"), ui.Label("b"), ui.Label("c"))

                self.assertEquals(len(vbox.get_children()), 3)
                self.assertEquals(vbox.get_children()[0].get_text(), "a")
                self.assertEquals(vbox.get_children()[1].get_text(), "b")
                self.assertEquals(vbox.get_children()[2].get_text(), "c")


        def test_hig(self):
                "VBox conforms to the HIG"

                vbox = ui.VBox()
                self.assertEquals(vbox.get_spacing(), 6)
                self.assertEquals(vbox.get_border_width(), 0)


        def test_subclass(self):
                "VBox is subclass of gtk.VBox"

                self.assertEquals(isinstance(ui.VBox(), gtk.VBox), True)



def gtk_run():
        while gtk.events_pending():
                gtk.main_iteration()



if __name__ == "__main__":
        unittest.main()