Exemple #1
0
    def test_get_queryset_calls_through_to_helper(self, mock_helper: Mock):
        # Given a mock get_activities that returns a sentinel
        mock_helper.return_value = sentinel.activity_list

        view = HomePageView()
        view.request = Mock(user=sentinel.user)

        # When getting the queryset for the view
        queryset = view.get_queryset()

        # Then the sentinel will be returned
        assert queryset == sentinel.activity_list

        # and the mock will have been called with the current user
        mock_helper.assert_called_once_with(sentinel.user)
Exemple #2
0
    def test_get_context_data_populates_leaders(self, get_context_mock: Mock,
                                                get_leaders_mock: Mock):
        # Given a mock get_leaders that returns a sentinel
        get_leaders_mock.return_value = sentinel.leaders

        get_context_mock.return_value = dict(super=sentinel.super)

        view = HomePageView()

        # When getting the context for the view
        context = view.get_context_data()

        # Then the context will contain the sentinel
        assert context['leaders'] == sentinel.leaders
        assert context['super'] == sentinel.super
Exemple #3
0
    def setUp(self):
        self.request = RequestFactory().get('/')
        self.view = HomePageView.as_view()

        Headline.objects.create(
            headline='Makers, Bakers, Screenprinters, Homebrewers')
        self.headline = Headline.random_headline.all()

        tempfile.tempdir = os.path.join(base.MEDIA_ROOT, 'clients/logos')
        tf_logo = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
        tf_logo.close()
        self.logo = tf_logo.name
        Client.objects.create(name='Coca-Cola',
                              logo=self.logo,
                              website='http://us.coca-cola.com/home/')
        self.client_list = Client.objects.all()

        tempfile.tempdir = os.path.join(base.MEDIA_ROOT, 'staff/mugshots')
        tf_mugshot = tempfile.NamedTemporaryFile(delete=False, suffix='.jpg')
        tf_mugshot.close()
        self.mugshot = tf_mugshot.name
        Employee.objects.create(first_name='Patrick',
                                middle_name='Scott',
                                last_name='Beeson',
                                title='Director of Digital Strategy',
                                brief_description='Mountains require grit',
                                mugshot=self.mugshot,
                                is_employed=True)
        self.employee_list = Employee.public.all()

        tempfile.tempdir = os.path.join(base.MEDIA_ROOT,
                                        'projects/hero_images')
        tf_hero = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
        tf_hero.close()
        self.hero_image = tf_hero.name
        Project.objects.create(
            name='Lowes Foods',
            slug='lowes-foods',
            description='Lowes Foods is a local grocery store chain.',
            hero_image=self.hero_image,
            is_featured=True,
            status='published')
        self.project_list = Project.featured.all()
Exemple #4
0
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from django.views.decorators.csrf import csrf_exempt, ensure_csrf_cookie
from django.http import HttpResponse

admin.autodiscover()


def yandex(request):
    return HttpResponse('500b3fb7d9ea')


