test_workshop_list()   C
last analyzed

Complexity

Conditions 7

Size

Total Lines 114

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 114
rs 5.3042
cc 7

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
from datetime import datetime, timedelta
2
3
import base
4
from tests import factories as f
5
from wye.base.constants import WorkshopStatus, WorkshopLevel
6
from wye.regions.models import RegionalLead
7
8
9
outbox_len = 0
10
password = '123123'
11
12
13
def test_workshop_list(base_url, browser, outbox):
14
    """
15
    Following testcases will be checked:
16
    - Check workshop listing for user with usertype poc
17
    - Check workshop listing for user with usertype tutor
18
    - Check workshop listing for user with usertype lead
19
    - Check workshop listing for user with no usertype
20
    """
21
22
    # Create usertypes
23
    regional_lead_type = f.create_usertype(
24
        slug='lead', display_name='regional lead')
25
    f.create_usertype(slug='tutor', display_name='tutor')
26
    poc_type = f.create_usertype(slug='poc', display_name='poc')
27
    state = f.create_state()
28
    # Testcase with usertyep poc
29
    user = base.create_user(password)
30
    url = base_url + '/workshop/'
31
    base.login_and_confirm(browser, url, outbox, user, password)
32
    user.profile.usertype.clear()
33
    user.profile.usertype.add(poc_type)
34
    user.profile.interested_states.add(state)
35
    user.profile.save()
36
    user.save()
37
38
    # Create org
39
    location = f.create_locaiton(state=state)
40
    org = f.create_organisation(location=location)
41
    org.user.add(user)
42
    user.profile.interested_locations.add(location)
43
    user.profile.location = org.location
44
    user.profile.save()
45
    org.save()
46
47
    # Create workshop
48
    workshop = f.create_workshop(requester=org)
49
    workshop.expected_date = datetime.now() + timedelta(days=20)
50
    workshop.status = WorkshopStatus.REQUESTED
51
    workshop.level = WorkshopLevel.BEGINNER
52
    workshop.location = org.location
53
    workshop.save()
54
55
    url = base_url + '/workshop/'
56
    base.login(browser, url, user, password)
57
    data_check = browser.find_by_text(org.name)
58
    assert data_check
59
60
    browser.visit(url + "?location={}".format(org.location.id))
61
    data_check = browser.find_by_text(org.name)
62
    assert data_check
63
64
    browser.visit(url + "?location={}".format(org.location.id + 1))
65
    data_check = browser.find_by_text(org.name)
66
    assert not data_check
67
68
    browser.visit(url + "?presenter={}".format(user.id))
69
    data_check = browser.find_by_text(org.name)
70
    assert not data_check
71
72
    browser.visit(url + "?status={}".format(WorkshopStatus.REQUESTED))
73
    data_check = browser.find_by_text(org.name)
74
    assert data_check
75
76
    browser.visit(url + "?level={}".format(WorkshopStatus.ACCEPTED))
77
    data_check = browser.find_by_text(org.name)
78
    assert not data_check
79
80
    # Testcase for usertype tutor
81
    browser.visit(base_url + "/accounts/logout")
82
    user = base.create_user(password)
83
    url = base_url + '/workshop/'
84
    base.login_and_confirm(browser, url, outbox, user, password)
85
    # user.profile.usertype.add(tutor_type)
86
    # user.save()
87
88
    # url = base_url + '/workshop/'
89
    # base.login(browser, url, user, password)
90
    # # User not associate with workshop
91
    # data_check = browser.find_by_text(org.name)
92
    # assert [] == data_check
93
94
    # User associated with workshop
95
    workshop.presenter.add(user)
96
    browser.visit(url)
97
    # data_check = browser.find_by_text(org.name)
98
    # assert data_check
99
100
    # Testcase for lead
101
    browser.visit(base_url + "/accounts/logout")
102
    user = base.create_user(password)
103
    url = base_url + '/workshop/'
104
    base.login_and_confirm(browser, url, outbox, user, password)
105
106
    user.profile.usertype.add(regional_lead_type)
107
    user.save()
108
    lead = RegionalLead.objects.create(location=org.location)
109
    lead.leads.add(user)
110
111
    url = base_url + '/workshop/'
112
    base.login(browser, url, user, password)
113
    # data_check = browser.find_by_text(org.name)
114
    # assert data_check
115
116
    # Testcase for user with no usertype
117
    browser.visit(base_url + "/accounts/logout")
118
    user = base.create_user(password)
119
    url = base_url + '/workshop/'
120
    base.login_and_confirm(browser, url, outbox, user, password)
121
122
    url = base_url + '/workshop/'
123
    base.login(browser, url, user, password)
124
    # data_check = browser.find_by_text(org.name)
125
    # assert [] == data_check
126
    browser.visit(base_url + "/accounts/logout")
127