Skip to content
Snippets Groups Projects
Verified Commit 1b76873f authored by Martin Weise's avatar Martin Weise
Browse files
parent 673132ef
No related branches found
No related tags found
2 merge requests!374Bumped version of DBRepo,!373Bumped version of DBRepo
...@@ -65,6 +65,8 @@ public class ViewDto extends CacheableDto { ...@@ -65,6 +65,8 @@ public class ViewDto extends CacheableDto {
@Schema(example = "7de03e818900b6ea6d58ad0306d4a741d658c6df3d1964e89ed2395d8c7e7916") @Schema(example = "7de03e818900b6ea6d58ad0306d4a741d658c6df3d1964e89ed2395d8c7e7916")
private String queryHash; private String queryHash;
@ToString.Exclude
@EqualsAndHashCode.Exclude
private DatabaseDto database; private DatabaseDto database;
@NotNull @NotNull
......
...@@ -107,6 +107,8 @@ public class TableDto extends CacheableDto { ...@@ -107,6 +107,8 @@ public class TableDto extends CacheableDto {
@NotNull @NotNull
private List<ColumnDto> columns; private List<ColumnDto> columns;
@ToString.Exclude
@EqualsAndHashCode.Exclude
private DatabaseDto database; private DatabaseDto database;
@NotNull @NotNull
......
...@@ -536,6 +536,8 @@ public interface MetadataMapper { ...@@ -536,6 +536,8 @@ public interface MetadataMapper {
} }
default TableDto tableToTableDto(Table data) { default TableDto tableToTableDto(Table data) {
data.getDatabase()
.setTables(null);
final TableDto table = TableDto.builder() final TableDto table = TableDto.builder()
.id(data.getId()) .id(data.getId())
.name(data.getName()) .name(data.getName())
...@@ -548,6 +550,7 @@ public interface MetadataMapper { ...@@ -548,6 +550,7 @@ public interface MetadataMapper {
.description(data.getDescription()) .description(data.getDescription())
.identifiers(new LinkedList<>()) .identifiers(new LinkedList<>())
.columns(new LinkedList<>()) .columns(new LinkedList<>())
.database(databaseToDatabaseDto(data.getDatabase()))
.constraints(constraintsToConstraintsDto(data.getConstraints())) .constraints(constraintsToConstraintsDto(data.getConstraints()))
.build(); .build();
if (data.getIdentifiers() != null) { if (data.getIdentifiers() != null) {
...@@ -833,6 +836,9 @@ public interface MetadataMapper { ...@@ -833,6 +836,9 @@ public interface MetadataMapper {
.trim(); .trim();
} }
@Mappings({
@Mapping(target = "database.views", ignore = true)
})
ViewDto viewToViewDto(View data); ViewDto viewToViewDto(View data);
@Mappings({ @Mappings({
......
...@@ -10,7 +10,6 @@ import at.tuwien.repository.DatabaseRepository; ...@@ -10,7 +10,6 @@ import at.tuwien.repository.DatabaseRepository;
import at.tuwien.repository.LicenseRepository; import at.tuwien.repository.LicenseRepository;
import at.tuwien.repository.UserRepository; import at.tuwien.repository.UserRepository;
import at.tuwien.service.AuthenticationService; import at.tuwien.service.AuthenticationService;
import at.tuwien.service.UserService;
import at.tuwien.test.AbstractUnitTest; import at.tuwien.test.AbstractUnitTest;
import at.tuwien.utils.KeycloakUtils; import at.tuwien.utils.KeycloakUtils;
import dasniko.testcontainers.keycloak.KeycloakContainer; import dasniko.testcontainers.keycloak.KeycloakContainer;
...@@ -31,7 +30,7 @@ import org.testcontainers.junit.jupiter.Testcontainers; ...@@ -31,7 +30,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import java.util.List; import java.util.List;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
...@@ -120,9 +119,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest ...@@ -120,9 +119,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest
.andDo(print()) .andDo(print())
.andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME)) .andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME))
.andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD)) .andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD))
.andExpect(header().string("X-Host", CONTAINER_1_HOST)) .andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password"))
.andExpect(header().string("X-Port", "" + CONTAINER_1_PORT))
.andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password X-Host X-Port"))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
...@@ -138,9 +135,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest ...@@ -138,9 +135,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest
.andDo(print()) .andDo(print())
.andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME)) .andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME))
.andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD)) .andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD))
.andExpect(header().string("X-Host", CONTAINER_1_HOST)) .andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password"))
.andExpect(header().string("X-Port", "" + CONTAINER_1_PORT))
.andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password X-Host X-Port"))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
...@@ -157,12 +152,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest ...@@ -157,12 +152,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest
.andDo(print()) .andDo(print())
.andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME)) .andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME))
.andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD)) .andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD))
.andExpect(header().string("X-Host", CONTAINER_1_HOST)) .andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password"))
.andExpect(header().string("X-Port", "" + CONTAINER_1_PORT))
.andExpect(header().string("X-Type", IMAGE_1_JDBC))
.andExpect(header().string("X-Database", DATABASE_1_INTERNALNAME))
.andExpect(header().string("X-Table", TABLE_1_INTERNAL_NAME))
.andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password X-Host X-Port X-Type X-Database X-Table"))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
...@@ -177,11 +167,6 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest ...@@ -177,11 +167,6 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest
.andDo(print()) .andDo(print())
.andExpect(header().doesNotExist("X-Username")) .andExpect(header().doesNotExist("X-Username"))
.andExpect(header().doesNotExist("X-Password")) .andExpect(header().doesNotExist("X-Password"))
.andExpect(header().doesNotExist("X-Host"))
.andExpect(header().doesNotExist("X-Port"))
.andExpect(header().doesNotExist("X-Type"))
.andExpect(header().doesNotExist("X-Database"))
.andExpect(header().doesNotExist("X-Table"))
.andExpect(header().doesNotExist("Access-Control-Expose-Headers")) .andExpect(header().doesNotExist("Access-Control-Expose-Headers"))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
...@@ -197,12 +182,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest ...@@ -197,12 +182,7 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest
.andDo(print()) .andDo(print())
.andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME)) .andExpect(header().string("X-Username", CONTAINER_1_PRIVILEGED_USERNAME))
.andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD)) .andExpect(header().string("X-Password", CONTAINER_1_PRIVILEGED_PASSWORD))
.andExpect(header().string("X-Host", CONTAINER_1_HOST)) .andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password"))
.andExpect(header().string("X-Port", "" + CONTAINER_1_PORT))
.andExpect(header().string("X-Type", IMAGE_1_JDBC))
.andExpect(header().string("X-Database", DATABASE_1_INTERNALNAME))
.andExpect(header().string("X-Table", TABLE_1_INTERNAL_NAME))
.andExpect(header().string("Access-Control-Expose-Headers", "X-Username X-Password X-Host X-Port X-Type X-Database X-Table"))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
...@@ -217,11 +197,6 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest ...@@ -217,11 +197,6 @@ public class AuthenticationPrivilegedIntegrationMvcTest extends AbstractUnitTest
.andDo(print()) .andDo(print())
.andExpect(header().doesNotExist("X-Username")) .andExpect(header().doesNotExist("X-Username"))
.andExpect(header().doesNotExist("X-Password")) .andExpect(header().doesNotExist("X-Password"))
.andExpect(header().doesNotExist("X-Host"))
.andExpect(header().doesNotExist("X-Port"))
.andExpect(header().doesNotExist("X-Type"))
.andExpect(header().doesNotExist("X-Database"))
.andExpect(header().doesNotExist("X-View"))
.andExpect(header().doesNotExist("Access-Control-Expose-Headers")) .andExpect(header().doesNotExist("Access-Control-Expose-Headers"))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
......
...@@ -14,46 +14,15 @@ from dbrepo.api.exceptions import MalformedError, ForbiddenError, NotExistsError ...@@ -14,46 +14,15 @@ from dbrepo.api.exceptions import MalformedError, ForbiddenError, NotExistsError
class TableUnitTest(unittest.TestCase): class TableUnitTest(unittest.TestCase):
def test_create_table_succeeds(self): def test_create_table_succeeds(self):
exp = Table(id=2, exp = TableBrief(id=2,
database_id=1,
name="Test", name="Test",
description="Test Table", description="Test Table",
database_id=1,
internal_name="test", internal_name="test",
owner=UserBrief(id='8638c043-5145-4be8-a3e4-4b79991b0a16', username='mweise'), owned_by='8638c043-5145-4be8-a3e4-4b79991b0a16',
is_versioned=True,
queue_name='test',
routing_key='dbrepo.test_database_1234.test',
is_public=True,
is_schema_public=True,
constraints=Constraints(uniques=[],
foreign_keys=[],
checks=[],
primary_key=[PrimaryKey(id=1,
table=TableBrief(id=2, database_id=1,
name='Other',
internal_name='other',
description=None,
is_versioned=True, is_versioned=True,
is_public=True, is_public=True,
is_schema_public=True, is_schema_public=True)
owned_by='8638c043-5145-4be8-a3e4-4b79991b0a16'),
column=ColumnBrief(id=1, table_id=2,
database_id=1,
name='id',
alias=None,
internal_name='id',
type=ColumnType.BIGINT))]),
columns=[Column(id=1,
ord=0,
name="ID",
database_id=1,
table_id=2,
internal_name="id",
auto_generated=True,
is_primary_key=True,
type=ColumnType.BIGINT,
is_public=True,
is_null_allowed=False)])
with requests_mock.Mocker() as mock: with requests_mock.Mocker() as mock:
# mock # mock
mock.post('/api/database/1/table', json=exp.model_dump(), status_code=201) mock.post('/api/database/1/table', json=exp.model_dump(), status_code=201)
......
...@@ -125,7 +125,7 @@ class UserUnitTest(unittest.TestCase): ...@@ -125,7 +125,7 @@ class UserUnitTest(unittest.TestCase):
def test_update_user_succeeds(self): def test_update_user_succeeds(self):
with requests_mock.Mocker() as mock: with requests_mock.Mocker() as mock:
exp = User(id='8638c043-5145-4be8-a3e4-4b79991b0a16', username='mweise', given_name='Martin', exp = UserBrief(id='8638c043-5145-4be8-a3e4-4b79991b0a16', username='mweise', given_name='Martin',
attributes=UserAttributes(theme='dark')) attributes=UserAttributes(theme='dark'))
# mock # mock
mock.put('http://localhost/api/user/8638c043-5145-4be8-a3e4-4b79991b0a16', status_code=202, mock.put('http://localhost/api/user/8638c043-5145-4be8-a3e4-4b79991b0a16', status_code=202,
...@@ -173,16 +173,12 @@ class UserUnitTest(unittest.TestCase): ...@@ -173,16 +173,12 @@ class UserUnitTest(unittest.TestCase):
def test_update_user_password_succeeds(self): def test_update_user_password_succeeds(self):
with requests_mock.Mocker() as mock: with requests_mock.Mocker() as mock:
exp = User(id='8638c043-5145-4be8-a3e4-4b79991b0a16', username='mweise', given_name='Martin',
attributes=UserAttributes(theme='dark'))
# mock # mock
mock.put('http://localhost/api/user/8638c043-5145-4be8-a3e4-4b79991b0a16/password', status_code=202, mock.put('http://localhost/api/user/8638c043-5145-4be8-a3e4-4b79991b0a16/password', status_code=202)
json=exp.model_dump())
# test # test
client = RestClient(username="a", password="b") client = RestClient(username="a", password="b")
response = client.update_user_password(user_id='8638c043-5145-4be8-a3e4-4b79991b0a16', response = client.update_user_password(user_id='8638c043-5145-4be8-a3e4-4b79991b0a16',
password='s3cr3t1n0rm4t10n') password='s3cr3t1n0rm4t10n')
self.assertEqual(exp, response)
def test_update_user_password_not_allowed_fails(self): def test_update_user_password_not_allowed_fails(self):
with requests_mock.Mocker() as mock: with requests_mock.Mocker() as mock:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment