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

Adapt and modify tests #299

Merged
merged 5 commits into from
Dec 22, 2018
Merged

Adapt and modify tests #299

merged 5 commits into from
Dec 22, 2018

Conversation

vddesai1871
Copy link
Contributor

Fixes #296

Checklist

  • My branch is up-to-date with upstream/develop branch.
  • Everything works and tested for Python 3.5.2 and above.

Description

Adapts the tests in test_app.py to recent changes.

Test Logs

(h) vishal@vishal:~/oss/hydrus$ pytest hydrus/tests/
============================================================ test session starts ============================================================
platform linux -- Python 3.5.2, pytest-3.4.2, py-1.5.2, pluggy-0.6.0
rootdir: /home/vishal/oss/hydrus, inifile:
collected 51 items                                                                                                                          

hydrus/tests/test_app.py ................                                                                                             [ 31%]
hydrus/tests/test_auth.py ..........                                                                                                  [ 50%]
hydrus/tests/test_crud.py ............                                                                                                [ 74%]
hydrus/tests/test_doc_writer.py ....                                                                                                  [ 82%]
hydrus/tests/test_parser.py .........                                                                                                 [100%]

========================================================= 51 passed in 3.88 seconds =========================================================
(h) vishal@vishal:~/oss/hydrus$ git add hydrus/samples/doc_writer_sample.py

Changes log

Debugs various errors mentioned in #296

Added

  • Feature 1
  • Feature 2

Changed

  • Change 1
  • Change 2

Fixed

  • Bug 1

Removed

  • Deprecated feature 1

@chrizandr
Copy link
Member

It would be good if you could also try and run this test for another API documentation, other than the dummy one created in the sample. Maybe try for the flock-demo documentation and see if all tests pass.

@vddesai1871
Copy link
Contributor Author

vddesai1871 commented Dec 8, 2018

Maybe try for the flock-demo documentation and see if all tests pass.

2 tests are failing because I am assuming if an endpoint class has POST or DELETE or GET method it must have a PUT method, so I am using put(directly without checking if class supports PUT operation) to add a new object before testing for GET, POST and DELETE.
(Area class in flock-demo is an endpoint class and doesn't have PUT method defined but has POST defined)
This piece of code is being used for testing endpoint class POST requests

                    if "POST" in class_methods:
                        dummy_object = gen_dummy_object(class_.title, self.doc)
                        put_response = self.client.put(
                            endpoints[class_name], data=json.dumps(dummy_object)
                        )
                        assert put_response.status_code == 201
                        post_response = self.client.post(
                            endpoints[class_name], data=json.dumps(dummy_object))
                        assert post_response.status_code == 200

@Mec-iS
Copy link
Contributor

Mec-iS commented Dec 8, 2018

it is not mandatory for any endpoint to have other methods beside the ones it declares in the doc. So the test should be fixed to test only the methods allowed by the endpoint, the others should return Method Not Allowed.

@Mec-iS
Copy link
Contributor

Mec-iS commented Dec 8, 2018

in the context of a unit test, every test case should be absolutely independent from other tests. So in this case, and any similar cases, we should insert the item using the ORM and then test only the GET:

def test_get_method(self):
     # test setup
     Item.create(...)
     
     # assertion
     assert requests.get(...).status_code == 200

Even better: the item creation should be in the class' setUp method (check unittest.TestCase.setUp in standard library) and reused by all the tests in the class.

@vddesai1871
Copy link
Contributor Author

It would be good if you could also try and run this test for another API documentation, other than the dummy one created in the sample. Maybe try for the flock-demo documentation and see if all tests pass.

Yes now tests are passing for flock-demo doc. Thanks!

@@ -58,17 +71,46 @@
op_returns,
op_status)


"""Add the operation to the Class"""
"""Same way add DELETE, PUT and GET operations"""
Copy link
Member

Choose a reason for hiding this comment

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

@vddesai1871 Looks good! Could you please replace the """ with simple comments.

@xadahiya
Copy link
Member

Also, can you fix this deprecation warning?
annotation 2018-12-19 153045

@vddesai1871
Copy link
Contributor Author

Also, can you fix this deprecation warning?

I don't think I can do anything about this. It is related to pyyaml's compatibility with pythin 3.7 they are woking on it

@xadahiya xadahiya merged commit b650fe5 into HTTP-APIs:develop Dec 22, 2018
@vddesai1871 vddesai1871 deleted the test branch January 5, 2019 08:26
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.

4 participants