How to use deactivate method in Slash

Best Python code snippet using slash

test_deactivate_product.py

Source:test_deactivate_product.py Github

copy

Full Screen

1from healthid.tests.test_fixtures.products import (2 deactivate_product, retrieve_deactivated_products, activate_product)3from healthid.tests.products.test_create_product import TestCreateProduct4from healthid.utils.messages.products_responses import PRODUCTS_ERROR_RESPONSES5class TestDeactivateProducts(TestCreateProduct):6 def deactivate_another_product(self):7 '''8 Method to deactivate a product9 '''10 self.product.is_active = False11 return self.product.save()12 def test_master_admin_can_deactivate_product(self):13 '''14 Method tests master admin can deactivate products15 '''16 response = self.query_with_token(self.access_token_master,17 deactivate_product([self.product.id]))18 self.assertIn("success", response["data"]["deactivateProduct"])19 self.assertNotIn('errors', response)20 def test_managers_or_all_users_cannot_deactivate_product(self):21 '''22 Method tests managerss and other users can not deactivate23 products24 '''25 response = self.query_with_token(self.access_token,26 deactivate_product([self.product.id]))27 self.assertIsNotNone(response['errors'])28 def test_cannot_deactivate_products_without_product_ids(self):29 '''30 Method tests an error is raised if a list of empty ids is31 provided32 '''33 response = self.query_with_token(self.access_token_master,34 deactivate_product([]))35 self.assertEqual(response['errors'][0]['message'],36 'Please provide product ids.')37 def test_cannot_deactivate_product_that_does_not_exist(self):38 '''39 Method tests an error is rasied if a product does not exist40 '''41 response = self.query_with_token(self.access_token_master,42 deactivate_product([101]))43 self.assertEqual(response['errors'][0]['message'],44 "Product with id [101] does not exist or is "45 "already deactivated.")46 def test_cannot_deactivate_product_when_unauthenticated(self):47 '''48 Method tests unauthenticated user cannot deactivate products49 '''50 response = self.query_with_token('',51 deactivate_product([self.product.id]))52 self.assertIsNotNone(response['errors'])53 def test_master_admin_can_retrieve_deactivated_products(self):54 '''55 Tests master admin can retrieve deactivated products56 '''57 self.deactivate_another_product()58 response = self.query_with_token(59 self.access_token_master,60 retrieve_deactivated_products(self.outlet.id))61 self.assertEqual(response['data']['deactivatedProducts'][0]['id'],62 str(self.product.id))63 def test_managers_or_all_users_cannot_retrieve_deactivated_products(self):64 '''65 Tests managers and other users cannot retrieve deactivated66 products67 '''68 response = self.query_with_token(69 self.access_token,70 retrieve_deactivated_products(self.outlet.id))71 self.assertIsNotNone(response['errors'])72 def test_cannot_retrieve_deactivated_products_when_unauthenticated(self):73 '''74 Tests unauthenticated user cannot retrieve deactivated products75 '''76 response = self.query_with_token(77 '', retrieve_deactivated_products(self.outlet.id))78 self.assertIsNotNone(response['errors'])79 def test_master_admin_can_activate_product(self):80 '''81 Method tests master admin can activate products82 '''83 self.deactivate_another_product()84 response = self.query_with_token(85 self.access_token_master,86 activate_product([self.product.id])87 )88 self.assertIn("success", response["data"]["activateProduct"])89 self.assertNotIn('errors', response)90 def test_managers_or_all_users_cannot_activate_product(self):91 '''92 Method tests managerss and other users can not activate93 products94 '''95 self.deactivate_another_product()96 response = self.query_with_token(97 self.access_token,98 activate_product([self.product.id])99 )100 self.assertIsNotNone(response['errors'])101 def test_cannot_activate_products_without_product_ids(self):102 '''103 Method tests an error is raised if a list of empty ids is104 provided105 '''106 self.deactivate_another_product()107 response = self.query_with_token(self.access_token_master,108 activate_product([]))109 self.assertEqual(response['errors'][0]['message'],110 'Please provide product ids.')111 def test_cannot_activate_product_that_does_not_exist(self):112 '''113 Method tests an error is rasied if a product does not exist114 '''115 self.deactivate_another_product()116 response = self.query_with_token(self.access_token_master,117 activate_product([101]))118 self.assertEqual(response['errors'][0]['message'],119 PRODUCTS_ERROR_RESPONSES[120 "product_activation_error"].format("[101]"))121 def test_cannot_activate_product_when_unauthenticated(self):122 '''123 Method tests unauthenticated user cannot activate products124 '''125 self.deactivate_another_product()126 response = self.query_with_token(127 '', activate_product([self.product.id])128 )...

