Skip to content

Commit

Permalink
Merge pull request #82 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa to master for textbook card release
  • Loading branch information
fanglinfang committed Mar 2, 2015
2 parents 0236ce9 + c7bffe5 commit c699eee
Show file tree
Hide file tree
Showing 26 changed files with 443 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ before_script:
- cp travis-ci/manage.py manage.py
- python manage.py syncdb --noinput
script:
- pep8 myuw_mobile/ --exclude=migrations,myuw_mobile/test,myuw_mobile/management
- pep8 myuw_mobile/ --exclude=migrations,myuw_mobile/management,myuw_mobile/test
- jshint myuw_mobile/static/js/ --verbose
- mocha myuw_mobile/static/js/test/ --recursive
- coverage run --source=myuw_mobile/ --omit=myuw_mobile/migrations/* manage.py test myuw_mobile
Expand Down
7 changes: 7 additions & 0 deletions myuw_mobile/dao/card_display_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ def get_values_by_date(now, request):
is_before_end_of_summer_reg_display_period1 = False
is_before_end_of_summer_reg_display_periodA = False
is_before_first_day_of_term = False
is_before_eof_7days_of_term = False

if now.date() < current_term.first_day_quarter:
is_before_first_day_of_term = True
# We need to see if we're before this term's 1st day - the term
# switches at the grade submission deadline.
is_after_grade_submission_deadline = True

if now.date() < current_term.first_day_quarter + timedelta(days=8):
# till the end of 7-day (exclude the first day)
is_before_eof_7days_of_term = True

raw_date = current_term.last_day_instruction
d = datetime(raw_date.year, raw_date.month, raw_date.day)
if now >= d + timedelta(days=1):
Expand Down Expand Up @@ -107,6 +112,7 @@ def get_values_by_date(now, request):
"is_before_end_of_summer_reg_display_periodA": summerA_end,
"is_before_end_of_summer_reg_display_period1": summer1_end,
"is_before_first_day_of_term": is_before_first_day_of_term,
"is_before_eof_7days_of_term": is_before_eof_7days_of_term,
"last_term": "%s,%s" % (last_term.year, last_term.quarter),
}

Expand Down Expand Up @@ -139,6 +145,7 @@ def set_js_overrides(request, values):
'myuw_before_last_day': 'is_before_last_day_of_classes',
'myuw_before_end_of_reg_display': before_reg,
'myuw_before_first_day': 'is_before_first_day_of_term',
'myuw_before_end_of_first_week': 'is_before_eof_7days_of_term',
}

for key, value in MAP.iteritems():
Expand Down
5 changes: 3 additions & 2 deletions myuw_mobile/dao/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

def get_comparison_date(request):
"""
Allows us to pretend we're at various points in the term,
so we can test against live data sources at various points in the year.
To test at various points in the year,
overrides to the date if specified in the request
otherwise return the default date.
"""
FORMAT = "%Y-%m-%d"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"13449": [{
"isbn":"9781256396362",
"title":"Writ of BC",
"authors": [{"name":"Mcdermott"}],
"price":58.00,
"used_price":null,
"required":true,
"notes":"required",
"cover_image": null
},
{
"isbn":"9780521600491",
"title":"History Of EMBA",
"authors":[{"name":"Trigger" }],
"price":45.00,
"used_price":null,
"required":false,
"notes":"this is optional",
"cover_image":null
}],
"13458": [{
"isbn":"9781256496062",
"title":"ESS Stuff 'n Things",
"authors": [{"name":"Mcdermott"}],
"price":58.00,
"used_price":null,
"required":true,
"notes":null,
"cover_image": null
}],
"13464": [{
"isbn":"9785256396062",
"title":"Studies in Bissy Bee",
"authors": [{"name":"Mcdermott"}],
"price":58.00,
"used_price":null,
"required":false,
"notes":null,
"cover_image": null
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ATermLastDay":null,"AcademicCatalog":"2010-08-01","BTermFirstDay":null,"CensusDay":"2012-01-13","FifthDay":"2012-01-06","FinancialAidYear":null,"FirstDay":"2012-01-03","FirstDayMedSchool":null,"GradeSubmissionDeadline":"2012-03-20T17:00:00","GradingPeriodClose":"2012-04-04T17:00:00","GradingPeriodOpen":"2012-02-27T08:00:00","GradingPeriodOpenATerm":null,"LastAddDay":"2012-01-23","LastAddDayATerm":null,"LastAddDayBTerm":null,"LastDayOfClasses":"2012-03-09","LastDropDay":"2012-02-20","LastDropDayATerm":null,"LastDropDayBTerm":null,"LastDropDayNotRecorded":"2012-01-15","LastDropDayNotRecordedATerm":null,"LastDropDayNotRecordedBTerm":null,"LastFinalExamDay":"2012-03-16","NextTerm":{"Href":"\/student\/v5\/term\/2012,spring.json","Quarter":"spring","Year":2012},"PreviousTerm":{"Href":"\/student\/v5\/term\/2011,autumn.json","Quarter":"autumn","Year":2011},"Quarter":"winter","RegistrationPeriods":[{"EndDate":"2011-11-27","StartDate":"2011-11-04"},{"EndDate":"2012-01-02","StartDate":"2011-11-28"},{"EndDate":"2012-01-09","StartDate":"2012-01-03"}],"RegistrationServicesStart":"2011-10-28","StudentAccountStart":null,"TimeScheduleConstruction":{"Bothell":false,"Seattle":false,"Tacoma":false},"TimeSchedulePublished":{"Bothell":true,"Seattle":true,"Tacoma":true},"Year":2012}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ATermLastDay":"2014-07-23","AcademicCatalog":"2010-08-01","BTermFirstDay":"2014-07-24","CensusDay":"2014-07-03","FifthDay":"2014-06-27","FinancialAidYear":null,"FirstDay":"2014-06-23","FirstDayMedSchool":null,"GradeSubmissionDeadline":"2014-08-26T17:00:00","GradingPeriodClose":"2014-09-10T17:00:00","GradingPeriodOpen":"2014-08-15T08:00:00","GradingPeriodOpenATerm":"2014-07-17T08:00:00","LastAddDay":"2014-07-13","LastAddDayATerm":"2014-07-13","LastAddDayBTerm":"2014-07-30","LastDayOfClasses":"2014-08-22","LastDropDay":"2014-08-10","LastDropDayATerm":"2014-07-13","LastDropDayBTerm":"2014-08-13","LastDropDayNotRecorded":"2014-07-06","LastDropDayNotRecordedATerm":"2014-06-29","LastDropDayNotRecordedBTerm":"2014-07-30","LastFinalExamDay":"2014-08-22","NextTerm":{"Href":"\/student\/v5\/term\/2014,autumn.json","Quarter":"autumn","Year":2014},"PreviousTerm":{"Href":"\/student\/v5\/term\/2014,spring.json","Quarter":"spring","Year":2014},"Quarter":"summer","RegistrationPeriods":[{"EndDate":"2014-05-21","StartDate":"2014-04-14"},{"EndDate":"2014-06-22","StartDate":"2014-05-22"},{"EndDate":"2014-06-29","StartDate":"2014-06-23"}],"RegistrationServicesStart":"2014-04-07","StudentAccountStart":null,"TimeScheduleConstruction":{"Bothell":false,"Seattle":false,"Tacoma":false},"TimeSchedulePublished":{"Bothell":true,"Seattle":true,"Tacoma":true},"Year":2014}
9 changes: 9 additions & 0 deletions myuw_mobile/static/css/mobile.less
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ body {
.shortTitle { font-family: 'Roboto', sans-serif; font-weight: 400; color: #444 !important; font-size: 16px !important; margin-top: 5px; display: block; }
}

.textbooks-list {
.textbooks-list-item { //font-size:13px;
.simplesquare {display: inline-block; height: .9em; width: .9em; margin-right: 0.3em;}
.textbooks-course-title {display: inline-block;width:38%;/* text-align:right; */}
.textbooks-course-books {font-weight:bold;}
.textbooks-course-required {font-size:12px;font-style: italic;}
}
}

