'Assert that the state of a *Count table is what it should be.
Example usage:
self.assertTableState(RealmCount, [\'property\', \'subgroup\', \'realm\'],
[[\'p1\', 4], [\'p2\', 10, self.alt_realm]])
table -- A *Count table.
arg_keys -- List of columns of <table>.
arg_values -- List of "rows" of <table>.
Each entry of arg_values (e.g. [\'p1\', 4]) represents a row of <table>.
The i\'th value of the entry corresponds to the i\'th arg_key, so e.g.
the first arg_values entry here corresponds to a row of RealmCount
with property=\'p1\' and subgroup=10.
Any columns not specified (in this case, every column of RealmCount
other than property and subgroup) are either set to default values,
or are ignored.
The function checks that every entry of arg_values matches exactly one
row of <table>, and that no additional rows exist. Note that this means
checking a table with duplicate rows is not supported.'

def assertTableState(self, table, arg_keys, arg_values):

    defaults = {'property': self.current_property, 'subgroup': None, 'end_time': self.TIME_ZERO, 'value': 1}
    for values in arg_values:
        kwargs = {}
        for i in range(len(values)):
            kwargs[arg_keys[i]] = values[i]
        for (key, value) in defaults.items():
            kwargs[key] = kwargs.get(key, value)
        if (table is not InstallationCount):
            if ('realm' not in kwargs):
                if ('user' in kwargs):
                    kwargs['realm'] = kwargs['user'].realm
                elif ('stream' in kwargs):
                    kwargs['realm'] = kwargs['stream'].realm
                else:
                    kwargs['realm'] = self.default_realm
        self.assertEqual(table.objects.filter(**kwargs).count(), 1)
    self.assertEqual(table.objects.count(), len(arg_values))
