-
Notifications
You must be signed in to change notification settings - Fork 4.3k
add acceptance tests for event tracking #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| @shard_2 | ||
| Feature: LMS.Events | ||
| As a researcher, I want to be able to track events in the LMS | ||
|
|
||
| Scenario Outline: An event is emitted for each request | ||
| Given: I am registered for the course "6.002x" | ||
| And I visit the url "<url>" | ||
| Then a "<url>" server event is emitted | ||
|
|
||
| Examples: | ||
| | url | | ||
| | /dashboard | | ||
| | /courses/edx/6.002x/Test_Course/info | | ||
| | /courses/edx/6.002x/Test_Course/courseware | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #pylint: disable=C0111 | ||
|
|
||
| from lettuce import step | ||
| from lettuce import world | ||
| from lettuce import before | ||
| from pymongo import MongoClient | ||
| from nose.tools import assert_equals | ||
| from nose.tools import assert_in | ||
|
|
||
|
|
||
| @before.all | ||
| def connect_to_mongodb(): | ||
| world.mongo_client = MongoClient() | ||
| world.event_collection = world.mongo_client['track']['events'] | ||
|
|
||
|
|
||
| @before.each_scenario | ||
| def reset_captured_events(_scenario): | ||
| world.event_collection.drop() | ||
|
|
||
|
|
||
| @before.outline | ||
| def reset_between_outline_scenarios(_scenario, order, outline, reasons_to_fail): | ||
| world.event_collection.drop() | ||
|
|
||
|
|
||
| @step('[aA]n? "(.*)" (server|browser) event is emitted') | ||
| def event_is_emitted(_step, event_type, event_source): | ||
|
|
||
| # Ensure all events are written out to mongo before querying. | ||
| world.mongo_client.fsync() | ||
|
|
||
| # Note that splinter makes 2 requests when you call browser.visit('/foo') | ||
| # the first just checks to see if the server responds with a status | ||
| # code of 200, the next actually uses the browser to submit the request. | ||
| # We filter out events associated with the status code checks by ignoring | ||
| # events that come directly from splinter. | ||
| criteria = { | ||
| 'event_type': event_type, | ||
| 'event_source': event_source, | ||
| 'agent': { | ||
| '$ne': 'python/splinter' | ||
| } | ||
| } | ||
| cursor = world.event_collection.find(criteria) | ||
| assert_equals(cursor.count(), 1) | ||
|
|
||
| event = cursor.next() | ||
|
|
||
| # These fields should be present in the event, but we won't bother | ||
| # validating them since it is difficult to predict their values. | ||
| for expected_field in ['host', 'time', 'agent', 'ip', 'event_source', 'event', 'page']: | ||
| assert_in(expected_field, event, msg='Expected field {} not found in event'.format(expected_field)) | ||
|
|
||
| expected_field_values = { | ||
| "username": world.scenario_dict['USER'].username, | ||
| "event_type": event_type, | ||
| } | ||
| for key, value in expected_field_values.iteritems(): | ||
| assert_equals(event[key], value) | ||
|
|
||
| # Note that the event may contain other fields, which is fine! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can consolidate these lines:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've always listed them separately. I find it easier to read and it also tends to limit the scope of diffs making code review easier when imports change.