Skip to content

Ensure a session is passed through to GitHubCore #774

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

Merged
merged 2 commits into from
Feb 3, 2018

Conversation

omgjlk
Copy link
Collaborator

@omgjlk omgjlk commented Jan 25, 2018

Unless a session (or a self) is passed through a new session might be
created, which can lead to some interesting things. See #770

This also adds a session class argument for PullDestination and updates
the calls to it.

A future commit will make the session argument of GitHubCore
nonoptional.

Related-to: #771

Signed-off-by: Jesse Keating omgjlk@github.com

Unless a session (or a self) is passed through a new session might be
created, which can lead to some interesting things. See sigmavirus24#770

This also adds a session class argument for PullDestination and updates
the calls to it.

A future commit will make the session argument of GitHubCore
nonoptional.

Related-to: sigmavirus24#771

Signed-off-by: Jesse Keating <omgjlk@github.com>
@omgjlk omgjlk force-pushed the send-the-session-771 branch 2 times, most recently from 59d3762 to 52fe8e0 Compare January 25, 2018 03:47
Copy link
Owner

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

One thought and request for your opinion. I'd prefer we use the auto-spec'd GitHubSession mock in our unit tests for consistency. Otherwise, everything looks fabulous. Thanks :)

@@ -57,7 +58,8 @@ class GitHub(GitHubCore):
"""

def __init__(self, username='', password='', token=''):
super(GitHub, self).__init__({})
session = GitHubSession()
Copy link
Owner

Choose a reason for hiding this comment

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

One thing that was convenient in the past was not having calls to GitHubSession sprinkled everywhere. What do you think of having a GitHubCore method new_session that returns a new GitHubSession so we can do

super(GitHub, self).__init__({}, self.new_session())

And likewise with other things like GitHubStatus.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that could work pretty well. Mostly I was trying to avoid the end user from having to instantiate their own session first, so that they could continue using foo = GitHub() as they do today. Your way should still support that, I'll play around with it.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I agree that the user shouldn't have to instantiate it themselves.

@@ -50,14 +52,14 @@ def test_none_creator(self):
"""Show that creator is None when json attribute is set to None."""
json = self.instance.as_dict().copy()
json['creator'] = None
milestone = github3.issues.milestone.Milestone(json)
milestone = github3.issues.milestone.Milestone(json, session)
Copy link
Owner

Choose a reason for hiding this comment

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

There's a create_session method on our UnitHelper classes. Please use that. It ensures we never accidentally talk to the internet in our unit tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool, I was very unsure about these bits in tests. Glad to have your input 👍

@@ -105,7 +107,7 @@ def test_exposes_attributes(self):

def test_from_json(self):
"""Verify that method returns GitHubObject from json."""
github_core = GitHubCore.from_json('{}')
github_core = GitHubCore.from_json('{}', session)
Copy link
Owner

Choose a reason for hiding this comment

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

Same here

We want the session to always be there. This change makes it required
and updates the various places that broke.

Fixes: 771

Signed-off-by: Jesse Keating <omgjlk@github.com>
@omgjlk omgjlk force-pushed the send-the-session-771 branch from 52fe8e0 to c8e256c Compare February 1, 2018 00:37
@omgjlk
Copy link
Collaborator Author

omgjlk commented Feb 1, 2018

I think I addressed the concerns! Please review again @sigmavirus24

@sigmavirus24 sigmavirus24 merged commit f8487f7 into sigmavirus24:develop Feb 3, 2018
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.

2 participants