def test_if_data_on_page(self): """Check if data renders on page. """ contact = self.model.objects.last() request = self.factory.get(path=self.fake_path) response = ContactView.as_view()(request) response_content = response.render().content db_data = json.loads( serializers.serialize('json', [contact, ]) )[0]['fields'] self.assertEqual(response.context_data['contact'], contact) for value in [el for el in db_data.values()]: self.assertIn(value, response_content)
def test_contact_page_when_2_records_in_db(self): """Check if page don't render second record on page. """ model = self.model(**FAKE_DATA) model.save() self.assertEqual(self.model.objects.count(), 2) request = self.factory.get(path=self.fake_path) response = ContactView.as_view()(request) response_content = response.render().content self.assertEqual(response.status_code, 200) self.assertEqual( response.template_name[0], self.template ) db_data = Contact.objects.all().values()[1] for el in db_data.values()[:-1]: if el: self.assertNotIn(str(el), response_content)
from django.urls import path, include from django.contrib import admin admin.autodiscover() import hello.views from hello.views import HomeView, ChartData, handle_particle_hook, API, TempView, BatteryView, PresView, ContactView, AboutView # To add a new path, first import the app: # import blog # # Then add the new path: # path('blog/', blog.urls, name="blog") # # Learn more here: https://docs.djangoproject.com/en/2.1/topics/http/urls/ urlpatterns = [ path("admin/", admin.site.urls), path("", HomeView.as_view()), path("charts/temp/", TempView.as_view()), path("charts/battery/", BatteryView.as_view()), path("charts/pres/", PresView.as_view()), path("contact/", ContactView.as_view()), path("about/", AboutView.as_view()), path('api/', API.as_view()), path('api/chart/data/', ChartData.as_view()), path('api/webhook/', hello.views.handle_particle_hook, name='handle_particle_hook') ]
from django.conf.urls import patterns, include, url from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf.urls.static import static from django.conf import settings from django.contrib import admin from hello.views import ( ContactView, EditView, LogRequestView, LoginView, LogoutView, ) admin.autodiscover() urlpatterns = patterns( '', url(r'^$', ContactView.as_view(), name='contact'), url(r'^edit/(?P<pk>\d+)/$', EditView.as_view(), name='edit'), url(r'^requests/$', LogRequestView.as_view(), name='requests'), url(r'^login/$', LoginView.as_view(), name='login'), url(r'^logout/$', LogoutView.as_view(), name='logout'), url(r'^admin/', include(admin.site.urls)), ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += staticfiles_urlpatterns()