Exemple #1
0
 def databases(self):
     """
     Returns: a list of :class:`tdclient.models.Database`
     """
     databases = self.api.list_databases()
     return [
         models.Database(self, db_name, **kwargs)
         for (db_name, kwargs) in databases.items()
     ]
Exemple #2
0
    def database(self, db_name):
        """
        Params:
            db_name (str): name of a database

        Returns: :class:`tdclient.models.Database`
        """
        databases = self.api.list_databases()
        for (name, kwargs) in databases.items():
            if name == db_name:
                return models.Database(self, name, **kwargs)
        raise api.NotFoundError("Database '%s' does not exist" % (db_name))
Exemple #3
0
def test_database():
    client = mock.MagicMock()
    database = models.Database(client,
                               "sample_datasets",
                               tables=["nasdaq", "www_access"],
                               count=12345,
                               created_at="created_at",
                               updated_at="updated_at",
                               org_name="org_name",
                               permission="administrator")
    assert database.org_name == "org_name"
    assert database.permission == "administrator"
    assert database.count == 12345
    assert database.name == "sample_datasets"
    assert database.tables() == ["nasdaq", "www_access"]
    assert database.created_at == "created_at"
    assert database.updated_at == "updated_at"
Exemple #4
0
def test_database_update_tables():
    client = mock.MagicMock()
    client.tables = mock.MagicMock(return_value=[
        models.Table(client, "sample_datasets", "foo", "type", "schema",
                     "count"),
        models.Table(client, "sample_datasets", "bar", "type", "schema",
                     "count"),
        models.Table(client, "sample_datasets", "baz", "type", "schema",
                     "count"),
    ])
    database = models.Database(client,
                               "sample_datasets",
                               tables=None,
                               count=12345,
                               created_at="created_at",
                               updated_at="updated_at",
                               org_name="org_name",
                               permission="administrator")
    tables = database.tables()
    assert [table.name for table in tables] == ["foo", "bar", "baz"]
    client.tables.assert_called_with("sample_datasets")