.destination-arrow { position:absolute; top: 50%; right: 0; margin-top:-14px;
.show_textbooks { display:inline-block; width:40px; line-height: 40px; text-align:center; color:#777; }
}
Expand Down
51 changes: 29 additions & 22 deletions myuw_mobile/static/js/card/textbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ var TextbookCard = {
name: 'TextbookCard',
dom_target: undefined,
term: undefined,
missing_book_error: false,

render_init: function() {
var term = (TextbookCard.term === undefined) ? 'current' : TextbookCard.term;
WSData.fetch_book_data(term, TextbookCard.render_upon_data, TextbookCard.textbook_error);
WSData.fetch_course_data_for_term(term, TextbookCard.render_upon_data, TextbookCard._render_error);
// may need to add a missing_course_error
if (TextbookCard.term === 'current') {
if (!window.card_display_dates.is_before_eof_7days_of_term) {
$("#TextbookCard").hide();
return;
}
}

WSData.fetch_course_data_for_term(TextbookCard.term, TextbookCard.render_upon_data, TextbookCard.render_error);
WSData.fetch_book_data(TextbookCard.term, TextbookCard.render_upon_data, TextbookCard.textbook_error);
},


Expand All @@ -20,38 +24,32 @@ var TextbookCard = {
//If more than one data source, multiple callbacks point to this function
//Delay rendering until all requests are complete
//Do something smart about not showing error if AJAX is pending
if (!TextbookCard._has_all_data()) {
return;
if (TextbookCard._has_all_data()) {
TextbookCard._render();
}
TextbookCard._render();
},

textbook_error: function() {
TextbookCard.missing_book_error = true;
TextbookCard._render_error();
},

_render_error: function() {
if (TextbookCard.missing_book_error) {
}
else {
var source = $("#textbook_card").html();
var template = Handlebars.compile(source);
TextbookCard.dom_target.html(template({'no_books': true,
'term': TextbookCard.term}
));
var book_error_code = WSData.book_data_error_code();
var course_error_code = WSData.course_data_error_code();
if (book_error_code === 404 && (course_error_code === null || course_error_code === 404)) {
$("#TextbookCard").hide();
return;
}
TextbookCard.dom_target.html(CardWithError.render("Textbook"));
},

_render: function () {
var term = TextbookCard.term;
var course_data = WSData.course_data_for_term(term);
var no_book_assigned = true;
var registered = true;
var section_book_data = [];
if (course_data.sections.length === 0) {
registered = false;
} else {
var textbook_data = TextBooks.process_book_data(WSData.book_data(term), course_data);

$.each(textbook_data.sections, function (sec_idx, section) {
var required = 0;
var optional = 0;
Expand All @@ -61,18 +59,27 @@ var TextbookCard = {
} else {
optional += 1;
}
if (no_book_assigned) {
no_book_assigned = false;
}
});
var course_id = section.curriculum + " " + section.course_number + " " + section.section_id;

var section_data = {"course_id": course_id,
"color_id": section.color_id,
"required": required,
"optional": optional
"total": required + optional,
"no_course_books": (required + optional) ? false :true
};
section_book_data.push(section_data);
});
}
var template_data = {"registered": registered,
"term": term,
"no_book_assigned": no_book_assigned,
"quarter": course_data.quarter,
"year": course_data.year,
"summer_term": course_data.summer_term,
"sections": section_book_data};

var source = $("#textbook_card").html();
Expand Down
1 change: 1 addition & 0 deletions myuw_mobile/static/js/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Landing = {
RegStatusCard,
SummerRegStatusCardA,
VisualScheduleCard,
TextbookCard,
CourseCard,
HfsCard,
TuitionCard,
Expand Down
3 changes: 3 additions & 0 deletions myuw_mobile/static/js/myuw_m.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ var titilizeTerm = function(term) {
//Takes a term string (Eg 2032,summer,b-term) and
//returns a title (Eg Summer 2032 B-term)
var pieces = term.split(",");
if (pieces.length === 1) {
return capitalizeString(string);
}
var string = capitalizeString(pieces[1]) + " " + pieces[0];
if (pieces.length > 2) {
string += " " + capitalizeString(pieces[2]);
Expand Down
6 changes: 6 additions & 0 deletions myuw_mobile/static/js/ws_data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
WSData = {
_book_data: {},
_book_data_error_status: null,
_course_data: {},
_course_data_error_status: null,
_profile_data: null,
Expand Down Expand Up @@ -81,6 +82,10 @@ WSData = {
return WSData._book_data[term];
},

book_data_error_code: function() {
return WSData._book_data_error_status;
},

course_data_error_code: function() {
return WSData._course_data_error_status;
},
Expand Down Expand Up @@ -250,6 +255,7 @@ WSData = {
WSData._run_success_callbacks_for_url(url);
},
error: function(xhr, status, error) {
WSData._book_data_error_status = xhr.status;
WSData._run_error_callbacks_for_url(url);
}
});
Expand Down
39 changes: 24 additions & 15 deletions myuw_mobile/templates/handlebars/card/textbook.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,31 @@
<div class="card" data-name="TextbookCard" data-type="card">
<div class="fade-in">

<h3>Textbooks <!--<span class="shortTitle">{{termNoYear term}}</span>--></h3>
<h3>Textbooks</h3>

{{ #if no_books }}
<p class="text-muted">No textbooks for this term</p>
{{ else }}
<ul class="unstyled-list">
{{ #each sections }}
<li>{{ course_id }}: {{ required }} required, {{ optional }} optional</li>
{{ /each }}
</ul>
{{ /if }}

{{#unless no_books}}
<div class="destination-arrow">
<a class="show_textbooks" href="/mobile/textbooks/{{term}}" title="View textbooks"><i class="fa fa-chevron-right"></i></a
</div>
<ul class="unstyled-list textbooks-list">
{{ #each sections }}
<li class="textbooks-list-item">
<div class="c{{color_id}} simplesquare todo"></div>
<span class="textbooks-course-title">{{ course_id }}:</span>
<span class="textbooks-course-books">
{{ #if no_course_books }}
No books
{{else}}
{{ total }} {{ pluralize total 'book' 'books' }}
</span>
<span class="textbooks-course-required">
({{#if required}}{{required}}{{else}}not{{/if}} required)
</span>
</li>
{{ /if }}
{{ /each }}
</ul>

{{#unless no_book_assigned}}
<div class="destination-arrow">
<a class="show_textbooks" href="/mobile/textbooks/{{year}},{{quarter}}{{#if summer_term}},{{toLowerCase summer_term}}{{/if}}" title="View textbooks"><i class="fa fa-chevron-right"></i></a>
</div>
{{/unless}}

</div>
Expand Down
1 change: 1 addition & 0 deletions myuw_mobile/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"is_before_end_of_summer_reg_display_periodA": {{ card_display_dates.is_before_end_of_summer_reg_display_periodA|yesno:"true, false" }},
"is_before_end_of_summer_reg_display_period1": {{ card_display_dates.is_before_end_of_summer_reg_display_period1|yesno:"true, false" }},
"is_before_first_day_of_term": {{ card_display_dates.is_before_first_day_of_term|yesno:"true, false" }},
"is_before_eof_7days_of_term": {{ card_display_dates.is_before_eof_7days_of_term|yesno:"true, false" }},
"last_term": "{{ card_display_dates.last_term }}"
};
</script>
Expand Down
64 changes: 64 additions & 0 deletions myuw_mobile/test/api/cur_books.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from django.test import TestCase
from django.test.client import Client
from django.core.urlresolvers import reverse
from unittest2 import skipIf
from myuw_mobile.test.api import missing_url, get_user, get_user_pass
from django.test.utils import override_settings
import json

@override_settings(RESTCLIENTS_SWS_DAO_CLASS='restclients.dao_implementation.sws.File',
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'userservice.user.UserServiceMiddleware',
),
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
)
class TestCurBooks(TestCase):
def setUp(self):
self.client = Client()

@skipIf(missing_url("myuw_current_book"), "myuw_current_book url not configured")
def test_javerage_cur_term_books(self):
url = reverse("myuw_current_book")
get_user('javerage')
self.client.login(username='javerage', password=get_user_pass('javerage'))
response = self.client.get(url)
self.assertEquals(response.status_code, 200)

data = json.loads(response.content)

self.assertEquals(len(data["18545"]), 2)
self.assertEquals(data["verba_link"], "http://uw-seattle.verbacompare.com/m?section_id=AB12345&quarter=spring")
self.assertEquals(data["18545"][0]["cover_image_url"], "www7.bookstore.washington.edu/MyUWImage.taf?isbn=9780878935970&key=46c9ef715edb2ec69517e2c8e6ec9c18")
self.assertEquals(len(data["18545"][0]["authors"]), 1)
self.assertEquals(data["18545"][0]["is_required"], True)
self.assertEquals(data["18545"][0]["price"], None)
self.assertEquals(data["18545"][0]["used_price"], None)
self.assertEquals(data["18545"][0]["isbn"], '9780878935970')
self.assertEquals(data["18545"][0]["notes"], 'required')

@skipIf(missing_url("myuw_current_book"), "myuw_current_book url not configured")
def test_eight_cur_term_books(self):
url = reverse("myuw_current_book")
get_user('eight')
self.client.login(username='eight', password=get_user_pass('eight'))
response = self.client.get(url)
self.assertEquals(response.status_code, 200)

data = json.loads(response.content)

self.assertEquals(len(data["11646"]), 1)
self.assertEquals(data["11646"][0]["cover_image_url"], None)
self.assertEquals(len(data["11646"][0]["authors"]), 1)
self.assertEquals(data["11646"][0]["is_required"], True)
self.assertEquals(data["11646"][0]["price"], 45.0)
self.assertEquals(data["11646"][0]["used_price"], None)
self.assertEquals(data["11646"][0]["isbn"], "9780521600491")
self.assertEquals(data["11646"][0]["notes"], 'required')

Loading

0 comments on commit c699eee

Please sign in to comment.