示例#1
0
    def test_no_contacts_in_context(self):

        factory = RequestFactory()
        request = factory.get('/')

        response = ContactListView.as_view()(request)

        self.assertEqual(list(response.context_data['object_list']), [])
示例#2
0
文件: tests.py 项目: rwisecar/Pyphon
 def test_contact_list_view_status(self):
     """Test that contact list view returns 200 OK response."""
     user1 = User()
     user1.save()
     view = ContactListView.as_view()
     req = self.request.get(reverse_lazy("contacts"))
     req.user = user1
     response = view(req)
     self.assertEqual(response.status_code, 200)
示例#3
0
 def test_contacts_in_context(self):
     factory = RequestFactory()
     request = factory.get('/')
     
     c = Contact.objects.create(first_name = 'Joey', last_name = 'Smith',
             email = '*****@*****.**')
     
     response = ContactListView.as_view()(request)
     
     self.assertEquals( list(response.context_data['object_list']), [c],)
示例#4
0
 def test_no_contacts_in_context(self):
     factory = RequestFactory()
     request = factory.get('/')
     
     response = ContactListView.as_view()(request)
     
     self.assertEquals(
         list(response.context_data['object_list']), 
         [],
     )
示例#5
0
    def test_contacts_in_context(self):

        factory = RequestFactory()
        request = factory.get('/')

        # 手动插入一条数据
        c = Contact.objects.create(first_name='qing',
                                   last_name='yi',
                                   email='*****@*****.**')
        response = ContactListView.as_view()(request)

        self.assertEqual(list(response.context_data['object_list']), [c])
示例#6
0
	def test_contacts_in_context(self):
		factory = RequestFactory()
		request = factory.get('/')
		
		c = Contact.objects.create(first_name='Mike')
		
		response = ContactListView.as_view()(request)

		self.assertEquals(
			list(response.context_data['object_list']),
			[c],
		)
示例#7
0
文件: tests.py 项目: rwisecar/Pyphon
 def test_contact_list_view_returns_contact(self):
     """Test that contact list view returns 200 OK response."""
     user1 = User()
     user1.save()
     jabba = Contact(name="Jabba", number="+1234567890")
     jabba.save()
     view = ContactListView.as_view()
     req = self.request.get(reverse_lazy("contacts"))
     req.user = user1
     contacts = Contact.objects.all()
     response = view(req, {"contacts": contacts})
     contact = response.context_data['contacts'][0]
     self.assertTrue(contact.name == "Jabba")
示例#8
0
    def test_contacts_in_context(self):

        factory = RequestFactory()
        request = factory.get('/')

        c = Contact.objects.create(first_name='Joe',
                                   last_name='Smith',
                                   email='*****@*****.**')

        response = ContactListView.as_view()(request)

        self.assertEquals(
            list(response.context_data['object_list']),
            [c],
        )
示例#9
0
    def test_contacts_in_context(self):

        factory = RequestFactory()
        request = factory.get('/')

        # 手动插入一条数据
        c = Contact.objects.create(
            first_name='qing',
            last_name = 'yi',
            email = '*****@*****.**'
        )
        response = ContactListView.as_view()(request)

        self.assertEqual(
            list(response.context_data['object_list']),
            [c]
        )
示例#10
0
from django.urls import path
from contacts.views import (
    IndexView,
    ContactListView,
    ContactDetailsView,
    ContactTypeListView,
    ContactTypeDetailsView,
)

app_name = 'contacts'
urlpatterns = [
    path('', IndexView.as_view(), name='index'),
    path('api/v1/contacts/', ContactListView.as_view()),
    path('api/v1/contacts/<int:pk>/', ContactDetailsView.as_view()),
    path('api/v1/contacts-type/', ContactListView.as_view()),
    path('api/v1/contacts-type/<int:pk>/', ContactDetailsView.as_view()),
]
示例#11
0
from django.urls import path, include
from rest_framework.routers import DefaultRouter

from contacts.views import ContactViewSet, ContactListView

router = DefaultRouter()
router.register(r'contacts', ContactViewSet, basename='contact')

urlpatterns = [
    path('', ContactListView.as_view(), name='contacts-list'),
    path('api/', include(router.urls)),
]
示例#12
0
文件: urls.py 项目: rwisecar/Pyphon
from django.conf.urls import url
from contacts.views import ContactIdView, ContactListView, ContactAddView, ContactEditView

urlpatterns = [
    url(r'^(?P<pk>\d+)/$', ContactIdView.as_view(), name="contact_detail"),
    url(r'^$', ContactListView.as_view(), name='contacts'),
    url(r'^new/$', ContactAddView.as_view(), name='new_contact'),
    url(r'^(?P<pk>\d+)/edit/$', ContactEditView.as_view(), name='edit_contact'),
]
示例#13
0
文件: urls.py 项目: shoa3b/accounts
from django.urls import path

from contacts.views import (ContactDetail, ContactListView, ContactUpdate,
                            CreateContact)

app_name = "contacts"
urlpatterns = [
    path("", ContactListView.as_view(), name="list"),
    path("create", CreateContact.as_view(), name="create"),
    path("<int:pk>", ContactDetail.as_view(), name="detail"),
    path("edit/<int:pk>", ContactUpdate.as_view(), name="edit"),
]
示例#14
0
from django.contrib import admin
from django.urls import path, include
from contacts.views import ContactCreateView, ContactListView, ContactSlugView, ContactEditView, ContactDeleteView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('contacts/', ContactListView.as_view(), name='test'),
    path('create_contact/', ContactCreateView.as_view(), name='create'),
    path('contact/<slug:slug>', ContactSlugView.as_view(), name='slug_view'),
    path('edit_contact/<slug:slug>',
         ContactEditView.as_view(),
         name='edit_view'),
    path('delete_contact/<slug:slug>',
         ContactDeleteView.as_view(),
         name='edit_view'),
    path('api-auth/', include('rest_framework.urls'))
]