Skip to content

Add test fixtures#3

Closed
SergioSim wants to merge 3 commits into
openfun:masterfrom
SergioSim:add-test-fixtures
Closed

Add test fixtures#3
SergioSim wants to merge 3 commits into
openfun:masterfrom
SergioSim:add-test-fixtures

Conversation

@SergioSim

Copy link
Copy Markdown
Collaborator

Purpose

  • A event test fixture factory could help to test the function of the GELFParser

Proposal

  • Implementation of the event test fixture factory

@SergioSim
SergioSim force-pushed the add-test-fixtures branch from 757aaa8 to 7b6a312 Compare May 19, 2020 15:12
@SergioSim SergioSim mentioned this pull request May 19, 2020
2 tasks
@jmaupetit
jmaupetit self-requested a review May 19, 2020 19:18
@SergioSim
SergioSim force-pushed the add-test-fixtures branch 4 times, most recently from 37d2271 to 2127a36 Compare May 20, 2020 15:31
@SergioSim
SergioSim force-pushed the add-test-fixtures branch 2 times, most recently from cb90dbf to 11189c2 Compare May 28, 2020 11:57
Comment thread tests/fixtures/event/proposal.py Outdated
@SergioSim
SergioSim force-pushed the add-test-fixtures branch 3 times, most recently from f65af66 to 3ee5e11 Compare June 5, 2020 14:38

@jmaupetit jmaupetit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
Comment thread tests/test_event_feedback_displayed.py Outdated
Comment thread tests/fixtures/event/proposal_marshmallow.py Outdated
@SergioSim
SergioSim force-pushed the add-test-fixtures branch 4 times, most recently from a89d787 to 9b4ed23 Compare June 8, 2020 23:57
Comment thread tests/fixtures/event/mixins.py Outdated
@SergioSim
SergioSim force-pushed the add-test-fixtures branch from d03d14a to 6e876f7 Compare June 11, 2020 13:22
Comment thread src/ralph/schemas/edx/base.py Outdated
Comment thread src/ralph/schemas/edx/base.py Outdated
Comment thread src/ralph/schemas/edx/base.py Outdated
Comment thread tests/fixtures/event/mixins.py Outdated
Comment thread tests/fixtures/event/mixins.py Outdated
@SergioSim
SergioSim force-pushed the add-test-fixtures branch 3 times, most recently from 6634331 to 499ccf3 Compare June 18, 2020 14:44
Comment thread tests/test_event_base.py Outdated
with pytest.raises(ValidationError):
base_events(1, ip=" ")
with pytest.raises(ValidationError):
base_events(1, ip="051.255.9.27")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the regex ip validation was removed this test does not raise an exception and silently corrects the ip from "051.255.9.27" to "51.255.9.27".
This causes the "event" to change after deserialisation/serialisation.
If this is not a problem it's good for me - removing this test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a problem to me.

@SergioSim
SergioSim force-pushed the add-test-fixtures branch 3 times, most recently from c763f38 to cae290c Compare July 7, 2020 07:50
Comment thread src/ralph/schemas/edx/browser.py Outdated
raise ValidationError("Event should contain a parsable JSON string")
keys = set(event.keys())
if len(required_keys.intersection(keys)) != 3:
if keys != required_keys:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not what we want, but rather:

Suggested change
if keys != required_keys:
if len(required_keys.intersection(keys)) != len(required_keys):

WDYT?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern here was that we might silently accept events having the required keys but also other keys that will be ignored in this case.
If this is not a problem, it's good for me, i will change that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From your experience, does this occurs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood it right, the event field is created by the client then send to the django back-end and in the back-end there is no validation (it just tries to parse the json if it's a string)
I suggest the event field can't be trusted as it might contain any values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so feel free to be more stringent then.

Comment thread src/ralph/schemas/edx/browser.py Outdated
)

@staticmethod
def parse_json_check_keys(data, required_keys):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def parse_json_check_keys(data, required_keys):
def validate_event_keys(data, required_keys):

Comment thread src/ralph/schemas/edx/browser.py Outdated
@staticmethod
def parse_json_check_keys(data, required_keys):
"""Parse JSON string and check that it contains the keys in the
`keys_array` and no other keys

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks - required_keys is an set

@SergioSim
SergioSim force-pushed the add-test-fixtures branch 2 times, most recently from a370591 to 1c8a1e1 Compare July 7, 2020 10:24
Comment thread src/ralph/schemas/edx/browser.py Outdated
Comment thread src/ralph/schemas/edx/base.py Outdated
Comment thread src/ralph/schemas/edx/base.py Outdated
Comment thread src/ralph/schemas/edx/base.py Outdated
Comment thread src/ralph/schemas/edx/browser.py Outdated
"textbook.pdf.searchcasesensitivity.toggled",
]

BROWSER_EVENT_VALID_AMAUNT = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same typo occurs in many lines:

Suggested change
BROWSER_EVENT_VALID_AMAUNT = [
BROWSER_EVENT_VALID_AMOUNT = [

Also look for amaunt: s/amaunt/amount/g

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch Julien, I made the mistake in my notes too, will change that

Comment thread src/ralph/schemas/edx/browser.py Outdated
if event["amaunt"] not in BROWSER_EVENT_VALID_AMAUNT:
raise ValidationError(
f"amaunt should be one of {BROWSER_EVENT_VALID_AMAUNT}"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is not a good idea to have a single BrowserEventSchema with x schema validation methods. This is not efficient at all! I would prefer having 1 schema per event and a BaseBrowserEventSchema to inherit from.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Idea, I will give it a try, thanks

@slandrault

Copy link
Copy Markdown

I didn't see any circle-ci config file. Maybe we could add one to run the test suite (and use it as a base in the future for more checks / build)? What do you think @jmaupetit ? Or maybe in a separate PR to also include some linters like in others openfun projects?

@SergioSim

Copy link
Copy Markdown
Collaborator Author

I didn't see any circle-ci config file. Maybe we could add one to run the test suite (and use it as a base in the future for more checks / build)? What do you think @jmaupetit ? Or maybe in a separate PR to also include some linters like in others openfun projects?

Hello @slandrault ,
do you search this config file https://github.com/openfun/ralph/blob/master/.circleci/config.yml ?

@slandrault

Copy link
Copy Markdown

I didn't see any circle-ci config file. Maybe we could add one to run the test suite (and use it as a base in the future for more checks / build)? What do you think @jmaupetit ? Or maybe in a separate PR to also include some linters like in others openfun projects?

Hello @slandrault ,
do you search this config file https://github.com/openfun/ralph/blob/master/.circleci/config.yml ?

😅 Awesome, I don't know why I didn't see it, I was probably on the wrong branch. All good then, sorry about that!

Comment thread tests/fixtures/edx/browser.py Outdated
@@ -0,0 +1,307 @@
"""
Broser event factory definitions

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Broser/Browser

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks, will update this

@SergioSim
SergioSim force-pushed the add-test-fixtures branch 4 times, most recently from c69457d to 03bc861 Compare November 13, 2020 16:03
- add server schema to validate server events
- add server event to xapi converter for the conversion
- remove pandas dependency
@SergioSim SergioSim mentioned this pull request Feb 4, 2021
10 tasks
@SergioSim

Copy link
Copy Markdown
Collaborator Author

Closing this pull request as it will be split into smaller pieces.
The first part is #59

@SergioSim SergioSim closed this Feb 10, 2021
@MYilFun00 MYilFun00 mentioned this pull request Jul 17, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants