-
Notifications
You must be signed in to change notification settings - Fork 11
Improve/client: update public api and refactoring #15
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e357d60
refactor!: /s/environment_id/environment_api_key
gagantrivedi f22a6d9
docs(flagsmith)Add type hints
gagantrivedi 61cabeb
[minor refactoring]
gagantrivedi 255f67c
refactor: move generate_header content to utils
gagantrivedi d284f7b
refactor(analytics): accept http_headers as arg instead of env_key
gagantrivedi 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import typing | ||
|
|
||
|
|
||
| def generate_header_content( | ||
| environment_key: str, headers: typing.Dict[str, str] = None | ||
| ) -> typing.Dict[str, str]: | ||
| """ | ||
| Generates required header content for accessing API | ||
| :param headers: (optional) dictionary of other required header values | ||
| :return: dictionary with required environment header appended to it | ||
| """ | ||
| headers = headers or {} | ||
|
|
||
| headers["X-Environment-Key"] = environment_key | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably pull this out into a constant API_TOKEN_HEADER = "X-Environment-Key" |
||
| return headers | ||
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 |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| import pytest | ||
|
|
||
| from flagsmith.analytics import AnalyticsProcessor | ||
| from flagsmith.utils import generate_header_content | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def analytics_processor(): | ||
| return AnalyticsProcessor( | ||
| environment_key="test_key", base_api_url="http://test_url" | ||
| base_api_url="http://test_url", http_headers=generate_header_content("test_key") | ||
| ) |
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 |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ class FlagsmithTestCase(TestCase): | |
| test_environment_key = "test-env-key" | ||
|
|
||
| def setUp(self) -> None: | ||
| self.bt = Flagsmith(environment_id=self.test_environment_key, api=TEST_API_URL) | ||
| self.bt = Flagsmith(environment_key=self.test_environment_key, api=TEST_API_URL) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also change this from |
||
|
|
||
| @mock.patch( | ||
| "flagsmith.flagsmith.requests.get", | ||
|
|
||
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,23 @@ | ||
| from flagsmith.utils import generate_header_content | ||
|
|
||
|
|
||
| def test_generate_header_content_returns_dict_with_api_key(): | ||
| # Given | ||
| environment_key = "api_key" | ||
|
|
||
| # When | ||
| headers = generate_header_content(environment_key) | ||
|
|
||
| # Then | ||
| assert headers == {"X-Environment-Key": environment_key} | ||
|
|
||
|
|
||
| def test_generate_header_content_appends_headers_to_header_arg_if_present(): | ||
| # Given | ||
| environment_key = "api_key" | ||
| given_headers = {"Host": "test"} | ||
| # When | ||
| headers = generate_header_content(environment_key, given_headers) | ||
|
|
||
| # Then | ||
| assert headers == {"X-Environment-Key": environment_key, **given_headers} |
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.
Since we're changing the method signatures, we should change this from
identitytoidentifier.