Full Screen

Full Screen

test_deactivate_account.py

Source:test_deactivate_account.py Github

copy

Full Screen

1'''2Created on 28/08/201534@author: EJArizaR5'''6from django.core.urlresolvers import reverse7from mock import patch8from django.template.loader import get_template9from django.template.context import Context10from mock.mock import call11from django.contrib.auth import get_user_model12from apps.DaneUsers.tests.test_base import test_base13User = get_user_model()1415class DeactivateAccountBase(test_base):1617 def setUp(self):18 test_base.setUp(self) 19 self.create_user()20 self.DEFAULT_CREDENTIALS = {"email":"email@email.com", "password":"password"}21 self.WRONG_CREDENTIALS = {'email':'usuario@erroneo.com', 'password':'contrasenia'}22 23 def login(self):24 self.client.login(email = "email@email.com", password='password')25 26 def post_for_deactivate_defaul_user(self):27 return self.client.post(reverse('DaneUsers:deactivate'), self.DEFAULT_CREDENTIALS)282930class DeactivateAccountTest(DeactivateAccountBase):31 def test_redirect_to_login_page_when_no_logged(self):32 response = self.client.get(reverse('DaneUsers:deactivate')) 33 self.assertRedirects(response, reverse('DaneUsers:login') + "/?next=" + reverse('DaneUsers:deactivate')) 3435 def post_for_deactivate_unexistent_user(self):36 return self.client.post(reverse('DaneUsers:deactivate'), self.WRONG_CREDENTIALS) 3738 def get_default_user(self):39 return User.objects.get(email="email@email.com")40 41 def test_when_given_correct_credentials_deactivate_account(self):42 self.login() 43 self.post_for_deactivate_defaul_user()44 userDeactivated = User.objects.get(email="email@email.com")45 self.assertFalse(userDeactivated.is_active)4647 def test_when_given_wrong_credentials_does_not_deactivate_account(self):48 self.client.login(username='usuario', password='contrasenia') 49 self.client.post(reverse('DaneUsers:deactivate'), {"email":"wrong_user" , "password": "wrong_pass"})50 userDeactivated = self.get_default_user()51 self.assertTrue(userDeactivated.is_active)52 53 def test_when_given_no_email_does_not_deactivate_account(self):54 self.login() 55 self.client.post(reverse('DaneUsers:deactivate'), {"password": "wrong_pass"})56 userDeactivated = self.get_default_user()57 self.assertTrue(userDeactivated.is_active) 5859 def test_when_given_invalid_email_does_not_deactivate_account(self):60 self.login() 61 self.client.post(reverse('DaneUsers:deactivate'), {"email": "invalidstuff","password": "wrong_pass"})62 userDeactivated = self.get_default_user()63 self.assertTrue(userDeactivated.is_active) 6465 def test_when_logged_opens_the_deactivate_template(self):66 self.login()67 response = self.client.get(reverse('DaneUsers:deactivate')) 68 self.assertIn('DaneUsers/deactivate.html', [t.name for t in response.templates])69 70 def test_when_deactivate_redirect_to_deactivated_page(self):71 self.login() 72 response = self.post_for_deactivate_defaul_user()73 self.assertRedirects(response, reverse('DaneUsers:notActiveUser')) 74 75 def test_when_deactivate_logs_out(self):76 self.login() 77 self.post_for_deactivate_defaul_user()78 self.assertNotIn('_auth_user_id', self.client.session) 7980 def test_redirects_correctly_when_given_wrong_credentials(self):81 self.login() 82 response = self.post_for_deactivate_unexistent_user()83 self.assertRedirects(response, reverse('DaneUsers:deactivate') +'?wrongCredentials=True')84 85 def test_does_not_deactivate_account_when_user_given_is_not_the_authenticated_user(self):86 User.objects.create_user( "corre2@forest.com", "contrasenia")87 self.login() 88 response = self.client.post(reverse('DaneUsers:deactivate'), {"email":"corre2@forest.com" , "password": "contrasenia"})89 self.assertRedirects(response, reverse('DaneUsers:deactivate') +'?wrongCredentials=True') 90 91 92@patch("apps.DaneUsers.views.DeactivateUserView.EmailMultiAlternatives")93class DeactivateUserMailTest(DeactivateAccountBase):94 def test_create_mail_when_account_deactivated(self, mocked_send_mail):95 self.login() 96 self.post_for_deactivate_defaul_user()97 mocked_send_mail.assert_called_with('Deactivated Account', 98 'Your account has been deactivated', 99 'from@example.com', 100 ["email@email.com"])101102 def test_deactivated_mail_contains_deactivate_mail_template(self, mocked_send_mail):103 self.login() 104 self.post_for_deactivate_defaul_user()105 email_template = get_template("DaneUsers/mail/deactivate.html")106 email_html = email_template.render({})107 mocked_send_mail().attach_alternative.assert_called_with(email_html, "text/html")108 109 def test_sends_mail_for_deactivated_accounts(self, mocked_send_mail):110 self.login() 111 self.post_for_deactivate_defaul_user()112 self.assertTrue(mocked_send_mail().send.called)113114 def test_send_mail_at_last(self, mocked_send_mail):115 self.login() 116 self.client.post(reverse('DaneUsers:deactivate'), self.DEFAULT_CREDENTIALS) 117 last_call = mocked_send_mail().mock_calls[-1]118 expected_last_call = call.send()119 self.assertEqual(last_call, expected_last_call)120 ...

