Add test fixtures#3
Conversation
757aaa8 to
7b6a312
Compare
37d2271 to
2127a36
Compare
cb90dbf to
11189c2
Compare
f65af66 to
3ee5e11
Compare
a89d787 to
9b4ed23
Compare
d03d14a to
6e876f7
Compare
6634331 to
499ccf3
Compare
| with pytest.raises(ValidationError): | ||
| base_events(1, ip=" ") | ||
| with pytest.raises(ValidationError): | ||
| base_events(1, ip="051.255.9.27") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
It's not a problem to me.
c763f38 to
cae290c
Compare
| raise ValidationError("Event should contain a parsable JSON string") | ||
| keys = set(event.keys()) | ||
| if len(required_keys.intersection(keys)) != 3: | ||
| if keys != required_keys: |
There was a problem hiding this comment.
I think this is not what we want, but rather:
| if keys != required_keys: | |
| if len(required_keys.intersection(keys)) != len(required_keys): |
WDYT?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
From your experience, does this occurs?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok, so feel free to be more stringent then.
| ) | ||
|
|
||
| @staticmethod | ||
| def parse_json_check_keys(data, required_keys): |
There was a problem hiding this comment.
| def parse_json_check_keys(data, required_keys): | |
| def validate_event_keys(data, required_keys): |
| @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 |
There was a problem hiding this comment.
Good catch, thanks - required_keys is an set
a370591 to
1c8a1e1
Compare
| "textbook.pdf.searchcasesensitivity.toggled", | ||
| ] | ||
|
|
||
| BROWSER_EVENT_VALID_AMAUNT = [ |
There was a problem hiding this comment.
The same typo occurs in many lines:
| BROWSER_EVENT_VALID_AMAUNT = [ | |
| BROWSER_EVENT_VALID_AMOUNT = [ |
Also look for amaunt: s/amaunt/amount/g
There was a problem hiding this comment.
Good catch Julien, I made the mistake in my notes too, will change that
| if event["amaunt"] not in BROWSER_EVENT_VALID_AMAUNT: | ||
| raise ValidationError( | ||
| f"amaunt should be one of {BROWSER_EVENT_VALID_AMAUNT}" | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Good Idea, I will give it a try, thanks
ec1b2eb to
6ca0282
Compare
|
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 , |
😅 Awesome, I don't know why I didn't see it, I was probably on the wrong branch. All good then, sorry about that! |
| @@ -0,0 +1,307 @@ | |||
| """ | |||
| Broser event factory definitions | |||
There was a problem hiding this comment.
Good catch, thanks, will update this
c69457d to
03bc861
Compare
e3a7965 to
f25b637
Compare
- add server schema to validate server events - add server event to xapi converter for the conversion - remove pandas dependency
f25b637 to
2da63b7
Compare
fc44f41 to
79279a2
Compare
|
Closing this pull request as it will be split into smaller pieces. |
Purpose
Proposal