def test_dataset_subscribe_default_credentials(self, mocked_credentials, mock_display_form, mock_subscription_ids): # Given expected_credentials = Credentials('fake_user', '1234') mocked_credentials.return_value = expected_credentials dataset = Dataset(db_dataset1) # When dataset.subscribe() # Then mock_subscription_ids.assert_called_once_with(expected_credentials) mock_display_form.assert_called_once_with(db_dataset1['id'], 'dataset', expected_credentials)
def test_dataset_subscribe_wrong_credentials(self): # Given wrong_credentials = 1234 dataset = Dataset(db_dataset1) # When with pytest.raises(ValueError) as e: dataset.subscribe(wrong_credentials) # Then assert str(e.value) == ('Credentials attribute is required. ' 'Please pass a `Credentials` instance ' 'or use the `set_default_credentials` function.')
def test_dataset_subscribe_existing(self, mock_display_message, mock_display_form, mock_subscription_ids): # Given expected_id = db_dataset1['id'] expected_subscribed_ids = [expected_id] mock_subscription_ids.return_value = expected_subscribed_ids credentials = Credentials('fake_user', '1234') dataset = Dataset(db_dataset1) # When dataset.subscribe(credentials) # Then mock_subscription_ids.assert_called_once_with(credentials) mock_display_message.assert_called_once_with(expected_id, 'dataset') assert not mock_display_form.called
def test_dataset_subscribe_without_do_enabled(self, mock_display_form, mock_subscription_ids): # Given def raise_exception(a, b, c): raise ServerErrorException(['The user does not have Data Observatory enabled']) mock_display_form.side_effect = raise_exception dataset = Dataset(db_dataset1) credentials = Credentials('fake_user', '1234') # When with pytest.raises(Exception) as e: dataset.subscribe(credentials) # Then assert str(e.value) == ( 'We are sorry, the Data Observatory is not enabled for your account yet. ' 'Please contact your customer success manager or send an email to ' '[email protected] to request access to it.')