Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_url_for_resource(self):
from eucaconsole.views.stacks import StackStateView
_register_routes(self.config)
request = testing.DummyRequest()
url = StackStateView.get_url_for_resource(request, 'AWS::ElasticLoadBalancing::LoadBalancer', 'lb-1234')
self.assertEqual(url, '/elbs/lb-1234')
url = StackStateView.get_url_for_resource(request, 'AWS::EC2::SecurityGroup', 'sg-1234')
self.assertEqual(url, '/securitygroups/sg-1234')
url = StackStateView.get_url_for_resource(request, 'AWS::EC2::EIP', '1.2.3.4')
self.assertEqual(url, '/ipaddresses/1.2.3.4')
url = StackStateView.get_url_for_resource(request, 'AWS::EC2::Instance', 'i-1234')
self.assertEqual(url, '/instances/i-1234')
url = StackStateView.get_url_for_resource(request, 'AWS::EC2::Volume', 'vol-1234')
self.assertEqual(url, '/volumes/vol-1234')
session = Session(bind=engine)
Base = declarative_base()
class Entity(Base):
__tablename__ = 'entity'
id = Column(Integer, primary_key=True)
value = Column(String)
Base.metadata.create_all(bind=engine)
session.add_all([
Entity(id=1, value='one'),
Entity(id=2, value='two'),
Entity(id=3, value='three'),
])
session.commit()
class ContextFactory(SQLAlchemyORMContext):
entity = Entity
request = DummyRequest()
request.db_session = session
self.context = ContextFactory(request)
def request_(self, context):
request = testing.DummyRequest()
request.root = context
return request
def test_home_page(self):
from pyramid import testing
from .views import home_page
request = testing.DummyRequest()
info = home_page(request)
self.assertEqual(info, {})
def test_wiki_view(self):
from tutorial.views import WikiViews
request = testing.DummyRequest()
inst = WikiViews(request)
response = inst.wiki_view()
self.assertEqual(response['title'], 'Welcome to the Wiki')
def dummy_request(dbsession):
return testing.DummyRequest(dbsession=dbsession)
def test_reply_query_match():
"""Test if the notifier.send_notifications is called
"""
annotation = {
'user': 'acct:testuser@testdomain',
'permissions': {'read': ["group:__world__"]}
}
request = DummyRequest()
event = events.AnnotationEvent(request, annotation, 'create')
with patch('h.notification.notifier.AnnotationNotifier') as mock_notif:
with patch('h.notification.notifier.parent_values') as mock_parent:
with patch('h.notification.notifier.Subscriptions.get_active_subscriptions') as mock_subs:
mock_subs.return_value = [
Mock(uri='acct:parent@testdomain',
template=types.REPLY_TEMPLATE)
]
mock_parent.return_value = {'user': 'acct:parent@testdomain'}
notifier.send_notifications(event)
assert mock_notif().send_notification_to_owner.call_count == 1
def test_resources_with_name_prefix(self):
from nefertari.resource import add_resource_routes
add_resource_routes(
self.config,
DummyCrudView,
'message',
'messages',
name_prefix="special_"
)
self.assertEqual(
'/messages/1',
route_path('special_message', testing.DummyRequest(), id=1)
)
def test_site_view(self):
request = DummyRequest()
context = DummySite()
inst = self._makeOne(context, request)
result = inst.site_view()
self.assertEqual(len(result['children']), 5)
def test_home_view(self):
from .views import TutorialViews
request = DummyRequest()
title = 'Dummy Context'
context = DummyResource(title=title, __name__='dummy')
inst = TutorialViews(context, request)
result = inst.home()
self.assertIn('Home', result['page_title'])