def test_get_committer_data(self): committer = Mock() committer.email = "*****@*****.**" committer.login = "******" data = self.provider.get_committer_data(committer)._identity self.assertEqual(data["name"], "foo") self.assertEqual(data["email"], "*****@*****.**") committer = Mock() committer.email = None committer.login = "******" committer.get_emails.return_value = [ { "primary": True, "email": "*****@*****.**" }, ] data = self.provider.get_committer_data(committer)._identity self.assertEqual(data["name"], "foo") self.assertEqual(data["email"], "*****@*****.**") committer = Mock() committer.email = None committer.login = "******" committer.get_emails.return_value = [] with self.assertRaises(errors.NoPermissionError): data = self.provider.get_committer_data(committer)
def test_filter(self): user = Mock() user.email = '*****@*****.**' record = Mock() record.request.user = user record.request.META = {} self.assertTrue(AddCurrentUser().filter(record))
def test_get_enrollment_data(self, datetime_now_mock, _get_course_list_mock, get_user_mock): """Test _get_enrollment_data method.""" data = { 'user_email': '*****@*****.**', 'is_active': True, } course_settings = { 'external_course_run_id': 'course_id+10', } expected_data = u'08-04-2020 10:50:34, John Doe, John, Doe, [email protected], course_id+10, true\n' expected_data += u'08-04-2020 10:50:34, Mary Brown, Mary, Brown, [email protected], course_id+10, true\n' user = Mock() user.first_name = 'Mary' user.last_name = 'Brown' user.email = '*****@*****.**' user.profile.name = 'Mary Brown' get_user_mock.return_value = (user, '') datetime_now_mock.now.return_value.strftime.return_value = '08-04-2020 10:50:34' dropbox_response = Mock() dropbox_response.text = u'08-04-2020 10:50:34, John Doe, John, Doe, [email protected], course_id+10, true\n' _get_course_list_mock.return_value = dropbox_response self.assertEqual( self.base._get_enrollment_data(data, course_settings), # pylint: disable=protected-access expected_data, )
def the_user(): the_user = Mock() the_user.userid = USERID the_user.username = USERNAME the_user.email = EMAIL the_user.password = PASSWORD yield the_user
def test_send_if_everything_is_okay(): """Test whether we generate notifications if every condition is okay""" with patch('h.notification.reply_template.Annotation') as mock_annotation: mock_annotation.fetch = MagicMock(side_effect=fake_fetch) request = _create_request() annotation = store_fake_data[1] with patch('h.notification.reply_template.Subscriptions') as mock_subs: mock_subs.get_active_subscriptions_for_a_type.return_value = [ MockSubscription(id=1, uri='acct:[email protected]') ] with patch('h.notification.reply_template.check_conditions' ) as mock_conditions: mock_conditions.return_value = True with patch( 'h.notification.reply_template.render') as mock_render: mock_render.return_value = '' with patch('h.notification.reply_template.get_user_by_name' ) as mock_user_db: user = Mock() user.email = '*****@*****.**' mock_user_db.return_value = user msgs = rt.generate_notifications( request, annotation, 'create') msgs.next()
def test_add_new_address(self, mock_log): secondary_address = Mock() secondary_address.email = "*****@*****.**" with patch('django_mailman3.lib.mailman.get_mailman_user', return_value=None): # If the user does not exist, function return and logs the result. mailman.add_address_to_mailman_user(self.user, secondary_address) mock_log.info.assert_called()
def test_that_helper_does_not_add_email_to_BSD_if_permission_refused(self, mock_task_func): mock_user = Mock() mock_user.email = '*****@*****.**' mock_privacy_form = Mock() mock_privacy_form.cleaned_data = {'add_me_to_email_list': False} views._add_email_to_bsd(mock_user, mock_privacy_form) eq_(mock_task_func.delay.call_args_list, [])
def test_that_helper_adds_email_to_BSD_if_permission_was_given(self, mock_task_func): mock_user = Mock() mock_user.email = '*****@*****.**' mock_privacy_form = Mock() mock_privacy_form.cleaned_data = {'add_me_to_email_list': True} views._add_email_to_bsd(mock_user, mock_privacy_form) mock_task_func.delay.assert_called_with('*****@*****.**', '111')
def _get_or_add_address(self, email, **kw): try: mm_addr = self.mm_addresses[email] except KeyError: mm_addr = Mock() mm_addr.email = email mm_addr.verified_on = None self.mm_addresses[email] = mm_addr return mm_addr
def _get_or_add_address(self, email, **kw): # pylint: disable-msg=unused-argument try: mm_addr = self.mm_addresses[email] except KeyError: mm_addr = Mock() mm_addr.email = email mm_addr.verified_on = None self.mm_addresses[email] = mm_addr return mm_addr
def testGetEmail(self, mockRemoteStore): email = '*****@*****.**' # Mock a remote user object, and bind it to fetch_user remote_user = Mock() remote_user.email = email instance = mockRemoteStore.return_value instance.fetch_user.return_value = remote_user ddsutil = DDSUtil(self.user) self.assertEqual(email, ddsutil.get_remote_user(self.user_id).email) self.assertTrue(instance.fetch_user.called)
def test_google_user_logged_for_the_first_time(self): google_account_user = Mock() google_account_user.user_id = lambda: '123' google_account_user.email = lambda: '*****@*****.**' google_account_user.nickname = lambda: 'foo' user = facade.login_google(google_account_user, Mock()).execute().result self.assertEqual('*****@*****.**', user.email) self.assertEqual('foo', user.name) self.assertEqual(MainUser.query().get(), user) google_user = OriginsSearch(ExternalToMainUser, user).execute().result[0] self.assertEqual('123', google_user.google_id)
def test_get_email(): """Tests whether it gives back the user.email property""" with patch('h.notification.reply_template.get_user_by_name') as mock_user_db: user = Mock() user.email = '*****@*****.**' mock_user_db.return_value = user request = _fake_request() annotation = _fake_anno(0) email = rt.get_recipients(request, annotation) assert email[0] == user.email
def login(self, adapter, provider_name): del adapter, provider_name response = Mock() response.error = self.error if self.error: response.user = False else: user = Mock() user.name = self.name user.email = self.email response.user = user return response
def test_extract_leads_from_chats(self): operator = Mock() operator.email = MagicMock(return_value='*****@*****.**') product_reference = 'PF12345' with patch.dict(CHAT1['Chat'], {'Operator': operator, 'Customs': {'Imovel': product_reference}}): chat_list = [CHAT1] actual = Livezilla.extract_leads_from_chats(chat_list) expected = {'name': u'Chat #11123 | Ivone Duarte', 'description': u'Can you help me?\nA', 'contact_name': u'Ivone Duarte', 'contact_phone': u'967961100', 'contact_email': u'*****@*****.**', 'operator': unicode(operator.email), 'group': u'groupid1', 'product_code': product_reference} self.assertEqual(1, len(actual)) self.assertDictEqual(expected, actual[0])
def test_existing_address_but_not_verified(self): # The secondary address exists but is not verified self.mailman_client.get_address.side_effect = self._get_or_add_address secondary_address = Mock() secondary_address.email = "*****@*****.**" secondary_address.verified_on = None secondary_address.__unicode__ = lambda self: self.email self.mm_user.addresses.append(secondary_address) self.mm_addresses["*****@*****.**"] = secondary_address mailman.add_address_to_mailman_user(self.user, "*****@*****.**") # The secondary address must only have been verified. self.assertFalse(self.mm_user.add_address.called) secondary_address.verify.assert_called_with()
def test_get_committer_data(self): committer = Mock() committer.email = "*****@*****.**" committer.login = "******" data = self.provider.get_committer_data(committer)._identity self.assertEqual(data["name"], "foo") self.assertEqual(data["email"], "*****@*****.**") committer = Mock() committer.email = None committer.login = "******" committer.get_emails.return_value = [{"primary": True, "email": "*****@*****.**"},] data = self.provider.get_committer_data(committer)._identity self.assertEqual(data["name"], "foo") self.assertEqual(data["email"], "*****@*****.**") committer = Mock() committer.email = None committer.login = "******" committer.get_emails.return_value = [] with self.assertRaises(errors.NoPermissionError): data = self.provider.get_committer_data(committer)
def test_existing_address_but_not_verified(self): # The secondary address exists but is not verified self.mailman_client.get_address.side_effect = self._get_or_add_address secondary_address = Mock() secondary_address.email = "*****@*****.**" secondary_address.verified_on = None secondary_address.__unicode__ = lambda self: self.email self.mm_user.addresses.append(secondary_address) details = {"secondary_email": "*****@*****.**"} mailman.add_user_to_mailman(self.user, details) # The secondary address must only have been verified. self.assertFalse(self.mm_user.add_address.called) secondary_address.verify.assert_called_with()
def test_adult_details_with_adult(self): person = Mock() person.name = "Bob" person.email = "*****@*****.**" person.age_str = Mock(return_value="22") person.adult = Mock(return_value=True) # An example using a mock instead of an actual person to prevent the need for hitting the database # for no reason. And also to validate that the check for the user being an adult was first checked expect(self.example.adult_details(person)).to(equal("Bob - [email protected] - 22")) expect(person.adult.call_count).to(equal(1)) # Make sure that the adult function was called person.adult.assert_called()
def test_that_create_event_and_venue_does_that_given_valid_data(self): event_kind = models.EventKind(name = "Test", slug = "test", description = "Test") event_kind.save() self.data['event-kind'] = str(event_kind.id) ef = forms.EventForm(self.data) vf = forms.VenueForm(self.data) mock_user = Mock() mock_user.email = '*****@*****.**' event, venue = views._create_event_and_venue(mock_user, ef, vf) ok_(event.id is not None) ok_(venue.id is not None) eq_(venue.location.y, 51.0) eq_(venue, event.venue)
def test_adult_details_with_adult(self): person = Mock() person.name = "Bob" person.email = "*****@*****.**" person.age_str = Mock(return_value="22") person.adult = Mock(return_value=True) # An example using a mock instead of an actual person to prevent the need for hitting the database # for no reason. And also to validate that the check for the user being an adult was first checked expect(self.example.adult_details(person)).to( equal("Bob - [email protected] - 22")) expect(person.adult.call_count).to(equal(1)) # Make sure that the adult function was called person.adult.assert_called()
def test_success(self): users_mock = Mock() google_user = Mock() user_email = '*****@*****.**' google_user.email = Mock(return_value=user_email) users_mock.get_current_user = Mock(return_value=google_user) users_mock.is_current_user_admin = Mock(return_value=True) sites.users = users_mock setup = facade.initial_setup() setup.execute() site = setup.result find = facade.find_current_site() find.execute() self.assertEqual(site.key, find.result.key)
def test_get_email(): """Tests whether it gives back the user.email property""" with patch('h.notification.reply_template.Annotation') as mock_annotation: mock_annotation.fetch = MagicMock(side_effect=fake_fetch) with patch('h.notification.reply_template.get_user_by_name') as mock_user_db: user = Mock() user.email = '*****@*****.**' mock_user_db.return_value = user request = _create_request() annotation = store_fake_data[1] parent = rt.parent_values(annotation) email = rt.get_recipients(request, parent) assert email[0] == user.email
def test_extract_leads_from_chats_excluding_duplicates1(self): """ Different chats between the same operator and the same client should be merged into a single lead where the description is the concatenation of the plain texts of the chats """ operator = Mock() operator.email = MagicMock(return_value='*****@*****.**') with patch.dict(CHAT1['Chat'], {'Operator': operator}), patch.dict(CHAT2['Chat'], {'Operator': operator}): chat_list = [CHAT1, CHAT2] actual = Livezilla.extract_leads_from_chats(chat_list) expected = {'name': u'Chat #11123 | Ivone Duarte', 'description': u'Can you help me?\nA' + '\n' + 20 * '-' + '\n' + u'Can you help me?\nB', 'contact_name': u'Ivone Duarte', 'contact_phone': u'967961100', 'contact_email': u'*****@*****.**', 'operator': unicode(operator.email), 'group': u'groupid1', 'product_code': None} self.assertEqual(1, len(actual)) self.assertDictEqual(expected, actual[0])
def test_should_send_correct_email_in_html_format_in_english_to_a_newly_created_user( self): site = get_current_site(None) user = Mock(spec=User) user.email = '*****@*****.**' user.id = 1 user.first_name = "test" language_code = "en" request = Mock() request.user.first_name = "rakoto" with patch( "django.contrib.auth.tokens.default_token_generator.make_token" ) as make_token: make_token.return_value = "token" send_email_to_data_sender(user, language_code, type="created_user", request=request) emails = [mail.outbox.pop() for i in range(len(mail.outbox))] self.assertEqual(1, len(emails)) sent_email = emails[0] self.assertEqual("html", sent_email.content_subtype) self.assertEqual(settings.EMAIL_HOST_USER, sent_email.from_email) self.assertEqual(['*****@*****.**'], sent_email.to) self.assertEqual([settings.HNI_SUPPORT_EMAIL_ID], sent_email.bcc) ctx_dict = { 'domain': site.domain, 'uid': int_to_base36(user.id), 'user': user, 'token': "token", 'protocol': 'http', 'creator_user': request.user.first_name, 'site': site, 'account_type': 'Pro SMS', } self.assertEqual( render_to_string( 'registration/created_user_email_subject_en.txt') % site.domain, sent_email.subject) self.assertEqual( render_to_string('registration/created_user_email_en.html', ctx_dict), sent_email.body)
def _create_mock_contact_message(mock_pk=1, mock_name="message name", mock_email="*****@*****.**", mock_content="lorem ipsum dolor sit amet "): """ :param mock_pk: :param mock_name: :param mock_email: :param mock_content: :return: """ mock_message = Mock(spec=ContactMessage) mock_message.id = mock_pk mock_message.name = mock_name mock_message.email = mock_email mock_message.content = mock_content return mock_message
def test_get_email(): """Tests whether it gives back the user.email property""" with patch('h.notification.reply_template.Annotation') as mock_annotation: mock_annotation.fetch = MagicMock(side_effect=fake_fetch) with patch('h.notification.reply_template.get_user_by_name') as mock_user_db: user = Mock() user.email = '*****@*****.**' mock_user_db.return_value = user request = DummyRequest() request.domain = 'www.howtoreachtheark.now' annotation = store_fake_data[1] data = { 'parent': rt.parent_values(annotation), 'subscription': {'id': 1} } email = rt.get_recipients(request, data) assert email[0] == user.email
def test_send_if_everything_is_okay(): """Test whether we generate notifications if every condition is okay""" request = _create_request() annotation = Annotation.fetch(1) with patch('h.notification.reply_template.Subscriptions') as mock_subs: mock_subs.get_active_subscriptions_for_a_type.return_value = [ MockSubscription(id=1, uri='acct:[email protected]') ] with patch('h.notification.reply_template.check_conditions') as mock_conditions: mock_conditions.return_value = True with patch('h.notification.reply_template.render') as mock_render: mock_render.return_value = '' with patch('h.notification.reply_template.get_user_by_name') as mock_user_db: user = Mock() user.email = '*****@*****.**' mock_user_db.return_value = user msgs = rt.generate_notifications(request, annotation, 'create') msgs.next()
def test_success(self): users_mock = Mock() google_user = Mock() user_email = '*****@*****.**' google_user.email = Mock(return_value=user_email) users_mock.get_current_user = Mock(return_value=google_user) users_mock.is_current_user_admin = Mock(return_value=True) sites.users = users_mock setup = facade.initial_setup() setup.execute() site = setup.result self.assertEqual(settings.APP_HOST, site.domain) find_user = FindOrCreateUser(user_email) find_user.execute() user = find_user.result search = SitesSearch(to_node_key(user)) search.execute() user_sites = search.result self.assertListEqual([site.key], [s.key for s in user_sites])
def test_create_tag(self, user_email): mock_user = Mock(spec=NamedUser) mock_user.email = user_email mock_user.name = 'test_name' with patch.object(Github, 'get_user', return_value=mock_user): create_tag_mock = Mock() create_ref_mock = Mock() self.repo_mock.create_git_tag = create_tag_mock self.repo_mock.create_git_ref = create_ref_mock test_tag = 'test_tag' test_sha = 'abc' self.api.create_tag(test_sha, test_tag) _, kwargs = create_tag_mock.call_args # pylint: disable=unpacking-non-sequence self.assertEqual(kwargs['tag'], test_tag) self.assertEqual(kwargs['message'], '') self.assertEqual(kwargs['type'], 'commit') self.assertEqual(kwargs['object'], test_sha) create_ref_mock.assert_called_with( ref='refs/tags/{}'.format(test_tag), sha=test_sha)
def test_create_icc_user(self, get_random_string_mock, configuration_helpers_mock, mock_post, get_user_mock): """ Testing _create_icc_user method. """ data = { 'user_email': 'test-email', } user_mock = Mock() user_mock.username = '******' user_mock.email = 'user-test-email' user_mock.first_name = 'user-test-firstname' user_mock.last_name = 'user-test-lastname' get_user_mock.return_value = (user_mock, Mock()) get_random_string_mock.return_value = 'test-password' configuration_helpers_mock.get_value.return_value = 'test-auth-method' mock_post.return_value.content = '''<?xml version="1.0" encoding="UTF-8" ?> <RESPONSE> <MULTIPLE> <SINGLE> <KEY name="id"> <VALUE>1223</VALUE> </KEY> <KEY name="username"> <VALUE>testuser</VALUE> </KEY> </SINGLE> </MULTIPLE> </RESPONSE>''' expected_icc_user = { 'id': '1223', 'username': '******', } self.assertEqual( self.base._create_icc_user(data, False), # pylint: disable=protected-access expected_icc_user, ) get_random_string_mock.assert_called_once() get_user_mock.assert_called_once_with(email=data.get('user_email'))
def test_should_send_correct_activaton_email_in_html_format_in_french( self): site = get_current_site(None) user = Mock(spec=User) user.email = '*****@*****.**' user.id = 1 user.first_name = "test" language_code = "fr" with patch( "django.contrib.auth.tokens.default_token_generator.make_token" ) as make_token: make_token.return_value = "token" send_email_to_data_sender(user, language_code) emails = [mail.outbox.pop() for i in range(len(mail.outbox))] self.assertEqual(1, len(emails)) sent_email = emails[0] self.assertEqual("html", sent_email.content_subtype) self.assertEqual(settings.EMAIL_HOST_USER, sent_email.from_email) self.assertEqual(['*****@*****.**'], sent_email.to) self.assertEqual([settings.HNI_SUPPORT_EMAIL_ID], sent_email.bcc) ctx_dict = { 'domain': site.domain, 'uid': int_to_base36(user.id), 'user': user, 'token': "token", 'protocol': 'http', 'site': site, } self.assertEqual( render_to_string( 'activatedatasenderemail/activation_email_subject_for_data_sender_account_fr.txt' ), sent_email.subject) self.assertEqual( render_to_string( 'activatedatasenderemail/activation_email_for_data_sender_account_fr.html', ctx_dict), sent_email.body)
def test_create_icc_user_fail(self, get_random_string_mock, configuration_helpers_mock, mock_post, get_user_mock): """ Testing fail _create_icc_user method. """ data = { 'user_email': 'test-email', } user_mock = Mock() user_mock.username = '******' user_mock.email = 'user-test-email' user_mock.first_name = 'user-test-firstname' user_mock.last_name = 'user-test-lastname' get_user_mock.return_value = (user_mock, Mock()) get_random_string_mock.return_value = 'test-password' configuration_helpers_mock.get_value.return_value = 'test-auth-method' mock_post.side_effect = Exception('Test') self.assertEqual( self.base._create_icc_user(data, False), # pylint: disable=protected-access {}, )
def test_send_if_everything_is_okay(): """Test whether we call the send_email() if every condition is okay""" with patch('h.notification.reply_template.Annotation') as mock_annotation: mock_annotation.fetch = MagicMock(side_effect=fake_fetch) request = DummyRequest() request.domain = 'www.howtoreachtheark.now' annotation = store_fake_data[1] event = events.AnnotationEvent(request, annotation, 'create') with patch('h.notification.reply_template.Subscriptions') as mock_subs: mock_subs.get_active_subscriptions_for_a_type.return_value = [ MockSubscription(id=1, uri='acct:[email protected]') ] with patch('h.notification.reply_template.check_conditions') as mock_conditions: mock_conditions.return_value = True with patch('h.notification.reply_template.render') as mock_render: mock_render.return_value = '' with patch('h.notification.reply_template.get_user_by_name') as mock_user_db: user = Mock() user.email = '*****@*****.**' mock_user_db.return_value = user with patch('h.notification.reply_template.send_email') as mock_mail: rt.send_notifications(event) assert mock_mail.called is True
def test_process(self, mock_get_user, mock_get_commit, mock_commit_hunk_init, mock_put_multi, mock_get_repo, mock_commit_init): """Ensure process_commit saves a Commit and CommitHunks to the datastore. """ repo = repository.Repository(id=123, name='foo') mock_get_repo.return_value = repo mock_commit_init.get_by_id.return_value = None mock_author = Mock() mock_author.id = 900 mock_author.date = datetime.now() mock_author.name = 'Bruce Lee' mock_author.email = '*****@*****.**' mock_committer = Mock() mock_committer.id = 900 mock_committer.date = datetime.now() mock_committer.name = 'Bruce Lee' mock_committer.email = '*****@*****.**' mock_commit_prop = Mock() mock_commit_prop.author = mock_author mock_commit_prop.committer = mock_committer mock_commit_prop.message = 'blah' mock_commit = Mock() mock_commit.commit = mock_commit_prop file1 = Mock() file1.filename = 'file1.py' file1.patch = '@@ -0,0 +1,4 @@ def main(): \n\n' file2 = Mock() file2.filename = 'file2.py' file2.patch = '@@ -14,4 +14,3 @@ def foo(bar): \n\n' mock_commit.files = [file1, file2] mock_author_user = Mock() mock_author_user.id = '123' mock_commit.author = mock_author mock_commit.sha = 'abc' mock_committer_user = Mock() mock_committer_user.id = '123' mock_commit.committer = mock_committer mock_get_commit.return_value = mock_commit commit = Mock() commit.key = Mock() commit.author_date = mock_author.date mock_commit_init.return_value = commit owner_token = 'token' user = User(id=123) user.github_token = owner_token mock_get_user.return_value = user commit_hunks = [Mock(), Mock()] mock_commit_hunk_init.side_effect = commit_hunks repo_id = '123' commit_id = 'abc' repository.process_commit(repo_id, commit_id, user.key.id()) mock_get_repo.assert_called_once_with(repo_id) mock_commit_init.get_by_id.assert_called_once_with(commit_id, parent=repo.key) mock_get_commit.assert_called_once_with(repo.name, commit_id, owner_token) self.assertEqual([call(user.key.id()), call('github_%s' % mock_author.id), call('github_%s' % mock_committer.id)], mock_get_user.call_args_list) mock_commit_init.assert_called_once_with( id=commit_id, parent=repo.key, author=user.key, author_name=mock_author.name, author_email=mock_author.email, author_date=mock_author.date, committer=user.key, committer_name=mock_committer.name, committer_email=mock_committer.email, committer_date=mock_committer.date, message=mock_commit_prop.message ) mock_commit_init.return_value.put.assert_called_once_with() expected = [call(parent=commit.key, commit=commit.key, filename='file1.py', lines=[1, 2, 3, 4], timestamp=mock_author.date), call(parent=commit.key, commit=commit.key, filename='file2.py', lines=[14, 15, 16], timestamp=mock_author.date)] self.assertEqual(expected, mock_commit_hunk_init.call_args_list) mock_put_multi.assert_called_once_with(commit_hunks)
def xtest_create_extended_resource_container(self): mock_clients = self._create_service_mock('resource_registry') self.clients = mock_clients self.container = Mock() extended_resource_handler = ExtendedResourceContainer( self, mock_clients.resource_registry) instrument_device = Mock() instrument_device._id = '123' instrument_device.name = "MyInstrument" instrument_device.type_ = RT.TestInstrument instrument_device.lcstate = LCS.DRAFT instrument_device.availability = AS.PRIVATE instrument_device2 = Mock() instrument_device2._id = '456' instrument_device2.name = "MyInstrument2" instrument_device2.type_ = RT.TestInstrument actor_identity = Mock() actor_identity._id = '111' actor_identity.name = "Foo" actor_identity.type_ = RT.ActorIdentity actor_identity = Mock() actor_identity._id = '1112' actor_identity.name = "Foo2" actor_identity.type_ = RT.ActorIdentity user_info = Mock() user_info._id = '444' user_info.name = "John Doe" user_info.email = "*****@*****.**" user_info.phone = "555-555-5555" user_info.variables = [{ "name": "subscribeToMailingList", "value": "False" }] user_info2 = Mock() user_info2._id = '445' user_info2.name = "aka Evil Twin" user_info2.email = "*****@*****.**" user_info2.phone = "555-555-5555" user_info2.variables = [{ "name": "subscribeToMailingList", "value": "False" }] # ActorIdentity to UserInfo association actor_identity_to_info_association = Mock() actor_identity_to_info_association._id = '555' actor_identity_to_info_association.s = "111" actor_identity_to_info_association.st = RT.ActorIdentity actor_identity_to_info_association.p = PRED.hasInfo actor_identity_to_info_association.o = "444" actor_identity_to_info_association.ot = RT.UserInfo # ActorIdentity to UserInfo association actor_identity_to_info_association2 = Mock() actor_identity_to_info_association2._id = '556' actor_identity_to_info_association2.s = "1112" actor_identity_to_info_association2.st = RT.ActorIdentity actor_identity_to_info_association2.p = PRED.hasInfo actor_identity_to_info_association2.o = "445" actor_identity_to_info_association2.ot = RT.UserInfo # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association = Mock() Instrument_device_to_actor_identity_association._id = '666' Instrument_device_to_actor_identity_association.s = "123" Instrument_device_to_actor_identity_association.st = RT.TestInstrument Instrument_device_to_actor_identity_association.p = PRED.hasOwner Instrument_device_to_actor_identity_association.o = "111" Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association2 = Mock() Instrument_device_to_actor_identity_association2._id = '667' Instrument_device_to_actor_identity_association2.s = "456" Instrument_device_to_actor_identity_association2.st = RT.TestInstrument Instrument_device_to_actor_identity_association2.p = PRED.hasOwner Instrument_device_to_actor_identity_association2.o = "111" Instrument_device_to_actor_identity_association2.ot = RT.ActorIdentity with self.assertRaises(BadRequest) as cm: extended_user = extended_resource_handler.create_extended_resource_container( RT.ActorIdentity, '111') self.assertIn( 'The requested resource ActorIdentity is not extended from ResourceContainer', cm.exception.message) mock_clients.resource_registry.read.return_value = instrument_device mock_clients.resource_registry.find_objects.return_value = ([ actor_identity ], [Instrument_device_to_actor_identity_association]) mock_clients.resource_registry.find_subjects.return_value = (None, None) mock_clients.resource_registry.find_associations.return_value = [ actor_identity_to_info_association, Instrument_device_to_actor_identity_association ] mock_clients.resource_registry.read_mult.return_value = [user_info] extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResource, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 2) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.TestInstrument) self.assertEquals(extended_res.resource_object.name, 'TestSystem_Resource') self.assertEquals(extended_res.owner_count, 2) self.assertEquals(extended_res.single_owner.name, user_info.name) self.assertEquals(len(extended_res.lcstate_transitions), 6) self.assertEquals( set(extended_res.lcstate_transitions.keys()), set(['develop', 'deploy', 'retire', 'plan', 'integrate', 'delete'])) self.assertEquals(len(extended_res.availability_transitions), 2) self.assertEquals(set(extended_res.availability_transitions.keys()), set(['enable', 'announce'])) extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResourceDevice, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 2) with self.assertRaises(Inconsistent) as cm: extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResourceBad, '123') #Test adding extra paramaters to methods extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResource, '123', resource_name='AltSystem_Resource') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 2) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.TestInstrument) self.assertEquals(extended_res.resource_object.name, 'AltSystem_Resource') #Test field exclusion extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResource, '123', ext_exclude=['owners']) self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 0) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.TestInstrument) #Test the list of ids interface extended_res_list = extended_resource_handler.create_extended_resource_container_list( OT.TestExtendedResource, ['123', '456']) self.assertEqual(len(extended_res_list), 2) self.assertEquals(extended_res_list[0].resource, instrument_device) self.assertEquals(len(extended_res_list[0].owners), 2) self.assertEquals(extended_res_list[0].resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.TestInstrument) #Test create_prepare_update_resource prepare_create = extended_resource_handler.create_prepare_resource_support( prepare_resource_type=OT.TestPrepareUpdateResource) self.assertEqual(prepare_create.type_, OT.TestPrepareUpdateResource) self.assertEqual(prepare_create._id, '') prepare_update = extended_resource_handler.create_prepare_resource_support( resource_id='123', prepare_resource_type=OT.TestPrepareUpdateResource) self.assertEqual(prepare_update.type_, OT.TestPrepareUpdateResource) self.assertEqual(prepare_update._id, '123')
def test_create_extended_resource_container(self): mock_clients = self._create_service_mock('resource_registry') self.clients = mock_clients self.container = Mock() extended_resource_handler = ExtendedResourceContainer(self, mock_clients.resource_registry) instrument_device = Mock() instrument_device._id = '123' instrument_device.name = "MyInstrument" instrument_device.type_ = RT.InstrumentDevice instrument_device.lcstate = LCS.DRAFT instrument_device.availability = AS.PRIVATE instrument_device2 = Mock() instrument_device2._id = '456' instrument_device2.name = "MyInstrument2" instrument_device2.type_ = RT.InstrumentDevice actor_identity = Mock() actor_identity._id = '111' actor_identity.name = "Foo" actor_identity.type_ = RT.ActorIdentity actor_identity = Mock() actor_identity._id = '1112' actor_identity.name = "Foo2" actor_identity.type_ = RT.ActorIdentity user_info = Mock() user_info._id = '444' user_info.name = "John Doe" user_info.email = "*****@*****.**" user_info.phone = "555-555-5555" user_info.variables = [{"name": "subscribeToMailingList", "value": "False"}] user_info2 = Mock() user_info2._id = '445' user_info2.name = "aka Evil Twin" user_info2.email = "*****@*****.**" user_info2.phone = "555-555-5555" user_info2.variables = [{"name": "subscribeToMailingList", "value": "False"}] # ActorIdentity to UserInfo association actor_identity_to_info_association = Mock() actor_identity_to_info_association._id = '555' actor_identity_to_info_association.s = "111" actor_identity_to_info_association.st = RT.ActorIdentity actor_identity_to_info_association.p = PRED.hasInfo actor_identity_to_info_association.o = "444" actor_identity_to_info_association.ot = RT.UserInfo # ActorIdentity to UserInfo association actor_identity_to_info_association2 = Mock() actor_identity_to_info_association2._id = '556' actor_identity_to_info_association2.s = "1112" actor_identity_to_info_association2.st = RT.ActorIdentity actor_identity_to_info_association2.p = PRED.hasInfo actor_identity_to_info_association2.o = "445" actor_identity_to_info_association2.ot = RT.UserInfo # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association = Mock() Instrument_device_to_actor_identity_association._id = '666' Instrument_device_to_actor_identity_association.s = "123" Instrument_device_to_actor_identity_association.st = RT.InstrumentDevice Instrument_device_to_actor_identity_association.p = PRED.hasOwner Instrument_device_to_actor_identity_association.o = "111" Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association2 = Mock() Instrument_device_to_actor_identity_association2._id = '667' Instrument_device_to_actor_identity_association2.s = "456" Instrument_device_to_actor_identity_association2.st = RT.InstrumentDevice Instrument_device_to_actor_identity_association2.p = PRED.hasOwner Instrument_device_to_actor_identity_association2.o = "111" Instrument_device_to_actor_identity_association2.ot = RT.ActorIdentity with self.assertRaises(BadRequest) as cm: extended_user = extended_resource_handler.create_extended_resource_container(RT.ActorIdentity, '111') self.assertIn( 'The requested resource ActorIdentity is not extended from ResourceContainer',cm.exception.message) mock_clients.resource_registry.read.return_value = instrument_device mock_clients.resource_registry.find_objects.return_value = ([actor_identity], [Instrument_device_to_actor_identity_association]) mock_clients.resource_registry.find_subjects.return_value = (None,None) mock_clients.resource_registry.find_associations.return_value = [actor_identity_to_info_association, Instrument_device_to_actor_identity_association] mock_clients.resource_registry.read_mult.return_value = [user_info] extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),2) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) self.assertEquals(extended_res.resource_object.name, 'TestSystem_Resource') self.assertEquals(extended_res.owner_count, 2) self.assertEquals(extended_res.single_owner.name, user_info.name) self.assertEquals(len(extended_res.lcstate_transitions), 6) self.assertEquals(set(extended_res.lcstate_transitions.keys()), set(['develop', 'deploy', 'retire', 'plan', 'integrate', 'delete'])) self.assertEquals(len(extended_res.availability_transitions), 2) self.assertEquals(set(extended_res.availability_transitions.keys()), set(['enable', 'announce'])) extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResourceDevice, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),2) with self.assertRaises(Inconsistent) as cm: extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResourceBad, '123') #Test adding extra paramaters to methods extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123', resource_name='AltSystem_Resource') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),2) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) self.assertEquals(extended_res.resource_object.name, 'AltSystem_Resource') #Test field exclusion extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123',ext_exclude=['owners']) self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),0) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) #Test the list of ids interface extended_res_list = extended_resource_handler.create_extended_resource_container_list(OT.TestExtendedResource, ['123','456']) self.assertEqual(len(extended_res_list), 2) self.assertEquals(extended_res_list[0].resource, instrument_device) self.assertEquals(len(extended_res_list[0].owners),2) self.assertEquals(extended_res_list[0].resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) #Test create_prepare_update_resource prepare_create = extended_resource_handler.create_prepare_resource_support(prepare_resource_type=OT.TestPrepareUpdateResource) self.assertEqual(prepare_create.type_, OT.TestPrepareUpdateResource) self.assertEqual(prepare_create._id, '') prepare_update = extended_resource_handler.create_prepare_resource_support(resource_id='123',prepare_resource_type=OT.TestPrepareUpdateResource) self.assertEqual(prepare_update.type_, OT.TestPrepareUpdateResource) self.assertEqual(prepare_update._id, '123')
def get_maintainer(self): maint = Mock() maint.email = '*****@*****.**' maint.name = 'John Foo' return maint
def test_create_extended_resource_container(self): mock_clients = self._create_service_mock('resource_registry') self.clients = mock_clients extended_resource_handler = ExtendedResourceContainer(self, mock_clients.resource_registry) instrument_device = Mock() instrument_device._id = '123' instrument_device.name = "MyInstrument" instrument_device.type_ = RT.InstrumentDevice actor_identity = Mock() actor_identity._id = '111' actor_identity.name = "Foo" actor_identity.type_ = RT.ActorIdentity user_info = Mock() user_info.name = "John Doe" user_info.email = "*****@*****.**" user_info.phone = "555-555-5555" user_info.variables = [{"name": "subscribeToMailingList", "value": "False"}] # ActorIdentity to UserInfo association actor_identity_to_info_association = Mock() actor_identity_to_info_association._id = '555' actor_identity_to_info_association.s = "111" actor_identity_to_info_association.st = RT.ActorIdentity actor_identity_to_info_association.p = PRED.hasInfo actor_identity_to_info_association.o = "444" actor_identity_to_info_association.ot = RT.UserInfo # ActorIdentity to UserInfo association Instrument_device_to_actor_identity_association = Mock() Instrument_device_to_actor_identity_association._id = '666' Instrument_device_to_actor_identity_association.s = "123" Instrument_device_to_actor_identity_association.st = RT.InstumentDevice Instrument_device_to_actor_identity_association.p = PRED.hasOwner Instrument_device_to_actor_identity_association.o = "111" Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity with self.assertRaises(BadRequest) as cm: extended_user = extended_resource_handler.create_extended_resource_container(RT.ActorIdentity, '111') self.assertIn( 'Requested resource ActorIdentity is not extended from ResourceContainer',cm.exception.message) obj = IonObject(OT.TestExtendedResource) list_objs = ['123', '456', '789'] extended_resource_handler.set_field_associations(obj, 'policies', list_objs) extended_resource_handler.set_field_associations(obj, 'policy_count', list_objs) extended_resource_handler.set_field_associations(obj, 'resource_object', list_objs) self.assertEquals(obj.policies, list_objs) self.assertEquals(obj.policy_count, 3) self.assertEquals(obj.resource_object, '123') mock_clients.resource_registry.read.return_value = instrument_device mock_clients.resource_registry.find_objects.return_value = ([actor_identity], [Instrument_device_to_actor_identity_association]) extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),1) #Test field exclusion extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123',ext_exclude=['owners']) self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),0)
def test_create_extended_resource_container(self): mock_clients = self._create_service_mock('resource_registry') self.clients = mock_clients self.container = Mock() extended_resource_handler = ExtendedResourceContainer(self, mock_clients.resource_registry) instrument_device = Mock() instrument_device._id = '123' instrument_device.name = "MyInstrument" instrument_device.type_ = RT.InstrumentDevice instrument_device2 = Mock() instrument_device2._id = '456' instrument_device2.name = "MyInstrument2" instrument_device2.type_ = RT.InstrumentDevice actor_identity = Mock() actor_identity._id = '111' actor_identity.name = "Foo" actor_identity.type_ = RT.ActorIdentity user_info = Mock() user_info._id = '444' user_info.name = "John Doe" user_info.email = "*****@*****.**" user_info.phone = "555-555-5555" user_info.variables = [{"name": "subscribeToMailingList", "value": "False"}] user_info2 = Mock() user_info2._id = '445' user_info2.name = "aka Evil Twin" user_info2.email = "*****@*****.**" user_info2.phone = "555-555-5555" user_info2.variables = [{"name": "subscribeToMailingList", "value": "False"}] # ActorIdentity to UserInfo association actor_identity_to_info_association = Mock() actor_identity_to_info_association._id = '555' actor_identity_to_info_association.s = "111" actor_identity_to_info_association.st = RT.ActorIdentity actor_identity_to_info_association.p = PRED.hasInfo actor_identity_to_info_association.o = "444" actor_identity_to_info_association.ot = RT.UserInfo # ActorIdentity to UserInfo association actor_identity_to_info_association2 = Mock() actor_identity_to_info_association2._id = '556' actor_identity_to_info_association2.s = "111" actor_identity_to_info_association2.st = RT.ActorIdentity actor_identity_to_info_association2.p = PRED.hasInfo actor_identity_to_info_association2.o = "445" actor_identity_to_info_association2.ot = RT.UserInfo # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association = Mock() Instrument_device_to_actor_identity_association._id = '666' Instrument_device_to_actor_identity_association.s = "123" Instrument_device_to_actor_identity_association.st = RT.InstumentDevice Instrument_device_to_actor_identity_association.p = PRED.hasOwner Instrument_device_to_actor_identity_association.o = "111" Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association2 = Mock() Instrument_device_to_actor_identity_association2._id = '667' Instrument_device_to_actor_identity_association2.s = "456" Instrument_device_to_actor_identity_association2.st = RT.InstumentDevice Instrument_device_to_actor_identity_association2.p = PRED.hasOwner Instrument_device_to_actor_identity_association2.o = "111" Instrument_device_to_actor_identity_association2.ot = RT.ActorIdentity with self.assertRaises(BadRequest) as cm: extended_user = extended_resource_handler.create_extended_resource_container(RT.ActorIdentity, '111') self.assertIn( 'The requested resource ActorIdentity is not extended from ResourceContainer',cm.exception.message) obj = IonObject(OT.TestExtendedResource) list_objs = ['123', '456', '789'] extended_resource_handler.set_field_associations(obj, 'policies', list_objs) extended_resource_handler.set_field_associations(obj, 'policy_count', list_objs) extended_resource_handler.set_field_associations(obj, 'resource_object', list_objs) self.assertEquals(obj.policies, list_objs) self.assertEquals(obj.policy_count, 3) self.assertEquals(obj.resource_object, '123') mock_clients.resource_registry.read.return_value = instrument_device mock_clients.resource_registry.find_objects.return_value = ([actor_identity], [Instrument_device_to_actor_identity_association]) mock_clients.resource_registry.find_subjects.return_value = (None,None) extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),1) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) #Test field exclusion extended_res = extended_resource_handler.create_extended_resource_container(OT.TestExtendedResource, '123',ext_exclude=['owners']) self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners),0) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) #Test the list of ids interface extended_res_list = extended_resource_handler.create_extended_resource_container_list(OT.TestExtendedResource, ['123','456']) self.assertEqual(len(extended_res_list), 2) self.assertEquals(extended_res_list[0].resource, instrument_device) self.assertEquals(len(extended_res_list[0].owners),1) self.assertEquals(extended_res_list[0].resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
def get_user_info(self, user): info = Mock() info.email = '*****@*****.**' return info
def _get_user_mock(email): user = Mock(spec=User) user.email = email return user
def test_create_extended_resource_container(self): mock_clients = self._create_service_mock('resource_registry') self.clients = mock_clients self.container = Mock() extended_resource_handler = ExtendedResourceContainer( self, mock_clients.resource_registry) instrument_device = Mock() instrument_device._id = '123' instrument_device.name = "MyInstrument" instrument_device.type_ = RT.InstrumentDevice instrument_device2 = Mock() instrument_device2._id = '456' instrument_device2.name = "MyInstrument2" instrument_device2.type_ = RT.InstrumentDevice actor_identity = Mock() actor_identity._id = '111' actor_identity.name = "Foo" actor_identity.type_ = RT.ActorIdentity user_info = Mock() user_info._id = '444' user_info.name = "John Doe" user_info.email = "*****@*****.**" user_info.phone = "555-555-5555" user_info.variables = [{ "name": "subscribeToMailingList", "value": "False" }] user_info2 = Mock() user_info2._id = '445' user_info2.name = "aka Evil Twin" user_info2.email = "*****@*****.**" user_info2.phone = "555-555-5555" user_info2.variables = [{ "name": "subscribeToMailingList", "value": "False" }] # ActorIdentity to UserInfo association actor_identity_to_info_association = Mock() actor_identity_to_info_association._id = '555' actor_identity_to_info_association.s = "111" actor_identity_to_info_association.st = RT.ActorIdentity actor_identity_to_info_association.p = PRED.hasInfo actor_identity_to_info_association.o = "444" actor_identity_to_info_association.ot = RT.UserInfo # ActorIdentity to UserInfo association actor_identity_to_info_association2 = Mock() actor_identity_to_info_association2._id = '556' actor_identity_to_info_association2.s = "111" actor_identity_to_info_association2.st = RT.ActorIdentity actor_identity_to_info_association2.p = PRED.hasInfo actor_identity_to_info_association2.o = "445" actor_identity_to_info_association2.ot = RT.UserInfo # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association = Mock() Instrument_device_to_actor_identity_association._id = '666' Instrument_device_to_actor_identity_association.s = "123" Instrument_device_to_actor_identity_association.st = RT.InstumentDevice Instrument_device_to_actor_identity_association.p = PRED.hasOwner Instrument_device_to_actor_identity_association.o = "111" Instrument_device_to_actor_identity_association.ot = RT.ActorIdentity # ActorIdentity to Instrument Device association Instrument_device_to_actor_identity_association2 = Mock() Instrument_device_to_actor_identity_association2._id = '667' Instrument_device_to_actor_identity_association2.s = "456" Instrument_device_to_actor_identity_association2.st = RT.InstumentDevice Instrument_device_to_actor_identity_association2.p = PRED.hasOwner Instrument_device_to_actor_identity_association2.o = "111" Instrument_device_to_actor_identity_association2.ot = RT.ActorIdentity with self.assertRaises(BadRequest) as cm: extended_user = extended_resource_handler.create_extended_resource_container( RT.ActorIdentity, '111') self.assertIn( 'The requested resource ActorIdentity is not extended from ResourceContainer', cm.exception.message) mock_clients.resource_registry.read.return_value = instrument_device mock_clients.resource_registry.find_objects.return_value = ([ actor_identity ], [Instrument_device_to_actor_identity_association]) mock_clients.resource_registry.find_subjects.return_value = (None, None) mock_clients.resource_registry.find_associations.return_value = [ actor_identity_to_info_association, Instrument_device_to_actor_identity_association ] mock_clients.resource_registry.read_mult.return_value = [user_info] extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResource, '123') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 1) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) self.assertEquals(extended_res.resource_object.name, 'TestSystem_Resource') #Test adding extra paramaters to methods extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResource, '123', resource_name='AltSystem_Resource') self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 1) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) self.assertEquals(extended_res.resource_object.name, 'AltSystem_Resource') #Test field exclusion extended_res = extended_resource_handler.create_extended_resource_container( OT.TestExtendedResource, '123', ext_exclude=['owners']) self.assertEquals(extended_res.resource, instrument_device) self.assertEquals(len(extended_res.owners), 0) self.assertEquals(extended_res.resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice) #Test the list of ids interface extended_res_list = extended_resource_handler.create_extended_resource_container_list( OT.TestExtendedResource, ['123', '456']) self.assertEqual(len(extended_res_list), 2) self.assertEquals(extended_res_list[0].resource, instrument_device) self.assertEquals(len(extended_res_list[0].owners), 1) self.assertEquals(extended_res_list[0].resource_object.type_, RT.SystemResource) self.assertEquals(extended_res.remote_resource_object.type_, RT.InstrumentDevice)
def get_maintainer(self): maint = Mock() maint.email = "*****@*****.**" maint.name = "John Foo" return maint
def mock_google_account_user(self): google_account_user = Mock() google_account_user.user_id = lambda: '123' google_account_user.email = lambda: '*****@*****.**' google_account_user.nickname = lambda: 'foo' return google_account_user