Skip to content

Commit ebc0244

Browse files
renzonrenzon
authored andcommitted
Added tag "never-watched-video" to new leads
close #1298
1 parent 71fb77c commit ebc0244

File tree

10 files changed

+55
-10
lines changed

10 files changed

+55
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ before_script:
1919

2020
script:
2121
- flake8 .
22-
- pytest --cov=pythonpro
22+
- pytest pythonpro --cov=pythonpro
2323
after_success:
2424
- codecov
2525
notifications:

pythonpro/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ def client_with_client(client, django_user_model, logged_user):
4040
assign_role(logged_user, 'client')
4141
client.force_login(logged_user)
4242
return client
43+
44+
45+
pytest_plugins = ['pythonpro.modules.tests.test_topics_view']

pythonpro/dashboard/conftest.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

pythonpro/dashboard/facade.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pythonpro.dashboard.models import TopicInteraction as _TopicInteracion
2+
3+
4+
def has_watched_any_topic(user) -> bool:
5+
return _TopicInteracion.objects.filter(user=user).exists()

pythonpro/dashboard/tests/test_interaction_creation.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
import pytest
22
from django.urls import reverse
3+
from model_mommy import mommy
34

45
from pythonpro.dashboard.models import TopicInteraction
56

67

78
@pytest.fixture
8-
def resp(client_with_lead, topic, logged_user):
9+
def remove_tags_mock(mocker):
10+
return mocker.patch('pythonpro.dashboard.views.remove_tags')
11+
12+
13+
@pytest.fixture
14+
def resp(client_with_lead, topic, logged_user, remove_tags_mock):
15+
return client_with_lead.post(
16+
reverse('dashboard:topic_interaction'),
17+
data={
18+
'topic': topic.id,
19+
'topic_duration': 200,
20+
'total_watched_time': 120,
21+
'max_watched_time': 60
22+
},
23+
secure=True
24+
)
25+
26+
27+
@pytest.fixture
28+
def resp_with_interaction(client_with_lead, topic, logged_user, remove_tags_mock):
29+
mommy.make(TopicInteraction, user=logged_user, topic=topic)
930
return client_with_lead.post(
1031
reverse('dashboard:topic_interaction'),
1132
data={
@@ -18,6 +39,14 @@ def resp(client_with_lead, topic, logged_user):
1839
)
1940

2041

42+
def test_user_first_video(resp, remove_tags_mock, logged_user):
43+
remove_tags_mock.assert_called_once_with(logged_user.email, 'never-watched-video')
44+
45+
46+
def test_user_not_first_video(resp_with_interaction, remove_tags_mock):
47+
assert remove_tags_mock.call_count == 0
48+
49+
2150
def test_topic_interaction_status_code(resp):
2251
return resp.status_code == 200
2352

pythonpro/dashboard/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
app_name = 'dashboard'
66
urlpatterns = [
7-
path('topic_interaction', views.topic_interation, name='topic_interaction'),
7+
path('topic_interaction', views.topic_interaction, name='topic_interaction'),
88
path('', views.home, name='home'),
99
]

pythonpro/dashboard/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from django.shortcuts import render
44
from django.views.decorators.csrf import csrf_exempt
55

6+
from pythonpro.dashboard.facade import has_watched_any_topic
67
from pythonpro.dashboard.forms import TopicInteractionForm
78
from pythonpro.dashboard.models import TopicInteraction
9+
from pythonpro.mailchimp.facade import remove_tags
810

911

1012
@login_required
@@ -15,10 +17,13 @@ def home(request):
1517

1618
@login_required
1719
@csrf_exempt
18-
def topic_interation(request):
20+
def topic_interaction(request):
1921
data = dict(request.POST.items())
20-
data['user'] = request.user.id
22+
user = request.user
23+
data['user'] = user.id
2124
form = TopicInteractionForm(data)
2225
if form.is_valid():
26+
if not has_watched_any_topic(user):
27+
remove_tags(user.email, 'never-watched-video')
2328
form.save()
2429
return JsonResponse({'msg': 'ok'})

pythonpro/mailchimp/facade.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def _create_or_update(name: str, email: str, role: str):
3737
},
3838
'interests': {
3939
role_id: True
40-
}
40+
},
41+
'tags': ['never-watched-video']
4142
}
4243
return _members_client.create(_list_id, data)
4344

@@ -46,6 +47,10 @@ def tag_as(email: str, *tags):
4647
return _members_client.tags.update(_list_id, email, {'tags': [{'name': tag, 'status': 'active'} for tag in tags]})
4748

4849

50+
def remove_tags(email: str, *tags):
51+
return _members_client.tags.update(_list_id, email, {'tags': [{'name': tag, 'status': 'inactive'} for tag in tags]})
52+
53+
4954
def _update_member_role(email: str, role: str) -> dict:
5055
member = _members_client.get(_list_id, email)
5156
interests = member['interests']

pythonpro/mailchimp/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def test_creation(existing_lead, resps):
4444
},
4545
'interests': {
4646
roles_to_ids[facade._LEAD]: True
47-
}
47+
},
48+
'tags': ['never-watched-video']
4849
}
4950
facade.create_or_update_lead('Renzo', 'host@python.pro.br')
5051
assert json.loads(resps.calls[-1].request.body) == expected_on_request

pythonpro/modules/templates/topics/topic_detail.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ <h1 class="mt-4 mb-3">{{ topic.title }}</h1>
119119
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
120120
})();
121121
</script>
122-
{% else %}
123-
<div id='discourse-comments'>Membros possuem acesso a fórum de discussão aqui ;)</div>
124122
{% endif %}
125123
</div>
126124
</div>

0 commit comments

Comments
 (0)