Skip to content

Commit 72d0c63

Browse files
committed
Refactored news view into group posts are in new discussions view
Added test cases Added test fixture Updated requirements.txt for nose and django-nose
1 parent 6644de2 commit 72d0c63

File tree

11 files changed

+69
-67
lines changed

11 files changed

+69
-67
lines changed

mep_django/linkedin/.tests.py.swp

-12 KB
Binary file not shown.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"pk": 1, "model": "contenttypes.contenttype", "fields": {"model": "logentry", "name": "log entry", "app_label": "admin"}}, {"pk": 2, "model": "contenttypes.contenttype", "fields": {"model": "permission", "name": "permission", "app_label": "auth"}}, {"pk": 3, "model": "contenttypes.contenttype", "fields": {"model": "group", "name": "group", "app_label": "auth"}}, {"pk": 4, "model": "contenttypes.contenttype", "fields": {"model": "user", "name": "user", "app_label": "auth"}}, {"pk": 5, "model": "contenttypes.contenttype", "fields": {"model": "contenttype", "name": "content type", "app_label": "contenttypes"}}, {"pk": 6, "model": "contenttypes.contenttype", "fields": {"model": "session", "name": "session", "app_label": "sessions"}}, {"pk": 7, "model": "contenttypes.contenttype", "fields": {"model": "usersocialauth", "name": "user social auth", "app_label": "default"}}, {"pk": 8, "model": "contenttypes.contenttype", "fields": {"model": "nonce", "name": "nonce", "app_label": "default"}}, {"pk": 9, "model": "contenttypes.contenttype", "fields": {"model": "association", "name": "association", "app_label": "default"}}, {"pk": 10, "model": "contenttypes.contenttype", "fields": {"model": "code", "name": "code", "app_label": "default"}}, {"pk": "dzkr27fac575ng757f7tm1vip13wsu5w", "model": "sessions.session", "fields": {"expire_date": "2014-05-23T22:17:37.060Z", "session_data": "MWQ5ZTAzY2QwZWZiNzE4MDhiZjFiYWVkNmE3NDYwOGU0NTczYmQwMjp7fQ=="}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 1}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 2}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 3}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 4}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_usersocialauth", "name": "Can add user social auth", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_usersocialauth", "name": "Can change user social auth", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_usersocialauth", "name": "Can delete user social auth", "content_type": 7}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_nonce", "name": "Can add nonce", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_nonce", "name": "Can change nonce", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_nonce", "name": "Can delete nonce", "content_type": 8}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_association", "name": "Can add association", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_association", "name": "Can change association", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_association", "name": "Can delete association", "content_type": 9}}, {"pk": 28, "model": "auth.permission", "fields": {"codename": "add_code", "name": "Can add code", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_code", "name": "Can change code", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_code", "name": "Can delete code", "content_type": 10}}, {"pk": 1, "model": "auth.user", "fields": {"username": "admin", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2014-05-09T22:14:39.972Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$wpBJqRTP8ZrW$I3zVXGsBOENWKjAjJdsk8tYn/VuPBmbi+1FtB+yc2Fk=", "email": "", "date_joined": "2014-05-09T22:10:22.457Z"}}, {"pk": 2, "model": "auth.user", "fields": {"username": "test", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "2014-05-09T22:15:29.777Z", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$12000$ILarHukbgsYh$MRZfNyDZGcUfynQYZMVRDRQ+92jsjTSXqHWjm9+Z4JM=", "email": "", "date_joined": "2014-05-09T22:15:29.777Z"}}, {"pk": 1, "model": "default.usersocialauth", "fields": {"uid": "test uid", "extra_data": "{}", "user": 2, "provider": "test provider"}}, {"pk": 1, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-05-09T22:15:29.937Z", "object_repr": "test", "object_id": "2", "change_message": "", "user": 1, "content_type": 4}}, {"pk": 2, "model": "admin.logentry", "fields": {"action_flag": 1, "action_time": "2014-05-09T22:17:10.493Z", "object_repr": "UserSocialAuth object", "object_id": "1", "change_message": "", "user": 1, "content_type": 7}}]

mep_django/linkedin/models.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
from django.db import models
22

3-
# Create your models here.
4-
'''from django.contrib.auth.models import AbstractUser, UserManager
5-
3+
#from django.contrib.auth.models import AbstractUser, UserManager
64

5+
'''
76
class CustomUser(AbstractUser):
87
objects = UserManager()
9-
'''
10-
118
129
class GroupPost(models.Model):
1310
title = models.CharField(max_length = 500)
1411
summary = models.TextField()
1512
creation_timestamp = models.BigIntegerField()
1613
db_timestamp = models.DateField(auto_now_add = True)
1714
site_group_post_url = models.URLField()
15+
'''
1816

