Skip to content

Commit

Permalink
updatedAt is now Date() field
Browse files Browse the repository at this point in the history
  • Loading branch information
charliequinn-skyscanner committed Jun 19, 2017
1 parent 6813924 commit f8ae0ef
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/litmos/course.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from collections import OrderedDict

from litmos.litmos import LitmosType
Expand Down Expand Up @@ -34,6 +35,14 @@ def modules(self):
def module_complete(self, module_id, attributes):
attributes['CourseId'] = self.Id

iso_8601_date = attributes['UpdatedAt']

updated_at_datetime = datetime.datetime.strptime(iso_8601_date, '%Y-%m-%dT%H:%M:%S.%fZ')

epoch_datetime = int(updated_at_datetime.timestamp() * 1000)

attributes['UpdatedAt'] = "/Date({0})/".format(epoch_datetime)

return API.update_sub_resource(
'results',
None,
Expand Down
78 changes: 78 additions & 0 deletions tests/fixtures/mark-module-complete.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.12.3]
method: GET
uri: https://api.litmos.com/v1.svc/courses/RuzXNaD42Sw1?apikey=app-key12345&source=app-name12345&format=json
response:
body: {string: '{"Id":"RuzXNaD42Sw1","Code":"TST001","Name":"Test Why bother","Active":true,"ForSale":false,"OriginalId":590874,"Description":"","EcommerceShortDescription":"","EcommerceLongDescription":"","CourseCodeForBulkImport":"590874-TST001","Price":0.00,"AccessTillDate":null,"AccessTillDays":null}'}
headers:
Content-Length: ['289']
Content-Type: [application/json; charset=utf-8]
Date: ['Mon, 19 Jun 2017 16:01:45 GMT']
Server: [Microsoft-IIS/7.5]
X-Powered-By: [ASP.NET]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.12.3]
method: GET
uri: https://api.litmos.com/v1.svc/courses/RuzXNaD42Sw1/modules?apikey=app-key12345&source=app-name12345&format=json
response:
body: {string: '[{"Id":"0jnDHEIbXQo1","Code":"","Name":"Test","Description":""}]'}
headers:
Content-Length: ['64']
Content-Type: [application/json; charset=utf-8]
Date: ['Mon, 19 Jun 2017 16:01:46 GMT']
Server: [Microsoft-IIS/7.5]
X-Powered-By: [ASP.NET]
status: {code: 200, message: OK}
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.12.3]
method: GET
uri: https://api.litmos.com/v1.svc/users/CCzIpPA8OWo1?apikey=app-key12345&source=app-name12345&format=json
response:
body: {string: '{"Id":"CCzIpPA8OWo1","UserName":"charlie.quinn@pieshop.net","FirstName":"Charlie","LastName":"Quinn","FullName":"Charlie
Quinn","Email":"charlie.quinn@pieshop.net","AccessLevel":"Account_Owner","DisableMessages":false,"Active":true,"Skype":"","PhoneWork":"","PhoneMobile":"","LastLogin":"2017-06-19T15:48:28Z","LoginKey":"https:\/\/skyscanneruniversity.litmos.com\/login.aspx?loginkey=ff0310fc-b441-46fa-a290-4b631baaf534","IsCustomUsername":false,"Password":"","SkipFirstLogin":true,"TimeZone":"GMT
Standard Time","SalesforceId":null,"OriginalId":4974169,"Street1":"","Street2":"","City":"","State":"","PostalCode":"","Country":"","CompanyName":"","JobTitle":"","CustomField1":"1378","CustomField2":"","CustomField3":"","Culture":"en-US","CustomField4":"","CustomField5":"","CustomField6":"","CustomField7":"","CustomField8":"","CustomField9":"","CustomField10":"","SalesforceContactId":null,"SalesforceAccountId":null,"CreatedDate":"2016-12-05T17:39:15Z","Points":0,"Brand":"Default"}'}
headers:
Content-Length: ['992']
Content-Type: [application/json; charset=utf-8]
Date: ['Mon, 19 Jun 2017 16:01:46 GMT']
Server: [Microsoft-IIS/7.5]
X-Powered-By: [ASP.NET]
status: {code: 200, message: OK}
- request:
body: '{"UpdatedAt": "/Date(1497801750508)/", "CourseId": "RuzXNaD42Sw1", "UserId":
"CCzIpPA8OWo1", "Note": "", "Completed": true, "Score": 100}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['137']
Content-Type: [application/json]
User-Agent: [python-requests/2.12.3]
method: PUT
uri: https://api.litmos.com/v1.svc/results/modules/0jnDHEIbXQo1?apikey=app-key12345&source=app-name12345&format=json
response:
body: {string: ''}
headers:
Content-Length: ['0']
Date: ['Mon, 19 Jun 2017 16:01:47 GMT']
Server: [Microsoft-IIS/7.5]
X-Powered-By: [ASP.NET]
status: {code: 200, message: OK}
version: 1
4 changes: 2 additions & 2 deletions tests/test_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def test_module_complete(self, api_mock):
api_mock.update_sub_resource.return_value = True
course = Course({'Id': 'fgUr1', 'Name': 'Team1'})

module_complete = course.module_complete('fg2', {})
module_complete = course.module_complete('fg2', {'UpdatedAt': '2016-11-10T13:50:11.390Z'})

eq_(True, module_complete)
api_mock.update_sub_resource.assert_called_once_with(
'results',
None,
'modules',
'fg2',
{'CourseId': course.Id}
{'CourseId': course.Id, 'UpdatedAt': '/Date(1478785811390)/'}
)
8 changes: 4 additions & 4 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ def test_promote_and_demote(self):
team.promote_team_leader(team_member1)
assert_true(team.demote_team_leader(team_member1))

@vcr.use_cassette('fixtures/module_complete.yml')
@vcr.use_cassette('fixtures/mark-module-complete.yml')
def test_course_module_complete(self):
course = self.lms.Course.find('HvO-gG4n_BI1')
course = self.lms.Course.find('RuzXNaD42Sw1')

modules = course.modules()

Expand All @@ -269,8 +269,8 @@ def test_course_module_complete(self):
'UserId': team_member1.Id,
'Score': 100,
'Completed': True,
'UpdatedAt': (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ'),
'UpdatedAt': (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%S.%fZ'),
'Note': ''
}

assert_true(course.module_complete(modules[2].Id, attributes))
assert_true(course.module_complete(modules[0].Id, attributes))

0 comments on commit f8ae0ef

Please sign in to comment.