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

Feature/token refactor #23

Merged
merged 29 commits into from
Oct 1, 2021
Merged

Feature/token refactor #23

merged 29 commits into from
Oct 1, 2021

Conversation

Nathan-Nesbitt
Copy link
Contributor

No description provided.

@Nathan-Nesbitt Nathan-Nesbitt marked this pull request as draft September 9, 2021 20:13
Copy link
Member

@hillairet hillairet left a comment

Choose a reason for hiding this comment

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

I know it's a work in progress so probably some of the comments are not applicable. But I thought I'd check things out to guarantee alignment early on.

spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
@Nathan-Nesbitt
Copy link
Contributor Author

@hillairet This looks like a big PR, most of the changes are just moving files around in testing to support the tests for the two new tokens.

This is what I have at the moment, these were just quick tests to be sure that what I changed works, but I think it could just be one unit test with different parameters for the online and offline tokens:
image

Let me know your preference for layout!

@hillairet
Copy link
Member

Cool looks like we are getting there.
We have to be careful not to retest the same code and double our tests code base.
The graphql and rest methods belong to Token, not OfflineTokenABC or OnlineTokenABC. So there is no point testing the GraphQL and Rest code twice. You can create a class in your test code inheriting from Token and testing Rest and GraphQL directly. We don't need to test python's abstract classes mechanisms.
Testing the initialization is fine though with abstract classes, not sure what we are really testing.
Also let's not make the directory structure more complicated and deep than it needs to be:

/tests
     |- token
            |- test_initialization.py    # for the initialization of OfflineToken and OnlineToken
            |- test_graphql_base.py
            |- test_graphql_operation_name.py
            |- test_graphql_throttling.py
            |- test_rest.py

Also instead of shared.py you should use pytest fixtures which will be much better than having from ...shared import xxx

@Nathan-Nesbitt
Copy link
Contributor Author

This should be stable now, there is one error in the typing

spylib/token.py:235: error: Argument "headers" to "post" of "AsyncClient" has incompatible type "Dict[str, Optional[str]]"; expected "Union[Headers, Dict[str, str], Dict[bytes, bytes], Sequence[Tuple[str, str]], Sequence[Tuple[bytes, bytes]], None]"

This comes from the AsyncClient.post() method, and doesn't match their docs for what the expected input is.

I have opened a discussion with the devs on httpx as it is not clear what the input should be, but I will update this as soon as I know what's going wrong.

@Nathan-Nesbitt Nathan-Nesbitt marked this pull request as ready for review September 15, 2021 19:26
Copy link
Member

@hillairet hillairet left a comment

Choose a reason for hiding this comment

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

The README.md needs a good update.

I know I suggested that but now looking at the initialization test, I'm not sure what they are testing. We want to be testing our code, not python itself. You wrote a save token and load token for the test at you are testing that ... not sure what we are verifying here ...
It's ok to have them but they are kind of useless, at least part of the test is.

spylib/token.py Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
tests/token/conftest.py Outdated Show resolved Hide resolved
tests/token/conftest.py Outdated Show resolved Hide resolved
Copy link
Member

@hillairet hillairet left a comment

Choose a reason for hiding this comment

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

Ok on closer second inspection:

  • test_token, test_online_token, and test_offline_token are ok as they test some default values
  • test_save_token, test_load_token, test_save_offline_token and test_load_offline_token test the testing code you wrote in conftest.py so let's remove them. Let's not maintain code testing the test code. When we have a large set of tests, we don't want to have to keep these ones up to date too.

tests/token/test_rest.py Outdated Show resolved Hide resolved
Copy link
Member

@hillairet hillairet left a comment

Choose a reason for hiding this comment

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

More than I expected.
Now that there are changes ... In the docs you put online token before offline token. During the oauth we always get the offline token first since we get the app's token before we get a user's token. I'd follow the same order in the docs.

spylib/exceptions.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
tests/token_classes.py Outdated Show resolved Hide resolved
tests/token/test_rest.py Outdated Show resolved Hide resolved
@Nathan-Nesbitt
Copy link
Contributor Author

Nathan-Nesbitt commented Sep 27, 2021

@hillairet this is something I noticed when developing using this using the current design:

Screenshot from 2021-09-27 06-32-48

Since we aren't defining the __init__ for the classes it is using the default text for a pydantic object. I know the hope was to not have to do this, but can we add in the __init__ as it helps by showing the expected arguments? Unless you know a trick to get this functionality without it?

@Nathan-Nesbitt Nathan-Nesbitt requested review from hillairet and removed request for hillairet September 27, 2021 13:42
@hillairet
Copy link
Member

@hillairet this is something I noticed when developing using this using the current design:

Screenshot from 2021-09-27 06-32-48

Since we aren't defining the __init__ for the classes it is using the default text for a pydantic object. I know the hope was to not have to do this, but can we add in the __init__ as it helps by showing the expected arguments? Unless you know a trick to get this functionality without it?

Please make an issue for this and let's do that later. This PR doesn't have to be perfect or complete.

Copy link
Member

@hillairet hillairet left a comment

Choose a reason for hiding this comment

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

We might get there eventually.

tests/token/test_graphql_throttling.py Outdated Show resolved Hide resolved
tests/token/test_graphql_throttling.py Outdated Show resolved Hide resolved
tests/token/test_graphql_throttling.py Outdated Show resolved Hide resolved
tests/token/test_graphql_operation_names.py Outdated Show resolved Hide resolved
tests/token/test_graphql_operation_names.py Outdated Show resolved Hide resolved
tests/token/test_graphql_base.py Outdated Show resolved Hide resolved
tests/token/test_graphql_base.py Outdated Show resolved Hide resolved
tests/token/test_graphql_base.py Outdated Show resolved Hide resolved
spylib/token.py Outdated Show resolved Hide resolved
Copy link
Member

@hillairet hillairet left a comment

Choose a reason for hiding this comment

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

🎉 🥳 🎊

@Nathan-Nesbitt Nathan-Nesbitt merged commit 04af826 into main Oct 1, 2021
@Nathan-Nesbitt Nathan-Nesbitt linked an issue Oct 1, 2021 that may be closed by this pull request
@lishanl lishanl deleted the feature/token-refactor branch March 16, 2022 03:25
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.

Refactor Store class
2 participants