Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

from django.http import HttpRequest 

from django.test import SimpleTestCase, TestCase 

from django.test.client import Client 

from django.urls import reverse 

from users.models import CustomUser 

from main.models import Fanfic 

from unittest import mock 

 

 

class DashboardTests(TestCase): 

 

def setUp(self): 

self.normal_user = CustomUser.objects.create( 

name_surname="name", 

country="AM", 

date_of_birth="2000-07-02", 

email="em@gm.com", 

username='testuser', 

password="12345") 

 

self.client = Client() 

self.client.force_login(user=self.normal_user) 

 

def test_home_status_code(self): 

response = self.client.get(reverse('common:home'), follow=True) 

self.assertEquals(response.status_code, 200) 

 

def test_dashboard_status_code(self): 

response = self.client.get(reverse('common:dashboard'), follow=True) 

self.assertEquals(response.status_code, 200) 

 

 

class ExternalAddTests(TestCase): 

 

def setUp(self): 

self.normal_user = CustomUser.objects.create( 

name_surname="name", 

country="AM", 

date_of_birth="2000-07-02", 

email="em@gm.com", 

username='testuser', 

password="12345") 

 

Fanfic.objects.create(name="Testek fanfic", author="michaelRuiz", 

web="http://web-fanfic.com", genre1="adv", 

status="c") 

 

self.client = Client() 

self.client.force_login(user=self.normal_user) 

 

def test_external_add_status_code(self): 

response = self.client.get(reverse('common:external_add')) 

self.assertEquals(response.status_code, 200) 

 

@mock.patch('django.core.handlers.wsgi.WSGIRequest.is_ajax') 

@mock.patch('main.views.url_without_errors') 

def test_post_external_add_bad_url(self, mock_url_without_errors, 

mock_is_ajax): 

''' Try to add fanfic with bad url ''' 

mock_url_without_errors.return_value = "Error: bad url" 

mock_is_ajax.return_value = True 

 

post_data = {'url_fanfic': 'bad-url'} 

 

response = self.client.post(reverse('common:external_add'), 

data=post_data) 

self.assertEquals(response.status_code, 200) 

 

@mock.patch('django.core.handlers.wsgi.WSGIRequest.is_ajax') 

@mock.patch('main.views_functions.Fanfic.get_title_and_author') 

@mock.patch('main.views.url_without_errors') 

def test_post_external_add_with_similars(self, 

mock_url_without_errors, 

mock_title_and_author, 

mock_is_ajax): 

''' Try to add fanfic that has similar ones ''' 

mock_url_without_errors.return_value = "good-url" 

mock_title_and_author.return_value = ("test fanfic", "PetrovDiminov") 

mock_is_ajax.return_value = True 

 

post_data = {'url_fanfic': 'good-url'} 

 

response = self.client.post(reverse('common:external_add'), 

data=post_data) 

self.assertEquals(response.status_code, 200)