def test_requires_oc(): """The injector should make sure the OC client is installed.""" with patch('integrade.injector.subprocess.run') as run: with patch('integrade.injector.which') as which: which.return_value = False with pytest.raises(EnvironmentError): injector.run_remote_python('code') assert not run.called
def drop_image_data(): """Drop all image data from the cloudigrade's database.""" injector.run_remote_python(""" from account.models import AwsMachineImage, AwsMachineImageCopy # Must delete AwsMachineImageCopy first because they reference # AwsMachineImage objects AwsMachineImageCopy.objects.all().delete() AwsMachineImage.objects.all().delete() """)
def test_data_injection(): """The code gets data injected into it.""" code = 'global result;result = x + 1' with patch('integrade.injector.subprocess.run') as run: run.return_value.returncode = 0 run.return_value.stdout = b'' injector.run_remote_python(code, x=41) args, kwargs = run.call_args code = kwargs['input'].decode('utf8') globals = {} exec(code, globals) assert globals['result'] == 42
def create_user_account(user=None): """Create a new user account. :param user: A dictionary with the arguments to be passed to the Django's create_user helper function. """ if user is None: email = f'{uuid4()}@example.com' user = create_user_account({ 'email': email, 'password': gen_password(), 'username': email, }) else: user = copy.deepcopy(user) user['id'] = injector.run_remote_python( """ from django.contrib.auth.models import User return User.objects.create_user(**user).id """, **locals()) return user