Skip to content
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

[WIP] Gherkin feature suite #32

Draft
wants to merge 60 commits into
base: master
Choose a base branch
from
Draft

Conversation

domi41
Copy link

@domi41 domi41 commented Apr 27, 2020

Gherkin features ! #29

python manage.py behave

What I've got so far.

Esoteric (direct access to database)

  • Step: create user
  • Step: count users
  • Step: create poll
  • Step: count polls

Exoteric (via REST)

  • Step: register user
  • Step: submit poll
  • Step: vote in poll
  • Step: check poll winner

Tooling


This PR is definitely NOT atomic. Sorry about that. There's no way around it, the first PR is going to be big and will introduce breaking changes. I broke one thing, and once that anvil dropped…

Note from an old-timer:
Adding `.env` to the tree is not common, and may yield security risks.
What is usually done is to git ignore `.env` and provide a `.env.dist`.
This is usually considered a good practice (except in javascript -_-),
since it's versioning friendly and line-duplication friendly.
BREAKING CHANGE: old syntax won't work anymore
BREAKING CHANGE: `LANGUAGE_AVAILABLE` -> `LANGUAGES_AVAILABLE`
Let's experiment with `behave-django`.
The directory `features/fr` ought to be a git submodule.
We now need consent from everyone about the first scenario
before we can proceed.
Keep in mind that we need to write one scenario at a time,
then implement it, and then write another.
We must not write many scenarios at once.
It's going to be tempting.  Don't do it.
https://www.lesswrong.com/posts/uHYYA32CKgKT3FagE/hold-off-on-proposing-solutions
This should be considered like a Constitution,
where each article is thoroughly debated and carefully worded.
There will be some technical constraints in Gherkin
that Constitutions don't have.
This is a meta feature about the steps in the features.
This way I can work on stuff without deciding on the scenarios.
Note how naive parse_amount() is for now. … We cheated.
@domi41 domi41 changed the title [WIP] Feat gherkin [WIP] Gherkin feature suite Apr 27, 2020
"Requérir la présence à priori de scrutins."

Another brick in setting up the contexts
we'll want for our scenarios.
Language detection is a dummy for now.
But we're add a rather fault-intolerant but working YAML perser
to use with step pystrings.
I18N support is overall made of tape (not even cardboard).
election/models.py Outdated Show resolved Hide resolved
Eval is Evil.
– Your friend, _The Sign Painter_
Tested:
- raw assert (not explicit)
- describe (stale)
- compare (stale)
- nose-tools (very few tools, no?)

Not tested
- behave-pytest (404, did not inquire further)
- etc.

Looks like full I18N support is not coming out of the box.
https://github.com/oboff/hamcrest/issues/80
Inquiring further…
Our language pool is the one of `text2num`.  (at least en, fr, es)
Gherkin itself is widely translated and extendable in behave IIRC.

This commit introduces a huge list of `ISO 639-1` codes.
Esperanto is often overlooked in centralized databases.
Esoteric steps run from the inside and access the database directly.
Exoteric steps run from the outside and run REST requests.
Note: Shared context variables are tempting but ought to be scarce
and carefully though of, since they often incur inertia and creep.
This may eventually support email and id.
Behave is tricky to configure in order to show the output.
This step does not yield very useful information for now,
but it allows us to debug and experiment with behave conf.
Actors provide a handy layer over requests.
Especially useful once authentication kicks in.
Right now they are empty and hacky, but the idea is there.
I know, it's buried behind `/api/elections` for now.
A good idea is to prefix the API by `/v1`.
Just experimenting this pattern, to see if step defs get prettier.
…
And what's the cost.
Make sure when using print() in step defs to end it with a `\n`,
This is a pitfall of behave, I guess?

We can set the format to plain, using the --format plain CLI option,
since the `format = plain` in the `.behaverc` changes nothing.
When in plain format, there are no colors and our print() appears.
We tried behave 1.2.6 and 1.2.7-dev2.
This may well be solved by some tweaking.
Found out about `aloe`, and `pytest-bdd`.
This may well be solved by some experimenting.
Printing is not as good in behave as it is in other runners,
at least from an end-user perspective.
We hacked (very) partial I18N support in hamcrest.
Still need to figure out if we're going to use
`gettext` or `python-i18n`, or even something else.
Perhaps behave already does this behind the scenes.
It does not affect the output of the built-in AssertionError.
We also introduce a step to pass the time.
We'll move them into a submodule or a subtree?
Perhaps we should move to subtree?
Not sure.
…

I don't understand why this bug has been alive for years.
The Formatter interface is well-thought, thankfully.
@sonarcloud
Copy link

sonarcloud bot commented May 17, 2020

SonarCloud Quality Gate failed.

Bug C 22 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 69 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant