def test_update_store___store_is_not_users_store___403(self): # Arrange self.default_user.groups.add(self.management_store_group) # Act put_response = self.client.put(get_detail_store_url(self.store_a), {}) patch_response = self.client.patch(get_detail_store_url(self.store_a), {}) # Assert self.assertEqual(status.HTTP_403_FORBIDDEN, put_response.status_code) self.assertEqual(status.HTTP_403_FORBIDDEN, patch_response.status_code)
def test_close_store___has_permission_and_owner___201(self): # Act response = self.client.delete(get_detail_store_url(self.default_store)) # Assert self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.assertFalse( Store.objects.filter(pk=self.default_store.pk).exists())
def test_close_store___store_is_not_users_store___403(self): # Arrange self.default_user.groups.add(self.management_store_group) # Act response = self.client.delete(get_detail_store_url(self.store_a)) # Assert self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code)
def test_close_stores___without_authentication__404(self): # Arrange self.client.logout() # Act response = self.client.delete(get_detail_store_url(self.default_store)) # Assert self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
def test_update_store___has_permission_and_owner___200(self): # Arrange self.default_store.name = 'not changed' self.default_store.is_limited_access = False self.default_store.save() data = {'name': 'changed', 'is_limited_access': True} # Act put_response = self.client.put( get_detail_store_url(self.default_store), data) patch_response = self.client.put( get_detail_store_url(self.default_store), data) # Assert self.assertEqual(status.HTTP_200_OK, put_response.status_code) self.assertEqual(status.HTTP_200_OK, patch_response.status_code) updated_store = Store.objects.get(pk=self.default_store.pk) self.assertTrue('changed', updated_store.name) self.assertTrue(True, updated_store.is_limited_access)
def test_get_stores___to_limited_access_store___404(self): # Arrange self.store_a.is_limited_access = True self.store_a.save() # Act detail_response = self.client.get(get_detail_store_url(self.store_a)) # Assert self.assertEqual(status.HTTP_404_NOT_FOUND, detail_response.status_code)
def test_detail_store___store_is_limited_access_store_and_login_users_has_read_authorization_of_store___200( self): # Arrange self.default_store.is_limited_access = True self.user_a.groups.add(self.default_store.limited_customer_group) self.default_store.save() self.client.force_login(self.user_a) # Act response = self.client.get(get_detail_store_url(self.default_store)) # Assert self.assertEqual(status.HTTP_200_OK, response.status_code)
def test_get_stores___with_out_authentication___404(self): # Arrange self.client.logout() # Act list_response = self.client.get(STORE_LIST_URL) detail_response = self.client.get( get_detail_store_url(self.default_store)) # Assert self.assertEqual(status.HTTP_404_NOT_FOUND, list_response.status_code) self.assertEqual(status.HTTP_404_NOT_FOUND, detail_response.status_code)
def test_detail_store____items_parameter_is_true___200_get_with_items( self): # Arrange expected_columns = ['pk', 'name', 'user', 'items'] # Act response = self.client.get( get_detail_store_url(self.default_store) + "?items=true") # Assert self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertTrue( all([column in response.data for column in expected_columns]), response.data)