mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 09:57:37 +03:00 
			
		
		
		
	Add tests
This commit is contained in:
		
							parent
							
								
									26dc839fdf
								
							
						
					
					
						commit
						417b618bb6
					
				| 
						 | 
					@ -31,7 +31,7 @@ ALLOWED_HOSTS = []
 | 
				
			||||||
# Application definition
 | 
					# Application definition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INSTALLED_APPS = [
 | 
					INSTALLED_APPS = [
 | 
				
			||||||
    'web.apps.WebConfig',
 | 
					    'githubnavigator.web.apps.WebConfig',
 | 
				
			||||||
    'django.contrib.admin',
 | 
					    'django.contrib.admin',
 | 
				
			||||||
    'django.contrib.auth',
 | 
					    'django.contrib.auth',
 | 
				
			||||||
    'django.contrib.contenttypes',
 | 
					    'django.contrib.contenttypes',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,6 +17,6 @@ from django.contrib import admin
 | 
				
			||||||
from django.urls import path, include
 | 
					from django.urls import path, include
 | 
				
			||||||
 | 
					
 | 
				
			||||||
urlpatterns = [
 | 
					urlpatterns = [
 | 
				
			||||||
    path('', include('web.urls')),
 | 
					    path('', include('githubnavigator.web.urls')),
 | 
				
			||||||
    path('admin/', admin.site.urls),
 | 
					    path('admin/', admin.site.urls),
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,7 +5,7 @@ from . import views
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WebConfig(AppConfig):
 | 
					class WebConfig(AppConfig):
 | 
				
			||||||
    name = 'web'
 | 
					    name = 'githubnavigator.web'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def ready(self):
 | 
					    def ready(self):
 | 
				
			||||||
        container.wire(modules=[views])
 | 
					        container.wire(modules=[views])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,61 @@
 | 
				
			||||||
# from django.test import TestCase
 | 
					from unittest import mock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create your tests here.
 | 
					from django.urls import reverse
 | 
				
			||||||
 | 
					from django.test import TestCase
 | 
				
			||||||
 | 
					from github import Github
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from githubnavigator import container
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SampleTests(TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_index(self):
 | 
				
			||||||
 | 
					        github_client_mock = mock.Mock(spec=Github)
 | 
				
			||||||
 | 
					        github_client_mock.search_repositories.return_value = [
 | 
				
			||||||
 | 
					            mock.Mock(
 | 
				
			||||||
 | 
					                html_url='repo1-url',
 | 
				
			||||||
 | 
					                name='repo1-name',
 | 
				
			||||||
 | 
					                owner=mock.Mock(
 | 
				
			||||||
 | 
					                    login='owner1-login',
 | 
				
			||||||
 | 
					                    html_url='owner1-url',
 | 
				
			||||||
 | 
					                    avatar_url='owner1-avatar-url',
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					                get_commits=mock.Mock(return_value=[mock.Mock()]),
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					            mock.Mock(
 | 
				
			||||||
 | 
					                html_url='repo2-url',
 | 
				
			||||||
 | 
					                name='repo2-name',
 | 
				
			||||||
 | 
					                owner=mock.Mock(
 | 
				
			||||||
 | 
					                    login='owner2-login',
 | 
				
			||||||
 | 
					                    html_url='owner2-url',
 | 
				
			||||||
 | 
					                    avatar_url='owner2-avatar-url',
 | 
				
			||||||
 | 
					                ),
 | 
				
			||||||
 | 
					                get_commits=mock.Mock(return_value=[mock.Mock()]),
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with container.github_client.override(github_client_mock):
 | 
				
			||||||
 | 
					            response = self.client.get(reverse('index'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertContains(response, 'Results found: 2')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertContains(response, 'repo1-url')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'repo1-name')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'owner1-login')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'owner1-url')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'owner1-avatar-url')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertContains(response, 'repo2-url')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'repo2-name')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'owner2-login')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'owner2-url')
 | 
				
			||||||
 | 
					        self.assertContains(response, 'owner2-avatar-url')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_index_no_results(self):
 | 
				
			||||||
 | 
					        github_client_mock = mock.Mock(spec=Github)
 | 
				
			||||||
 | 
					        github_client_mock.search_repositories.return_value = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with container.github_client.override(github_client_mock):
 | 
				
			||||||
 | 
					            response = self.client.get(reverse('index'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertContains(response, 'Results found: 0')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,3 @@
 | 
				
			||||||
"""Views module."""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from django.http import HttpRequest, HttpResponse
 | 
					from django.http import HttpRequest, HttpResponse
 | 
				
			||||||
from django.shortcuts import render
 | 
					from django.shortcuts import render
 | 
				
			||||||
from dependency_injector.wiring import Provide
 | 
					from dependency_injector.wiring import Provide
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user