urlpatterns = patterns('',
                       # url(r'^payment?ik_co_id=(?P<ik_co_id>\S+)&ik_inv_id=(?P<ik_inv_id>\S+)&ik_inv_st=(?P<ik_inv_st>\S+)&ik_inv_crt=(?P<ik_inv_crt>\S+)&ik_inv_prc=(?P<ik_inv_prc>\S+)&ik_pm_no=(?P<ik_pm_no>\S+)&ik_pw_via=(?P<ik_pw_via>\S+)&ik_am=(?P<ik_am>\S+)&ik_cur=(?P<ik_cur>\S+)&ik_co_rfn=(?P<ik_co_rfn>\S+)&ik_ps_price=(?P<ik_ps_price>\S+)&ik_desc=(?P<ik_desc>\S+)$)',
                       url(r'^$',
                           HomePageView.as_view()),
                       url(r'^shop/tags/(?P<slug>\w+)$',
                           TagView.as_view(), name='tags'),
                       url(r'^shop/books/(?P<slug>\w+)/buy/$',
                           BuyView.as_view(), name='buy'),
                       url(r'^shop/books/(?P<slug>\w+)$',
                           BookView.as_view(), name='book'),
                       url(r'^shop$', ensure_csrf_cookie(BookList.as_view(template_name='shoplist.html')),
                           name='shop'),

                       url(r'^shop/(?P<author_slug>\w+)$',
                           AuthorBookList.as_view(
                               template_name='shoplist.html'), name='shop-author'),
                       url(r'^shop/(?P<author_slug>[\w-]+)/(?P<category_slug>[\w-]+)$',
                           AuthorBookList.as_view(
                               template_name='shoplist.html'), name='shop-author-category'),
Exemple #5
0
from django.contrib import admin
from django.conf import settings
from django.views.generic.base import TemplateView

from homepage.views import HomePageView
from profiles.views import ProfileRedirectView

admin.autodiscover()
handler404 = 'homepage.views.error_404_view'
handler500 = 'homepage.views.error_500_view'

urlpatterns = patterns('',
    # Examples:
    # url(r'^myapp/', include('myapp.urls')),
    url(r'^$', HomePageView.as_view(), name='home'),
    url(r'^datasets/', include('package.urls')),
    url(r'^grids/', include('grid.urls')),
    url(r'^profiles/', include('profiles.urls')),
    url(r'^publishers/', include('publisher.urls')),
    url(r'^datamap/', include('datamap.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('django.contrib.auth.urls')),
    url(r'^accounts/profile/$', ProfileRedirectView.as_view()),

    # static pages
Exemple #6
0
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

from homepage.views import HomePageView

admin.site.site_header = 'The Variable administration'

urlpatterns = patterns(
    '',
    url(r'^$', HomePageView.as_view(), name='home'),
    url(r'^administration/doc/', include('django.contrib.admindocs.urls')),
    url(r'^administration/', include(admin.site.urls)),
    url(r'^pages/', include('django.contrib.flatpages.urls')),
    url(r'^', include('projects.urls')),
)

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    import debug_toolbar
    urlpatterns += patterns(
        '',
        url(r'^__debug__/', include(debug_toolbar.urls)),
    )
Exemple #7
0
"""Routing for activity related pages"""
from django.conf.urls import url
from django.contrib.auth.decorators import login_required

from activities import views
from homepage.views import HomePageView

app_name = "activities"  # pylint: disable=invalid-name

urlpatterns = [
    url(r'^$', HomePageView.as_view(), name='activity_list'),
    url(r'^upload$', login_required(views.UploadView.as_view()),
        name='upload'),
    url(r'(?P<activity_id>\d+)/tracks/(?P<pk>\d+)/$',
        login_required(views.ActivityTrackView.as_view()),
        name="view_track"),
    url(r'(?P<activity_id>\d+)/tracks/(?P<pk>\d+)/trim$',
        login_required(views.ActivityTrackTrimView.as_view()),
        name="edit_track_trim"),
    url(r'(?P<activity_id>\d+)/tracks/(?P<pk>\d+)/download$',
        login_required(views.ActivityTrackDownloadView.as_view()),
        name="download_track_file"),
    url(r'(?P<activity_id>\d+)/tracks/upload$',
        login_required(views.UploadTrackView.as_view()),
        name='upload_track'),
    url(r'(?P<pk>\d+)/details/$',
        login_required(views.DetailsView.as_view()),
        name='details'),
    url(r'(?P<pk>\d+)/$', views.ActivityView.as_view(), name='view_activity'),
]
Exemple #8
0
The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from homepage.views import HomePageView, LoginView, RegForm, LogoutView, userViewSet
from rest_framework import routers

router = routers.DefaultRouter()
router.register(r'users', userViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', HomePageView.as_view(), name='home'),
    path('login/', LoginView.as_view(), name='login'),
    path('registeration/', RegForm.as_view(), name='registeration'),
    path('logout/', LogoutView.as_view(), name='logout'),
    path('', include(router.urls))
]
Exemple #9
0
"""hellodjango URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

from homepage.views import HomePageView

urlpatterns = [
    path('admin/', admin.site.urls),
    path("", HomePageView.as_view(), name="home"),  # as_view()? 
]