Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 662acec

Browse files
authored
Upgrading to django 1.11 (#168)
* upgraded django and other packages
1 parent 7a3e097 commit 662acec

7 files changed

Lines changed: 76 additions & 104 deletions

File tree

analytics_data_api/v0/tests/views/test_courses.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import ddt
1111
from django.conf import settings
12+
from django.utils import timezone
1213
from django_dynamic_fixture import G
1314
import pytz
1415
from opaque_keys.edx.keys import CourseKey
@@ -592,10 +593,12 @@ def test_get(self, course_id):
592593
# natural order and ensure the view properly sorts the objects before grouping.
593594
module_id = u'i4x://test/problem/1'
594595
alt_module_id = u'i4x://test/problem/2'
595-
created = datetime.datetime.utcnow()
596+
created = timezone.now()
596597
alt_created = created + datetime.timedelta(seconds=2)
597598
date_time_format = '%Y-%m-%d %H:%M:%S'
598599

600+
# using string representations of dates will cause "DateTimeField time zone support" RuntimeWarning
601+
# however, using the date with timezone causes conversion errors
599602
o1 = G(models.ProblemFirstLastResponseAnswerDistribution, course_id=course_id, module_id=module_id,
600603
correct=True, last_response_count=100, created=created.strftime(date_time_format))
601604
o2 = G(models.ProblemFirstLastResponseAnswerDistribution, course_id=course_id, module_id=alt_module_id,
@@ -661,7 +664,7 @@ def test_get(self, course_id):
661664
'learning_outcome': ['Learned nothing', 'Learned a few things', 'Learned everything']
662665
}
663666

664-
created = datetime.datetime.utcnow()
667+
created = timezone.now()
665668
alt_created = created + datetime.timedelta(seconds=2)
666669

667670
G(models.ProblemsAndTags, course_id=course_id, module_id=module_id,
@@ -728,18 +731,17 @@ def test_get(self, course_id):
728731

729732
module_id = 'i4x-test-video-1'
730733
video_id = 'v1d30'
731-
created = datetime.datetime.utcnow()
732-
date_time_format = '%Y-%m-%d %H:%M:%S'
734+
created = timezone.now()
733735
G(models.Video, course_id=course_id, encoded_module_id=module_id,
734736
pipeline_video_id=video_id, duration=100, segment_length=1, users_at_start=50, users_at_end=10,
735-
created=created.strftime(date_time_format))
737+
created=created)
736738

737739
alt_module_id = 'i4x-test-video-2'
738740
alt_video_id = 'a1d30'
739741
alt_created = created + datetime.timedelta(seconds=10)
740742
G(models.Video, course_id=course_id, encoded_module_id=alt_module_id,
741743
pipeline_video_id=alt_video_id, duration=200, segment_length=5, users_at_start=1050, users_at_end=50,
742-
created=alt_created.strftime(date_time_format))
744+
created=alt_created)
743745

744746
expected = [
745747
{

analytics_data_api/v0/tests/views/test_videos.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22

33
from django.conf import settings
4+
from django.utils import timezone
45
from django_dynamic_fixture import G
56

67
from analytics_data_api.v0 import models
@@ -17,17 +18,16 @@ def test_get(self):
1718
G(models.VideoTimeline)
1819

1920
video_id = 'v1d30'
20-
created = datetime.datetime.utcnow()
21-
date_time_format = '%Y-%m-%d %H:%M:%S'
21+
created = timezone.now()
2222
G(models.VideoTimeline, pipeline_video_id=video_id, segment=0, num_users=10,
23-
num_views=50, created=created.strftime(date_time_format))
23+
num_views=50, created=created)
2424
G(models.VideoTimeline, pipeline_video_id=video_id, segment=1, num_users=1,
25-
num_views=1234, created=created.strftime(date_time_format))
25+
num_views=1234, created=created)
2626

2727
alt_video_id = 'altv1d30'
2828
alt_created = created + datetime.timedelta(seconds=17)
2929
G(models.VideoTimeline, pipeline_video_id=alt_video_id, segment=0, num_users=10231,
30-
num_views=834828, created=alt_created.strftime(date_time_format))
30+
num_views=834828, created=alt_created)
3131

