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

Add basic tests for repository CRUD. #28

Merged
merged 1 commit into from
Nov 12, 2015

Conversation

jeremycline
Copy link
Contributor

This commit also introduces a utils module which currently only
provides a function to generate random strings using uuid.uuid4.

@@ -0,0 +1,226 @@
# coding=utf-8
"""Test the `repository`_ API endpoints."""
Copy link
Contributor

Choose a reason for hiding this comment

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

No target is given for the "repository" reference. As a result, it should be broken. You can provide a target like so:

.. repository: https://example.com

Of course, you don't actually want to link the user to example.com.

@Ichimonji10
Copy link
Contributor

Can you run the new tests and paste the output here when done?

@jeremycline
Copy link
Contributor Author

Output is:

(pulp-smash)[vagrant@dev pulp-smash]$ python -m unittest2 discover pulp_smash
....F.........................
======================================================================
FAIL: test_body (tests.platform.api_v2.test_login.LoginFailureTestCase)
Assert that the response is valid JSON and has correct keys.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/devel/pulp-smash/pulp_smash/tests/platform/api_v2/test_login.py", line 69, in test_body
    _LOGIN_ERROR_KEYS,
AssertionError: Items in the first set but not the second:
u'http_request_method'
u'auth_error_code'
Items in the second set but not the first:
u'href'

======================================================================
FAIL: test_status_code (tests.platform.api_v2.test_repository.CreateFailureTestCase) [(400, [u'Incorrect data type'])]
Assert that each response has the expected HTTP status code.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/devel/pulp-smash/pulp_smash/tests/platform/api_v2/test_repository.py", line 118, in test_status_code
    self.assertEqual(response.status_code, self.bodies[i][0])
AssertionError: 500 != 400

======================================================================
FAIL: test_use_deleted_user (tests.platform.api_v2.test_user.ReadUpdateDeleteTestCase) [put]
Assert that one cannot read, update or delete a deleted user.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vagrant/devel/pulp-smash/pulp_smash/tests/platform/api_v2/test_user.py", line 169, in test_use_deleted_user
    self.assertEqual(response.status_code, 404)
AssertionError: 400 != 404

----------------------------------------------------------------------
Ran 32 tests in 2.966s

FAILED (failures=3)

I'm not sure what the problem is with the user tests, but the repository test should be failing (https://pulp.plan.io/issues/1356).

@asmacdo
Copy link
Contributor

asmacdo commented Nov 9, 2015

Line 169 is this failure: #34

@Ichimonji10
Copy link
Contributor

I believe the failing user test is an expected failure. There's a known bug tested by that API call, and... I don't have a link to it.

(400, {'id': None}),
(400, ['Incorrect data type']),
(400, {'missing_required_keys': 'id'}),
(409, {'id': identical_id}),
Copy link
Contributor

Choose a reason for hiding this comment

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

As per Exception Handling, these four API calls should return a call report with ERROR_KEYS. Can we add in a test method for that?

@Ichimonji10
Copy link
Contributor

The two new .rst files which have been added to the documentation are not accessible. Can you link to them from docs/api.rst?

attributes = {key: attributes[key] for key in self.bodies[0].keys()}
self.assertEqual(self.bodies[0], attributes)

def test_update_attributes_spawned_tasks(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add # noqa pylint:disable=invalid-name to the end of this line?

@Ichimonji10
Copy link
Contributor

As per #28 (comment), I'm going to refactor this module at a later point. Can you add # pylint:disable=duplicate-code to the top of the module of tests, with a comment explaining what's going on?

@Ichimonji10
Copy link
Contributor

I think that's about it. If you can address the points above, I think this is great.

with self.subTest(key):
self.assertIn(key, response['result'])
self.assertEqual(
self.update_body[key],
Copy link
Contributor

Choose a reason for hiding this comment

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

self.update_body['delta'][key]

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch. This could also be written as:

for key, value in self.update_body['delta'].items():
    with self.subTest(key=key):
        self.assertIn(key, response['result'])
        self.assertEqual(value, response['result'][key])

@Ichimonji10
Copy link
Contributor

@jeremycline Please rebase and apply this patch:

diff --git a/Makefile b/Makefile
index 22b7274..1dada96 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,9 @@ docs-clean:

 lint:
    flake8 .
-   pylint --reports=n --disable=I docs/conf.py pulp_smash tests setup.py
+   pylint --reports=n --disable=I docs/conf.py tests setup.py \
+       pulp_smash/{__init__,__main__,config,constants,utils}.py
+   pylint --reports=n --disable=I,duplicate-code pulp_smash/tests/

 test:
    python $(TEST_OPTIONS)

The above patch causes pylint to ignore any duplicate code in the pulp_smash.tests module. I dislike just ignoring this warning - it's there for a reason, and the proper solution is to use composition or some other mechanism to pull the commonalities out. But I'm willing to take on that technical debt for now.

@jeremycline jeremycline force-pushed the test-repository-basics branch 2 times, most recently from 4222c79 to bd4cc63 Compare November 10, 2015 20:49
@jeremycline
Copy link
Contributor Author

@Ichimonji10 I have made it so. Note that I had to add SHELL=/bin/bash in the Makefile to support the bash path expansion in that patch.

@Ichimonji10
Copy link
Contributor

@jeremycline Will that cause the makefile to break on systems that may not have bash installed, such as Mac OS (or Cygwin, or other more exotic *nix-like distros)?

@jeremycline
Copy link
Contributor Author

@Ichimonji10 Yes. Does /usr/bin/env sh work in OSX/*nix?

@Ichimonji10
Copy link
Contributor

I don't know. We can just expand those braces:

diff --git a/Makefile b/Makefile
index 22b7274..1dada96 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,9 @@ docs-clean:

 lint:
    flake8 .
-   pylint --reports=n --disable=I docs/conf.py pulp_smash tests setup.py
+   pylint --reports=n --disable=I docs/conf.py tests setup.py \
+       pulp_smash/__init__.py \
+       pulp_smash/__main__.py \
+       pulp_smash/config.py \
+       pulp_smash/constants.py \
+       pulp_smash/utils.py
+   pylint --reports=n --disable=I,duplicate-code pulp_smash/tests/

 test:
    python $(TEST_OPTIONS)

This commit also introduces a ``utils`` module which currently only
provides a function to generate random strings using ``uuid.uuid4``.
@jeremycline
Copy link
Contributor Author

I guess we could just do that.

@Ichimonji10
Copy link
Contributor

Ugly, but highly compatible.

@jeremycline
Copy link
Contributor Author

Very true. It is done.

@Ichimonji10
Copy link
Contributor

tony-stark-blows-kisses

@Ichimonji10 Ichimonji10 merged commit cda18c4 into pulp:master Nov 12, 2015
@jeremycline jeremycline deleted the test-repository-basics branch November 12, 2015 15:08
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.

3 participants