-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from linea-it/192-remove-another-users-product
- Loading branch information
Showing
5 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,7 @@ def test_product_serialized_format(self): | |
"product_type_name": self.product_type.display_name, | ||
"uploaded_by": self.user.username, | ||
"is_owner": True, | ||
"can_delete": True, | ||
"internal_name": self.product.internal_name, | ||
"display_name": self.product.display_name, | ||
"official_product": self.product.official_product, | ||
|
@@ -336,6 +337,27 @@ def test_product_object_delete(self): | |
|
||
self.assertEqual(204, response.status_code) | ||
|
||
def test_product_object_delete_by_admin(self): | ||
"""Tests if the product admin can remove it""" | ||
view = ProductViewSet.as_view({"delete": "destroy"}) | ||
|
||
# Cria um usuario que faz parte do grupo admin | ||
adm_group = Group.objects.create(name="Admin") | ||
user = User.objects.create_user("john2", "[email protected]", "you_know_nothing") | ||
user.groups.add(adm_group) | ||
token = Token.objects.create(user=user) | ||
# Cria uma requisicao utilizando Factory | ||
# para que o metodo destroy da view tenha acesso ao request.user | ||
factory = APIRequestFactory() | ||
request = factory.delete(self.url, format="json") | ||
force_authenticate(request, user=user, token=user.auth_token) | ||
request.user = user | ||
|
||
raw_response = view(request, pk=self.product.pk) | ||
response = raw_response.render() | ||
|
||
self.assertEqual(204, response.status_code) | ||
|
||
def test_access_another_user_product(self): | ||
"""Verifica se é possivel um usuario ler produtos de outro usuario. | ||
Valida se a flag is_owner retorna False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters