Skip to content

Commit

Permalink
Reformat with Black and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pbugnion committed Dec 31, 2019
1 parent b9ca7cd commit 738b4b6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 33 deletions.
59 changes: 39 additions & 20 deletions __tests__/src/api/databaseStructure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ namespace Fixtures {
tables: ['t1', 't2'],
views: ['v1', 'v2']
}
}
};

export const databaseWithoutViews: DatabaseObjects = {
tables: ['t1', 't2'],
views: []
}
};

export const successWithoutViewsResponseBody: DatabaseStructureResponse.Type = {
responseType: 'success',
responseData: {
tables: ['t1', 't2']
}
}
};

export const successWithViewsEmptyResponseBody: DatabaseStructureResponse.Type = {
responseType: 'success',
responseData: {
tables: ['t1', 't2'],
views: []
}
}
};

export const errorResponseBody = {
responseType: 'error',
Expand All @@ -57,9 +57,9 @@ namespace Fixtures {
};

export const mockServerWithResponse = (responseBody: Object) => {
const response: Response = new Response(JSON.stringify(responseBody))
return jest.fn(() => Promise.resolve(response))
}
const response: Response = new Response(JSON.stringify(responseBody));
return jest.fn(() => Promise.resolve(response));
};
}

describe('getDatabaseStructure', () => {
Expand All @@ -69,7 +69,9 @@ describe('getDatabaseStructure', () => {
];

it.each(testCases)('valid %#: %s', async (_, responseBody) => {
ServerConnection.makeRequest = Fixtures.mockServerWithResponse(responseBody)
ServerConnection.makeRequest = Fixtures.mockServerWithResponse(
responseBody
);

const result = await getDatabaseStructure('connectionUrl');
expect(result).toEqual(responseBody);
Expand All @@ -88,29 +90,46 @@ describe('getDatabaseStructure', () => {

const successTestCases: Array<Array<any>> = [
['with views', Fixtures.databaseWithViews, Fixtures.successResponseBody],
['no views', Fixtures.databaseWithoutViews, Fixtures.successWithoutViewsResponseBody],
['empty views', Fixtures.databaseWithoutViews, Fixtures.successWithViewsEmptyResponseBody]
]
it.each(successTestCases)('matching on success %#: %s', async (_, expected, responseBody) => {
ServerConnection.makeRequest = Fixtures.mockServerWithResponse(responseBody);
[
'no views',
Fixtures.databaseWithoutViews,
Fixtures.successWithoutViewsResponseBody
],
[
'empty views',
Fixtures.databaseWithoutViews,
Fixtures.successWithViewsEmptyResponseBody
]
];
it.each(successTestCases)(
'matching on success %#: %s',
async (_, expected, responseBody) => {
ServerConnection.makeRequest = Fixtures.mockServerWithResponse(
responseBody
);

const result = await getDatabaseStructure('connectionUrl');
const result = await getDatabaseStructure('connectionUrl');

const mockOnSuccess = jest.fn();
DatabaseStructureResponse.match(result, mockOnSuccess, jest.fn());
const mockOnSuccess = jest.fn();
DatabaseStructureResponse.match(result, mockOnSuccess, jest.fn());

expect(mockOnSuccess).toHaveBeenCalledWith(expected);
});
expect(mockOnSuccess).toHaveBeenCalledWith(expected);
}
);

it('matching on error', async () => {
ServerConnection.makeRequest = Fixtures.mockServerWithResponse(Fixtures.errorResponseBody);
ServerConnection.makeRequest = Fixtures.mockServerWithResponse(
Fixtures.errorResponseBody
);

const result = await getDatabaseStructure('connectionUrl');

const mockOnError = jest.fn();
DatabaseStructureResponse.match(result, jest.fn(), mockOnError);

expect(mockOnError).toHaveBeenCalledWith(Fixtures.errorResponseBody.responseData);
expect(mockOnError).toHaveBeenCalledWith(
Fixtures.errorResponseBody.responseData
);
});

it('bad http status code', async () => {
Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_sql/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_database_objects(self, connection_url):
inspector = inspect(engine)
database_objects = DatabaseObjects(
tables=inspector.get_table_names(),
views=inspector.get_view_names()
views=inspector.get_view_names(),
)
return database_objects

Expand Down
1 change: 0 additions & 1 deletion jupyterlab_sql/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from collections import namedtuple


Expand Down
2 changes: 1 addition & 1 deletion jupyterlab_sql/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def success_no_rows():
def success_with_database_objects(database_objects):
response_data = {
"tables": database_objects.tables,
"views": database_objects.views
"views": database_objects.views,
}
response = {"responseType": "success", "responseData": response_data}
return response
10 changes: 5 additions & 5 deletions jupyterlab_sql/tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


def test_success_with_database_objects():
database_objects = DatabaseObjects(
tables=["t1", "t2"],
views=["v1", "v2"]
)
database_objects = DatabaseObjects(tables=["t1", "t2"], views=["v1", "v2"])
response = success_with_database_objects(database_objects)
expected = {"responseType": "success", "responseData": {"tables": ["t1", "t2"], "views": ["v1", "v2"]}}
expected = {
"responseType": "success",
"responseData": {"tables": ["t1", "t2"], "views": ["v1", "v2"]},
}
assert response == expected
11 changes: 6 additions & 5 deletions src/api/databaseStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export async function getDatabaseStructure(

export interface DatabaseObjects {
tables: Array<string>;
views: Array<string>
};
views: Array<string>;
}

export namespace DatabaseStructureResponse {
export type Type = ErrorResponse | SuccessResponse;
Expand All @@ -38,7 +38,7 @@ export namespace DatabaseStructureResponse {

type SuccessResponseData = {
tables: Array<string>;
views?: Array<string>
views?: Array<string>;
};

type ErrorResponseData = {
Expand Down Expand Up @@ -75,8 +75,9 @@ export namespace DatabaseStructureResponse {
// Remove in versions 4.x.
const views = responseData.views || [];
const databaseObjects: DatabaseObjects = {
tables, views
}
tables,
views
};
return onSuccess(databaseObjects);
}
}
Expand Down

0 comments on commit 738b4b6

Please sign in to comment.