mep_django/linkedin/tests.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def test_status_200(self):
1414
class TestNewsView(TestCase):
1515
'''Unit test for the news view'''
1616

17+
fixtures = ['fix1.json']
18+
1719
def setUp(self):
1820
self.MY_URL = '/news/'
1921

@@ -24,7 +26,7 @@ def test_status_403(self):
2426

2527
def test_status_200(self):
2628
'''Return status 200 upon GET request when user IS logged in'''
27-
self.client.login(username='user', password='pass')
29+
self.client.login(username='test', password='pass')
2830
response = self.client.get(self.MY_URL)
2931
self.assertEqual(response.status_code, 200)
3032

mep_django/linkedin/views.py

+27-44
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#from django.http import HttpResponse
66
from django.core.exceptions import PermissionDenied
77

8+
9+
API_KEY = '75l485e9k29snc'
10+
API_SECRET = 'iw7fONMpJZcY5HOb'
11+
812
def logout(request):
913
"""logs the user out, then redirects to the home page"""
1014
auth_logout(request)
@@ -46,42 +50,38 @@ def profile(request):
4650
else:
4751
return redirect('home')
4852

49-
50-
def get_access_tokens(user):
51-
"""Query user database to retrieve OAuth1 access tokens for the currently logged-in user"""
53+
def get_app(user):
54+
"""Given a valid user object, return a LinkedInApplication instance that can be used to make the Linkedin API calls"""
55+
# Query user database to retrieve OAuth1 access tokens for the currently logged-in user"""
5256
social_user = user.social_auth.get()
5357
OAUTH_USER_TOKEN = social_user.extra_data['access_token']['oauth_token']
54-
OAUTH_USER_TOKEN_SECRET = social_user.extra_data['access_token']['oauth_token_secret']
55-
return (OAUTH_USER_TOKEN, OAUTH_USER_TOKEN_SECRET)
58+
OAUTH_USER_TOKEN_SECRET = social_user.extra_data['access_token']['oauth_token_secret']
59+
auth = linkedin.LinkedInDeveloperAuthentication(API_KEY, API_SECRET, OAUTH_USER_TOKEN, OAUTH_USER_TOKEN_SECRET, '', linkedin.PERMISSIONS.enums.values())
60+
return linkedin.LinkedInApplication(auth)
5661

57-
def news(request):
58-
"""Diplays the LinkedIn content, this is the critical view of the app"""
59-
60-
#if not request.user.is_authenticated():
61-
#return redirect('home')
62-
62+
def discussions(request):
63+
"""Displays the LinkedIn group content"""
6364
# handle unauthorized access with a 403
6465
if not request.user.is_authenticated() or not request.user.is_active:
6566
raise PermissionDenied
66-
67-
API_KEY = '75l485e9k29snc'
68-
API_SECRET = 'iw7fONMpJZcY5HOb'
69-
USER_KEY, USER_SECRET = get_access_tokens(request.user)
70-
67+
# this is the ID of the linkedin group
7168
GROUP_ID = 1627067
72-
COMPANY_ID = 1035
73-
7469
POST_SELECTORS = ['title', 'summary', 'creation-timestamp', 'site-group-post-url', 'creator', 'id',]
75-
COMPANY_SELECTORS = ['name', 'id']
76-
77-
auth = linkedin.LinkedInDeveloperAuthentication(API_KEY, API_SECRET, USER_KEY, USER_SECRET, '', linkedin.PERMISSIONS.enums.values())
78-
app = linkedin.LinkedInApplication(auth)
79-
70+
app = get_app(request.user)
8071
group_posts = app.get_posts(GROUP_ID, selectors=POST_SELECTORS)
81-
72+
return render(request, 'discussions.html', {'post_list':group_posts['values'],})
73+
74+
def news(request):
75+
"""Diplays the LinkedIn company content, this is the critical view of the app"""
76+
# handle unauthorized access with a 403
77+
if not request.user.is_authenticated() or not request.user.is_active:
78+
raise PermissionDenied
79+
COMPANY_ID = 1035
80+
COMPANY_SELECTORS = ['name', 'id']
81+
app = get_app(request.user)
8282
company = app.get_companies(company_ids=[COMPANY_ID], selectors=COMPANY_SELECTORS, params={'is-company-admin': 'true'})
83-
84-
updates = app.get_company_updates(COMPANY_ID, params={'count': 10, 'event-type': 'status-update',})
83+
count = 10
84+
updates = app.get_company_updates(COMPANY_ID, params={'count': count, 'event-type': 'status-update',})
8585