Full Screen

Full Screen

soft_deactivate_users.py

Source:soft_deactivate_users.py Github

copy

Full Screen

1import sys2from argparse import ArgumentParser3from typing import Any, Dict, List4from django.conf import settings5from django.core.management.base import CommandError6from zerver.lib.management import ZulipBaseCommand7from zerver.lib.soft_deactivation import (8 do_auto_soft_deactivate_users,9 do_soft_activate_users,10 do_soft_deactivate_users,11 logger,12)13from zerver.models import Realm, UserProfile14def get_users_from_emails(emails: List[str],15 filter_kwargs: Dict[str, Realm]) -> List[UserProfile]:16 # Bug: Ideally, this would be case-insensitive like our other email queries.17 users = UserProfile.objects.filter(18 delivery_email__in=emails,19 **filter_kwargs)20 if len(users) != len(emails):21 user_emails_found = {user.delivery_email for user in users}22 user_emails_not_found = '\n'.join(set(emails) - user_emails_found)23 raise CommandError(24 'Users with the following emails were not found:\n\n'25 f'{user_emails_not_found}\n\n'26 'Check if they are correct.',27 )28 return users29class Command(ZulipBaseCommand):30 help = """Soft activate/deactivate users. Users are recognised by their emails here."""31 def add_arguments(self, parser: ArgumentParser) -> None:32 self.add_realm_args(parser)33 parser.add_argument('-d', '--deactivate',34 dest='deactivate',35 action='store_true',36 default=False,37 help='Used to deactivate user/users.')38 parser.add_argument('-a', '--activate',39 dest='activate',40 action='store_true',41 default=False,42 help='Used to activate user/users.')43 parser.add_argument('--inactive-for',44 type=int,45 default=28,46 help='Number of days of inactivity before soft-deactivation')47 parser.add_argument('users', metavar='<users>', type=str, nargs='*', default=[],48 help="A list of user emails to soft activate/deactivate.")49 def handle(self, *args: Any, **options: Any) -> None:50 if settings.STAGING:51 print('This is a Staging server. Suppressing management command.')52 sys.exit(0)53 realm = self.get_realm(options)54 user_emails = options['users']55 activate = options['activate']56 deactivate = options['deactivate']57 filter_kwargs: Dict[str, Realm] = {}58 if realm is not None:59 filter_kwargs = dict(realm=realm)60 if activate:61 if not user_emails:62 print('You need to specify at least one user to use the activate option.')63 self.print_help("./manage.py", "soft_deactivate_users")64 raise CommandError65 users_to_activate = get_users_from_emails(user_emails, filter_kwargs)66 users_activated = do_soft_activate_users(users_to_activate)67 logger.info('Soft Reactivated %d user(s)', len(users_activated))68 elif deactivate:69 if user_emails:70 users_to_deactivate = get_users_from_emails(user_emails, filter_kwargs)71 print('Soft deactivating forcefully...')72 users_deactivated = do_soft_deactivate_users(users_to_deactivate)73 else:74 users_deactivated = do_auto_soft_deactivate_users(int(options['inactive_for']),75 realm)76 logger.info('Soft Deactivated %d user(s)', len(users_deactivated))77 else:78 self.print_help("./manage.py", "soft_deactivate_users")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful