def test_programatically_add_row(self):
        """test appending different sized rows programatically"""
        #create some records
        self.db.put_record(
            Record({
                "key1_1": "val1_1",
                "key1_2": "val1_2",
                "key1_3": "val1_3",
                "record_type": self.record_type
            }))
        self.db.put_record(
            Record({
                "key1_1": "val2_1",
                "key1_2": "val2_2",
                "key1_3": "val2_3",
                "record_type": self.record_type
            }))

        #create a test widget with test database values
        cw = CouchGrid(self.dbname, record_type=self.record_type)

        #allow editing
        cw.append_row({"key1_1": "boo", "key1_2": "ray"})

        #make sure there are three columns and two rows
        self.assertEqual(cw.get_model().get_n_columns(), 4)
        self.assertEqual(len(cw.get_model()), 3)
 def test_headings_no_stored_records(self):
     record_type = "a_new_record_type"
     dicts = [{"key1": "val1"}, {"key1": "val2"}]
     cw = CouchGrid(self.dbname,
                    record_type=record_type,
                    dictionaries=dicts)
     self.assertEqual(len(cw.get_model()), 2)
     self.assertEqual(cw.get_model().get_n_columns(), 2)
    def test_no_headings_or_stored_records(self):
        """test when there is no defined headings and no stored records
        to infer headings from. Should raise a proper exception.
        """

        try:
            #create a test widget with test database values
            cw = CouchGrid(self.dbname)

            #set the record_type for the TreeView
            #it will not populate without this value being set
            cw.record_type = self.record_type

            #create a row with all four columns set
            cw.append_row(["val1", "val2", "val3", "val4"])

            #create a row with only the second column set
            cw.append_row(["", "val2"])

            #create an empty row (which will not be saved until the
            #user edits it)
            cw.append_row([])

            #if this all worked, there should be three rows in the model
            model = cw.get_model()

        #should be catching the following exception
        except RuntimeError, inst:
            self.assertEquals(
                inst.args[0].find("Cannot infer columns for CouchGrid"), 0)
    def test_new_rows_with_headings(self):
        """Test a simple creating a CouchGrid """

        #create a test widget with test database values
        cw = CouchGrid(self.dbname)

        #allow editing
        cw.editable = True

        #create headers/keys
        cw.keys = ["Key1", "Key2", "Key3", "Key4"]

        #set the record_type for the TreeView
        #it will not populate without this value being set
        cw.record_type = self.record_type

        #create a row with all four columns set
        cw.append_row({
            "Key1": "val1",
            "Key2": "val2",
            "Key2": "val3",
            "Key4": "val4"
        })

        #create a row with only the second column set
        cw.append_row({"Key1": "", "Key2": "val2"})

        #create an empty row (which will not be saved until the user edits it)
        cw.append_row({})

        #if this all worked, there should be three rows in the model
        model = cw.get_model()
        self.assertEqual(len(model), 3)
    def test_optional_args_no_stored_records(self):
        """Test a simple creating a CouchGrid """

        #create a test widget with test database values
        cw = CouchGrid(self.dbname,
                       record_type=self.record_type,
                       keys=["Key1", "Key2", "Key3", "Key4"])

        #create a row with all four columns set
        cw.append_row({
            "Key1": "val1",
            "Key2": "val2",
            "Key2": "val3",
            "Key4": "val4"
        })

        #create a row with only the second column set
        cw.append_row({"Key1": "", "Key2": "val2"})

        #create an empty row (which will not be saved until the user edits it)
        cw.append_row({})

        #if this all worked, there should be three rows in the model
        model = cw.get_model()
        self.assertEqual(len(model), 3)
 def test_single_col_from_database(self):
     #create some records
     self.db.put_record(
         Record({
             "key1_1": "val1_1",
             "key1_2": "val1_2",
             "key1_3": "val1_3",
             "record_type": self.record_type
         }))
     self.db.put_record(
         Record({
             "key1_1": "val2_1",
             "key1_2": "val2_2",
             "key1_3": "val2_3",
             "record_type": self.record_type
         }))
     #build the CouchGrid
     cw = CouchGrid(self.dbname)
     cw.keys = ["key1_1"]
     cw.record_type = self.record_type
     #make sure there are three columns and two rows
     self.assertEqual(cw.get_model().get_n_columns(), 2)
     self.assertEqual(len(cw.get_model()), 2)
    def test_optional_record_type_arg(self):
        """Test a simple creating a CouchGrid """
        #create some records
        self.db.put_record(
            Record({
                "key1_1": "val1_1",
                "key1_2": "val1_2",
                "key1_3": "val1_3",
                "record_type": self.record_type
            }))
        self.db.put_record(
            Record({
                "key1_1": "val1_1",
                "key1_2": "val2_2",
                "key1_3": "val2_3",
                "record_type": self.record_type
            }))

        #create a test widget with test database values
        cw = CouchGrid(self.dbname, record_type=self.record_type)

        #make sure there are three columns and two rows
        self.assertEqual(cw.get_model().get_n_columns(), 4)
        self.assertEqual(len(cw.get_model()), 2)