8686
import pprint
8787
pp = pprint.PrettyPrinter(indent=2)
@@ -98,22 +98,5 @@ def news(request):
9898
my_dict['shortenedUrl'] = update['updateContent']['companyStatusUpdate']['share']['content'].get('shortenedUrl')
9999
update_list.append(my_dict)
100100

101-
102-
103-
104-
'''
105-
for post in group_posts['values']:
106-
for k, v in post.iteritems():
107-
if k == 'creator':
108-
print 'Creator{'
109-
for k2, v2 in post['creator'].iteritems():
110-
print '\t' + str(k2) + ': '
111-
print '\t' + str(v2) + '\n'
112-
print '}'
113-
else:
114-
print str(k) + ': '
115-
print str(v) + '\n'
116-
#raw_input()
117-
'''
118-
return render(request, 'news.html', {'post_list':group_posts['values'], 'update_list': update_list})
101+
return render(request, 'news.html', {'update_list': update_list,})
119102

mep_django/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
url(r'^logout/$', views.logout, name='logout'),
1212
url(r'^about/$', views.about, name='about'),
1313
url(r'^contact/$', views.contact, name='contact'),
14-
url(r'^profile/$', views.profile, name='profile'),
14+
url(r'^discussions/$', views.discussions, name='discussions'),
1515
url(r'^news/$', views.news, name='news'),
1616
url('', include('social.apps.django_app.urls', namespace='social')),
1717
)

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Django==1.6.2
2+
django-nose==1.2
3+
nose==1.3.3
24
oauthlib==0.6.1
35
python-linkedin==4.0
46
python-openid==2.2.5
57
python-social-auth==0.1.23
68
requests==2.2.1
79
requests-oauthlib==0.4.0
810
six==1.6.1
9-
wsgiref==0.1.2

templates/base.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
<li><a href="{% url 'contact' %}">Contact</a></li>
4848
{% if user.is_authenticated %}
4949
<li><a href="{% url 'news' %}">News</a></li>
50-
{% else %}
51-
50+
<li><a href="{% url 'discussions' %}">Discussions</a></li>
5251
{% endif %}
5352
{% if not user.is_authenticated %}
5453
<!-- we know this works, it's been tested, but we want to try to take advantage of twitterbootstrap and use modal! ;) -->
@@ -74,7 +73,6 @@
7473
<!-- FOOTER -->
7574
<div class="container" style="margin-top:10px;">
7675
<footer>
77-
7876
<p><img style="width:15%;" src="/static/images/MEPnew.png">&copy; 2014 &middot; Web Design: Team Alpha &middot; <a href="#">Privacy</a> &middot; <a href="#">Terms</a></p>
7977
</footer>
8078
</div>
@@ -104,3 +102,4 @@
104102
</script>
105103
</body>
106104
</html>
105+

templates/discussions.html

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
<div class="container" style="margin:120px auto 0px auto">
6+
<div class="col-md-8">
7+
{% for post in post_list %}
8+
<div class="row">
9+
<div class="panel panel-primary">
10+
<div class="panel-heading">
11+
<p>{{ post.creator.firstName }}</p>
12+
{% if post.creator.pictureUrl %}
13+
<p><img src="{{ post.creator.pictureUrl }}" alt="user's picture"/></p>
14+
{% endif %}
15+
<h3 class="panel-title">{{ post.title }}</h3>
16+
</div>
17+
<div class="panel-body">
18+
{{ post.summary }}
19+
</div>
20+
</div>
21+
</div>
22+
{% endfor %}
23+
</div>
24+
</div>
25+
26+
{% endblock %}
27+

templates/news.html

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
{% block content %}
44

55
<div class="container" style="margin:120px auto 0px auto">
6+
7+
<!--
68
<div class="col-md-8">
79
{% for post in post_list %}
810
<div class="row">
@@ -20,6 +22,7 @@ <h3 class="panel-title">{{ post.title }}</h3>
2022
</div>
2123
</div>
2224
{% endfor %}
25+
-->
2326

2427
{% for update in update_list %}
2528
<div class="row">

templates/profile.html

-12
This file was deleted.

0 commit comments

Comments
 (0)