Skip to content

Commit

Permalink
feat: (WIP) getting through Guilhem's comments
Browse files Browse the repository at this point in the history
Signed-off-by: Léo-Paul HAUET <[email protected]>
  • Loading branch information
IC-1101asterisk committed Jul 10, 2023
1 parent acd4634 commit 3b08353
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
3 changes: 1 addition & 2 deletions backend/api/tests/views/test_views_computeplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,8 @@ def test_computeplan_list_success(self):
)

def test_computeplan_list_wrong_channel(self):
extra = {"HTTP_ACCEPT": "application/json;version=0.0"}
self.client.channel = "yourchannel"
response = self.client.get(self.url, **extra)
response = self.client.get(self.url, **self.extra)
self.assertEqual(response.json(), {"count": 0, "next": None, "previous": None, "results": []})

@internal_server_error_on_exception()
Expand Down
6 changes: 2 additions & 4 deletions backend/api/tests/views/test_views_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ def test_datamanager_list_success(self):
)

def test_datamanager_list_wrong_channel(self):
extra = {"HTTP_ACCEPT": "application/json;version=0.0"}
self.client.channel = "yourchannel"
response = self.client.get(self.url, **extra)
response = self.client.get(self.url, **self.extra)
self.assertEqual(response.json(), {"count": 0, "next": None, "previous": None, "results": []})

@internal_server_error_on_exception()
Expand Down Expand Up @@ -503,9 +502,8 @@ def test_datamanager_retrieve_with_tasks(self):

def test_datamanager_retrieve_wrong_channel(self):
url = reverse("api:data_manager-detail", args=[self.expected_results[0]["key"]])
extra = {"HTTP_ACCEPT": "application/json;version=0.0"}
self.client.channel = "yourchannel"
response = self.client.get(url, **extra)
response = self.client.get(url, **self.extra)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

def test_datamanager_retrieve_storage_addresses_update(self):
Expand Down
7 changes: 2 additions & 5 deletions backend/api/tests/views/test_views_datasample.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ def test_datasample_retrieve(self):

def test_datasample_retrieve_wrong_channel(self):
url = reverse("api:data_sample-detail", args=[self.expected_results[0]["key"]])
extra = {"HTTP_ACCEPT": "application/json;version=0.0"}
self.client.channel = "yourchannel"
sys.stderr.write(f"{self.client.channel}")
sys.stderr.write(f"{type(self.client.channel)}")

response = self.client.get(url, **extra)
response = self.client.get(url, **self.extra)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

@internal_server_error_on_exception()
Expand All @@ -139,9 +137,8 @@ def test_datasample_list_success(self):
)

def test_datasample_list_wrong_channel(self):
extra = {"HTTP_ACCEPT": "application/json;version=0.0"}
self.client.channel = "yourchannel"
response = self.client.get(self.url, **extra)
response = self.client.get(self.url, **self.extra)
self.assertEqual(response.json(), {"count": 0, "next": None, "previous": None, "results": []})

@internal_server_error_on_exception()
Expand Down
1 change: 0 additions & 1 deletion backend/users/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def test_oidc_username_generation(self):

class TestUserEndpoints:
url = None
extra = None

@pytest.fixture(autouse=True)
def use_dummy_channels(self, settings):
Expand Down
11 changes: 4 additions & 7 deletions backend/users/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def has_permission(self, request, view):

class IsAdmin(permissions.BasePermission):
def has_permission(self, request, view):
if request.user.is_authenticated:
return request.user.channel.role == UserChannel.Role.ADMIN
return request.user.channel.role == UserChannel.Role.ADMIN


class IsSelf(permissions.BasePermission):
Expand Down Expand Up @@ -280,11 +279,9 @@ def put(self, request, *args, **kwargs):
return ApiResponse(data={"message": "User not found"}, status=status.HTTP_404_NOT_FOUND)

channel_name = get_channel_name(request)
channel_data = {"channel_name": channel_name}
channel_data["role"] = _validate_role(d.get("role"))
channel_data["user"] = user
UserChannel.objects.create(**channel_data)
user.refresh_from_db()
channel_name = get_channel_name(request)
role = _validate_role(d.get("role"))
UserChannel.objects.create(channel_name=channel_name, role=role, user=user)
data = UserSerializer(instance=user).data
return ApiResponse(data=data, status=status.HTTP_200_OK) # get success header ?

Expand Down

0 comments on commit 3b08353

Please sign in to comment.