forked from versionone/VersionOne.SDK.Python
-
Notifications
You must be signed in to change notification settings - Fork 3
Use pytest instead of testtools #35
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
Open
ralittles
wants to merge
3
commits into
mtalexan:master
Choose a base branch
from
ralittles:use-pytest-instead-of-testtools
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
|
|
||
| importedOk=True | ||
|
|
||
| # Allow for tests that can't don't import this to use this file still | ||
| try: | ||
| import v1pysdk | ||
| except ImportError: | ||
| importedOk=False | ||
|
|
||
|
|
||
| class PublicTestServerConnection(): | ||
| username = 'admin' | ||
| password = 'admin' | ||
| address = 'www14.v1host.com' | ||
| instance = 'v1sdktesting' | ||
| scheme = 'https' | ||
| # must match scheme + "://" + address + "/" + instance | ||
| instance_url = 'https://www14.v1host.com/v1sdktesting' | ||
| token = '1.VdeWXQVNdY0yVpYexTtznCxcWTQ=' | ||
|
|
||
| def __init__(): | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def getV1Meta(): | ||
| """Creates a V1Meta object from the default configuration and returns it | ||
| """ | ||
| # If we couldn't import the v1pysdk, we can't create the object | ||
| if not importedOk: | ||
| return None | ||
| else: | ||
| return v1pysdk.V1Meta( | ||
| address = PublicTestServerConnection.address, | ||
| instance = PublicTestServerConnection.instance, | ||
| scheme = 'https', | ||
| username = PublicTestServerConnection.username, | ||
| password = PublicTestServerConnection.password, | ||
| ) | ||
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,6 @@ | ||
| import pytest | ||
| import common_test_server | ||
|
|
||
| @pytest.fixture | ||
| def v1(): | ||
| return common_test_server.PublicTestServerConnection.getV1Meta() |
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,54 @@ | ||
| import math | ||
|
|
||
| import pytest | ||
|
|
||
| import v1pysdk | ||
|
|
||
|
|
||
| class TestV1CommonSetup(): | ||
| def test_initial_create_story(self, v1): | ||
| """Creates a very simple story and returns the object""" | ||
| #v1StoryName = self.getUniqueString() | ||
| v1StoryName = "tests.query_tests.TestV1Query.test_find_query-1" | ||
| defaultEstimate = 1.0 | ||
| reference = "http://test.com" | ||
|
|
||
| scope = v1.Scope.select('Name').page(size=1) | ||
| defaultScope = None | ||
| if len(scope) > 0: | ||
| defaultScope = scope.first() | ||
|
|
||
| epic = v1.Epic.select('Name').page(size=1) | ||
| defaultSuper = None | ||
| if len(epic) > 0: | ||
| defaultSuper = epic.first() | ||
|
|
||
| # build a filter string that exactly matches what we've set above | ||
| baseFilterStr = "Reference='" + reference + "'&DetailEstimate='" + str(defaultEstimate) + "'&" | ||
| if defaultScope: | ||
| baseFilterStr += "Scope.Name='" + defaultScope.Name + "'&" | ||
| if defaultSuper: | ||
| baseFilterStr += "Super.Name='" + defaultSuper.Name + "'&" | ||
| baseFilterStr += "Name='" + v1StoryName + "'" | ||
|
|
||
| newStory = None | ||
| try: | ||
| newStory = v1.Story.create( | ||
| Name = v1StoryName, | ||
| Scope = defaultScope, | ||
| Super = defaultSuper, | ||
| DetailEstimate = defaultEstimate, | ||
| Reference = reference, | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail("Error creating new story: {0}".format(str(e))) | ||
|
|
||
| #Perform a readback using the constructed filter to make sure the item's on the server | ||
|
|
||
| createdItems = v1.Story.select('Name').filter(baseFilterStr) | ||
| for t in createdItems: # run query, but don't throw an exception if nothing is returned | ||
| pass | ||
|
|
||
| assert(len(createdItems) > 0, "Created item can't be queried") | ||
|
|
||
| return newStory |
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,214 @@ | ||
| import sys | ||
| if sys.version_info >= (3,0): | ||
| from urllib.error import HTTPError | ||
| else: | ||
| from urllib2 import HTTPError | ||
|
|
||
| # try the old version, then fallback to the new one | ||
| try: | ||
| from xml.etree import ElementTree | ||
| from xml.etree.ElementTree import parse, fromstring, Element | ||
| except ImportError: | ||
| from elementtree import ElementTree | ||
| from elementtree.ElementTree import parse, fromstring, Element | ||
|
|
||
| from v1pysdk.client import * | ||
| from v1pysdk import V1Meta | ||
| from common_test_server import PublicTestServerConnection | ||
|
|
||
| import pytest | ||
|
|
||
| class TestV1Connection(): | ||
| def test_connect(self): | ||
| username = PublicTestServerConnection.username | ||
| password = PublicTestServerConnection.password | ||
| address = PublicTestServerConnection.address | ||
| instance = PublicTestServerConnection.instance | ||
|
|
||
| server = V1Server(address=address, username=username, password=password,instance=instance) | ||
| # The story names, but limit to only the first result so we don't get inundated with results | ||
| code, body = server.fetch('/rest-1.v1/Data/Story?sel=Name&page=1,0') | ||
|
|
||
| elem = fromstring(body) | ||
| assert(elem.tag == 'Assets') | ||
|
|
||
| def test_meta_connect_instance_url(self): | ||
| v1 = None | ||
| try: | ||
| v1 = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| username = PublicTestServerConnection.username, | ||
| password = PublicTestServerConnection.password, | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail("Error trying to create connection: {0}".format(str(e))) | ||
|
|
||
| try: | ||
| items = v1.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error running query from connection: {0}".format(str(e))) | ||
|
|
||
| def test_meta_connect_instance_and_address(self): | ||
| v1 = None | ||
| try: | ||
| v1 = V1Meta( | ||
| address = PublicTestServerConnection.address, | ||
| instance = PublicTestServerConnection.instance, | ||
| username = PublicTestServerConnection.username, | ||
| password = PublicTestServerConnection.password, | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail("Error trying to create connection: {0}".format(str(e))) | ||
| try: | ||
| items = v1.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error running query from connection: {0}".format(str(e))) | ||
|
|
||
| def test_meta_connect_instance_url_overrides_separate(self): | ||
| v1 = None | ||
| address = '' | ||
| instance = None | ||
|
|
||
| try: | ||
| v1 = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| address = address, | ||
| instance = instance, | ||
| username = PublicTestServerConnection.username, | ||
| password = PublicTestServerConnection.password, | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail("Error trying to create connection: {0}".format(str(e))) | ||
|
|
||
| try: | ||
| items = v1.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error trying to create connection: {0}".format(str(e))) | ||
|
|
||
| def test_meta_connect_oauth(self): | ||
| v1 = None | ||
| try: | ||
| v1 = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| #no username | ||
| password = PublicTestServerConnection.token, | ||
| use_password_as_token=True, | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail("Error trying to create connection: {0}".format(str(e))) | ||
|
|
||
| try: | ||
| items = v1.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error running query from connection: {0}".format(str(e))) | ||
|
|
||
| def test_meta_connect_oauth_ignores_username(self): | ||
| v1 = None | ||
| username = '' | ||
|
|
||
| try: | ||
| v1 = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| username = username, | ||
| password = PublicTestServerConnection.token, | ||
| use_password_as_token=True, | ||
| ) | ||
| except Exception as e: | ||
| pytest.fail("Error trying to create connection: {0}".format(str(e))) | ||
|
|
||
| try: | ||
| items = v1.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error running query from connection: {0}".format(str(e))) | ||
|
|
||
| def test_connect_fails_when_invalid(self): | ||
| v1bad = None | ||
| username = '' | ||
| password = '' | ||
|
|
||
| try: | ||
| v1bad = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| username = username, | ||
| password = password, | ||
| use_password_as_token=False, | ||
| ) | ||
| # we have to try to use it to get it to connect and fail | ||
| items = v1bad.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except HTTPError as e: | ||
| assert(str(e.code) == '401', "Connection failed for reasons other than authorization") | ||
| else: | ||
| pytest.fail("Connection succeeded with bad credentials.") | ||
|
|
||
| def test_reconnect_succeeds_after_invalid(self): | ||
| v1bad = None | ||
| username = '' | ||
| password = '' | ||
|
|
||
| try: | ||
| v1bad = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| username = username, | ||
| password = password, | ||
| use_password_as_token=False, | ||
| ) | ||
| items = v1bad.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except HTTPError as e: | ||
| assert(str(e.code) == '401', "Connection failed for reasons other than authorization") | ||
| else: | ||
| pytest.fail("First connection succeeded with bad credentials, cannot continue test") | ||
|
|
||
| v1good = None | ||
|
|
||
| # Connect correctly first | ||
| try: | ||
| v1good = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| password = PublicTestServerConnection.token, | ||
| use_password_as_token=True, | ||
| ) | ||
| items = v1good.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error running query from good connection: {0}".format(str(e))) | ||
|
|
||
| def test_reconnect_fails_when_invalid(self): | ||
| v1good = None | ||
|
|
||
| # Connect correctly first | ||
| try: | ||
| v1good = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| password = PublicTestServerConnection.token, | ||
| use_password_as_token=True, | ||
| ) | ||
| items = v1good.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except Exception as e: | ||
| pytest.fail("Error running query from good connection: {0}".format(str(e))) | ||
|
|
||
| v1bad = None | ||
| username = '' | ||
|
|
||
| password = '' | ||
|
|
||
| try: | ||
| v1bad = V1Meta( | ||
| instance_url = PublicTestServerConnection.instance_url, | ||
| username = username, | ||
| password = password, | ||
| use_password_as_token=False, | ||
| ) | ||
| items = v1bad.Story.select('Name').page(size=1) | ||
| items.first() #run the query | ||
| except HTTPError as e: | ||
| assert(str(e.code) == "401", "Connection failed for reasons other than authorization") | ||
| else: | ||
| assert(str(e.code) == "401", "Second connection failed for reasons other than authorization") |
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,10 @@ | ||
| import v1pysdk | ||
| import common_test_server | ||
| from test_common_setup import TestV1CommonSetup | ||
|
|
||
| class TestV1Create(TestV1CommonSetup): | ||
| def test_create_story(self, v1): | ||
| """Creates a very simple story""" | ||
| with common_test_server.PublicTestServerConnection.getV1Meta() as v1: | ||
| # common setup already does this and tests the creation, it just needs a V1 instance to work on | ||
| self.test_initial_create_story(v1) |
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,52 @@ | ||
| """ | ||
| from testtools import TestCase | ||
| from testtools.assertions import assert_that | ||
| from testtools.content import text_content | ||
| from testtools.matchers import Equals | ||
| """ | ||
|
|
||
| import v1pysdk | ||
| from common_test_server import PublicTestServerConnection | ||
| import common_test_server | ||
| import test_common_setup | ||
| import pytest | ||
|
|
||
|
|
||
| class TestV1Operations(test_common_setup.TestV1CommonSetup): | ||
| def test_quick_close_and_reopen(self): | ||
| """Creates a story, quick closes it, then reopens it, then quick closes again""" | ||
| with common_test_server.PublicTestServerConnection.getV1Meta() as v1: | ||
| newStory = None | ||
| try: | ||
| newStory = self.test_initial_create_story(v1) | ||
| except Exception as e: | ||
| pytest.fail("Unable to setup by creating initial test story: {0}".format(str(e))) | ||
|
|
||
| assert(newStory.IsClosed == False, "New story created already closed, cannot test") | ||
|
|
||
| try: | ||
| newStory.QuickClose() | ||
| except Exception as e: | ||
| pytest.fail("Error while quick closing story: {0}".format(str(e))) | ||
|
|
||
| try: | ||
| v1.commit() | ||
| except Exception as e: | ||
| pytest.fail("Error while syncing commits after close {0}".format(str(e))) | ||
|
|
||
| assert(newStory.IsClosed == True, "Story didn't close when QuickClose() was called") | ||
|
|
||
| try: | ||
| newStory.Reactivate() | ||
| except Exception as e: | ||
| pytest.fail("Error while reactivating story {0}".format(str(e))) | ||
|
|
||
| try: | ||
| v1.commit() | ||
| except Exception as e: | ||
| pytest.fail("Error while syncing commits after reactivation") | ||
| assert(newStory.IsClosed == 'false', "Story didn't re-open when Reactivate() was called") | ||
|
|
||
| # "cleanup" by closing the story | ||
| newStory.QuickClose() | ||
| v1.commit() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.