Completed
Push — master ( 97e2cd...821a06 )
by Vijay
01:06
created

test_workshop_flow()   F

Complexity

Conditions 10

Size

Total Lines 89

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 10
dl 0
loc 89
rs 3.4615

How to fix   Long Method    Complexity   

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:

Complexity

Complex classes like test_workshop_flow() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from datetime import datetime, timedelta
2
3
import re
4
from wye.base.constants import WorkshopStatus
5
from .. import factories as f
6
7
8
def test_workshop_flow(base_url, browser, outbox):
9
    user = f.create_user()
10
    user.set_password('123123')
11
    user.save()
12
    url = base_url + '/workshop/'
13
    browser.visit(url)
14
    browser.fill('login', user.email)
15
    browser.fill('password', '123123')
16
    browser.find_by_css('[type=submit]')[0].click()
17
    assert len(outbox) == 1
18
    mail = outbox[0]
19
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
20
    assert confirm_link
21
    browser.visit(confirm_link[0])
22
    assert browser.title, "Confirm E-mail Address"
23
    browser.find_by_css('[type=submit]')[0].click()
24
25
    poc_type = f.create_usertype(slug='poc', display_name='poc')
26
    user.profile.usertype.add(poc_type)
27
    user.save()
28
    org = f.create_organisation()
29
    org.user.add(user)
30
    user.profile.interested_locations.add(org.location)
31
    org.save()
32
33
    workshop = f.create_workshop(requester=org)
34
35
    workshop.expected_date = datetime.now() + timedelta(days=20)
36
    # workshop.presenter.add(user)
37
    workshop.status = WorkshopStatus.REQUESTED
38
    workshop.location = org.location
39
    workshop.save()
40
    url = base_url + '/workshop/update/{}/'.format(workshop.id)
41
    browser.visit(url)
42
    browser.fill('login', user.email)
43
    browser.fill('password', '123123')
44
    browser.find_by_css('[type=submit]')[0].click()
45
    tutor_type = f.create_usertype(slug='tutor', display_name='tutor')
46
    user.profile.usertype.remove(poc_type)
47
    user.profile.usertype.add(tutor_type)
48
    user.save()
49
50
    url = base_url + '/workshop/'
51
    browser.visit(url)
52
53
    accept_workshop_link = browser.find_by_text('Accept')[0]
54
    assert accept_workshop_link
55
    accept_workshop_link.click()
56
57
    reject_workshop_link = browser.find_by_text('Reject')[0]
58
    assert reject_workshop_link
59
    reject_workshop_link.click()
60
61
    user.profile.usertype.remove(tutor_type)
62
    user.profile.usertype.add(poc_type)
63
    user.save()
64
65
#   checking to move requested workshop in hold state
66
    url = base_url + '/workshop/'
67
    browser.visit(url)
68
    hold_workshop_link = browser.find_by_text('Hold')[0]
69
    assert hold_workshop_link
70
    hold_workshop_link.click()
71
72
#   checking to move on hold workshop into requested state
73
    url = base_url + '/workshop/'
74
    browser.visit(url)
75
    publish_workshop_link = browser.find_by_text('Publish/Request')[0]
76
    assert publish_workshop_link
77
    publish_workshop_link.click()
78
    hold_workshop_link = browser.find_by_text('Hold')[0]
79
    assert hold_workshop_link
80
81
    workshop.expected_date = datetime.now() + timedelta(days=-20)
82
    workshop.save()
83
84
    url = base_url + '/workshop/'
85
    browser.visit(url)
86
87
    f.create_workshop_rating()
88
    publish_workshop_link = browser.find_by_text('Share Feedback')[0]
89
    assert publish_workshop_link
90
    publish_workshop_link.click()
91
    url = base_url + '/workshop/feedback/{}'.format(workshop.id)
92
    browser.visit(url)
93
    browser.check('rating0-1')
94
    browser.fill('comment', "Testing comments")
95
96
    browser.find_by_css('[type=submit]')[0].click()
97