3232
expected = [
3333
{

analyticsdataserver/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
url(r'^api-token-auth/', obtain_auth_token),
1414

1515
url(r'^api/', include('analytics_data_api.urls', 'api')),
16-
url(r'^docs/', include('rest_framework_swagger.urls')),
16+
url(r'^docs/', views.SwaggerSchemaView.as_view()),
1717

1818
url(r'^status/$', views.StatusView.as_view(), name='status'),
1919
url(r'^authenticated/$', views.AuthenticationTestView.as_view(), name='authenticated'),

analyticsdataserver/views.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from django.conf import settings
22
from django.db import connections
33
from django.http import HttpResponse
4-
from rest_framework import permissions
4+
from rest_framework import permissions, schemas
5+
from rest_framework.permissions import AllowAny
56
from rest_framework.renderers import JSONRenderer
67
from rest_framework.response import Response
78
from rest_framework.views import APIView
9+
from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer
810

911

1012
def handle_internal_server_error(_request):
@@ -27,6 +29,21 @@ def _handle_error(status_code):
2729
return HttpResponse(renderer.render(info), content_type=content_type, status=status_code)
2830

2931

32+
class SwaggerSchemaView(APIView):
33+
"""
34+
Renders the swagger schema for the documentation regardless of permissions.
35+
"""
36+
permission_classes = [AllowAny]
37+
renderer_classes = [
38+
OpenAPIRenderer,
39+
SwaggerUIRenderer
40+
]
41+
42+
def get(self, _request):
43+
generator = schemas.SchemaGenerator(title='Analytics API')
44+
return Response(generator.get_schema())
45+
46+
3047
class StatusView(APIView):
3148
"""
3249
Simple check to determine if the server is alive

requirements/base.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
boto==2.42.0 # MIT
2-
Django==1.10.7 # BSD License
3-
django-countries==4.0 # MIT
4-
djangorestframework==3.5.3 # BSD
5-
django-rest-swagger==0.3.8 # BSD
6-
djangorestframework-csv==1.4.1 # BSD
7-
django-storages==1.5.1 # BSD
2+
Django==1.11 # BSD License
3+
django-countries==4.5 # MIT
4+
djangorestframework==3.6.2 # BSD
5+
django-rest-swagger==2.1.2 # BSD
6+
djangorestframework-csv==2.0.0 # BSD
7+
django-storages==1.5.2 # BSD
88
elasticsearch-dsl==0.0.11 # Apache 2.0
9-
ordered-set==2.0.1 # MIT
10-
tqdm==4.10.0 # MIT
9+
ordered-set==2.0.2 # MIT
10+
tqdm==4.11.2 # MIT
1111

1212
# markdown is used by swagger for rendering the api docs
1313
Markdown==2.6.6 # BSD

requirements/test.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Test dependencies go here.
22
-r base.txt
3-
coverage==4.2
3+
coverage==4.4.1
44
ddt==1.1.1
55
diff-cover >= 0.9.9
6-
django-dynamic-fixture==1.9.0
6+
django-dynamic-fixture==1.9.5
77
django-nose==1.4.4
88
mock==2.0.0
9-
nose-exclude==0.4.1
9+
nose-exclude==0.5.0
1010
nose-ignore-docstring==0.2
1111
nose==1.3.7
1212
pep257==0.7.0
1313
pep8==1.7.0
14-
pylint==1.6.4
15-
pytz==2016.6.1
14+
pylint==1.6.5
15+
pytz==2017.2
1616
responses==0.5.1
Lines changed: 31 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,40 @@
1-
{% load staticfiles %}
2-
<!DOCTYPE html>
3-
<html>
4-
<head>
5-
<title>edX Analytics API</title>
6-
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
7-
<link href='{% static "rest_framework_swagger/css/highlight.default.css" %}' media='screen' rel='stylesheet' type='text/css'/>
8-
<link href='{% static "rest_framework_swagger/css/rest_framework_swagger.css" %}' media='screen' rel='stylesheet' type='text/css'/>
9-
<link href='{% static "rest_framework_swagger/css/screen.css" %}' media='screen' rel='stylesheet' type='text/css'/>
10-
<link href='{% static "css/edx-swagger.css" %}' media='screen' rel='stylesheet' type='text/css'/>
11-
<script type="text/javascript" src="{% static 'rest_framework_swagger/lib/shred.bundle.js' %}"></script>
12-
<script src='{% static "rest_framework_swagger/lib/jquery-1.8.0.min.js" %}' type='text/javascript'></script>
13-
<script src='{% static "rest_framework_swagger/lib/jquery.slideto.min.js" %}' type='text/javascript'></script>
14-
<script src='{% static "rest_framework_swagger/lib/jquery.wiggle.min.js" %}' type='text/javascript'></script>
15-
<script src='{% static "rest_framework_swagger/lib/jquery.ba-bbq.min.js" %}' type='text/javascript'></script>
16-
<script src='{% static "rest_framework_swagger/lib/jquery.cookie.js" %}' type='text/javascript'></script>
17-
<script src='{% static "rest_framework_swagger/lib/handlebars-1.0.0.js" %}' type='text/javascript'></script>
18-
<script src='{% static "rest_framework_swagger/lib/underscore-min.js" %}' type='text/javascript'></script>
19-
<script src='{% static "rest_framework_swagger/lib/backbone-min.js" %}' type='text/javascript'></script>
20-
<script src='{% static "rest_framework_swagger/lib/swagger.js" %}' type='text/javascript'></script>
21-
<script src='{% static "rest_framework_swagger/swagger-ui.min.js" %}' type='text/javascript'></script>
22-
<script src='{% static "rest_framework_swagger/lib/highlight.7.3.pack.js" %}' type='text/javascript'></script>
1+
{% extends "rest_framework_swagger/index.html" %}
232

24-
<link rel="icon" type="image/x-icon" href='{% static "images/favicon.ico" %}' />
3+
{% load staticfiles %}
254

5+
{% block header %}
6+
<div id="header">
7+
<div class="swagger-ui-wrap">
8+
<form id='api_selector'>
9+
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
10+
<div class='input'><input placeholder="API Key" id="input_apiKey" name="apiKey" type="text"/></div>
11+
</form>
12+
</div>
13+
</div>
14+
{% endblock %}
15+
16+
{% block extra_scripts %}
2617
<script type="text/javascript">
2718
$(function () {
2819
window.swaggerUi = new SwaggerUi({
29-
url: "{{ swagger_settings.discovery_url }}",
30-
apiKey: "{{ swagger_settings.api_key }}",
31-
dom_id: "swagger-ui-container",
32-
supportedSubmitMethods: {{ swagger_settings.enabled_methods }},
33-
onComplete: function(swaggerApi, swaggerUi){
34-
if(console) {
35-
console.log("Loaded SwaggerUI")
36-
}
37-
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
38-
},
39-
onFailure: function(data) {
40-
if(console) {
41-
console.log("Unable to Load SwaggerUI");
42-
console.log(data);
20+
url: '',
21+
dom_id: 'swagger-ui-container'
22+
});
23+
24+
// this sets the authorization token so calls to the API can made via swagger
25+
$('#input_apiKey').change(function() {
26+
var key = $('#input_apiKey')[0].value;
27+
console.log('key: ' + key);
28+
if(key && key.trim() !== '') {
29+
console.log('added key ' + key);
30+
window.swaggerUi.api.clientAuthorizations.add('key',
31+
new SwaggerClient.ApiKeyAuthorization('Authorization', 'Token ' + key, 'header')
32+
);
4333
}
44-
},
45-
docExpansion: "none"
34+
});
35+
window.swaggerUi.load();
4636
});
47-
48-
$('#input_apiKey').change(function() {
49-
var key = $('#input_apiKey')[0].value;
50-
console.log("key: " + key);
51-
if(key && key.trim() != "") {
52-
console.log("added key " + key);
53-
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Token " + key, "header"));
54-
}
55-
})
56-
{% if swagger_settings.api_key %}
57-
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Token " + "{{ swagger_settings.api_key }}", "header"));
58-
{% endif %}
59-
window.swaggerUi.load();
60-
});
61-
6237
</script>
63-
</head>
64-
65-
<body>
66-
<div id='header'>
67-
<div class="swagger-ui-wrap">
68-
<a id="logo" class="edx-logo" href="http://code.edx.org/"></a>
69-
70-
<form id='api_selector'>
71-
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
72-
<div class='input'><input placeholder="API Key" id="input_apiKey" name="apiKey" type="text"/></div>
73-
<div class='input'><a id="explore" href="#">Explore</a></div>
74-
</form>
75-
</div>
76-
</div>
77-
78-
<div id="message-bar" class="swagger-ui-wrap">
79-
&nbsp;
80-
</div>
81-
<div id="swagger-ui-container" class="swagger-ui-wrap">
82-
83-
</div>
84-
85-
</body>
8638

87-
</html>
39+
<script src='{% static "rest_framework_swagger/init.js" %}' type='text/javascript'></script>
40+
{% endblock %}

0 commit comments

Comments
 (0)