Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Ajustes no pytest da branch master #16

Open
rochacbruno opened this issue Aug 28, 2018 · 2 comments
Open

Ajustes no pytest da branch master #16

rochacbruno opened this issue Aug 28, 2018 · 2 comments

Comments

@rochacbruno
Copy link
Owner

Ajustar pytest conforme a branch extended

atualizar PDF

@Riverfount
Copy link
Contributor

Oi @rochacbruno seria possível explicitar melhor o que precisa ser ajustado no pytest?

@rochacbruno
Copy link
Owner Author

diff --git a/tests/conftest.py b/tests/conftest.py
index 26d6c00..8fd0911 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,15 +1,23 @@
-import pytest
 from base64 import b64encode
+from contextlib import suppress
+
+import pytest
+
 from talkshow.app import create_app
+from talkshow.ext.login import create_user
 
 
-@pytest.fixture(scope="module")
+@pytest.fixture(scope='module')
 def app():
     """Flask Pytest uses it"""
-    return create_app()
+    _app = create_app(MONGODB_NAME='test_db')
+    with _app.app_context(), suppress(RuntimeError):
+        # creates new admin user to be used in tests if it does not exist
+        create_user("admin", "1234")
+    return _app
 
 
-@pytest.fixture(scope="module")
+@pytest.fixture(scope='module')
 def auth():
     """The Basic Auth credentials for testing"""
     credentials = b64encode(bytes("admin:1234", 'ascii')).decode('ascii')
diff --git a/tests/test_api.py b/tests/test_api.py
new file mode 100644
index 0000000..7a8f1b6
--- /dev/null
+++ b/tests/test_api.py
@@ -0,0 +1,29 @@
+def test_can_create_event(client, auth):
+    """Asserts an event can be created via API"""
+    event_data = {"name": "Puggies Convention", "date": "2018-09-09"}
+    created = client.post('/api/v1/event/', json=event_data, headers=auth)
+    assert created.status_code == 201
+
+
+def test_can_list_event(client):
+    """Asserts event can be listed"""
+    events = client.get('/api/v1/event/')
+    assert events.status_code == 200
+    assert 'events' in events.json
+
+
+def test_can_get_event_create(client):
+    events = client.get('/api/v1/event/puggies-convention')
+    assert events.status_code == 200
+
+
+def test_can_create_proposal_in_event(client, app):
+    proposal_event_data = {"name": "Emma Smith ",
+                           "email": "emma_smith@mail.com",
+                           "title": "Tutorial Flask",
+                           "description": "A simple base app as "
+                                          "example of Flask Architecture"}
+    events = client.post(f"/api/v1/event/{app.db['events'].find_one()['_id']}",
+                         json=proposal_event_data)
+    assert events.status_code == 201
+    assert 'proposal created' in events.json
diff --git a/tests/test_apy.py b/tests/test_apy.py
deleted file mode 100644
index 2a51ccf..0000000
--- a/tests/test_apy.py
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-def test_can_create_event(app, auth):
-    """Asserts an event can be created via API"""
-    event_data = {"name": "Puggies Convention", "date": "2018-09-09"}
-    with app.test_client() as client:
-        created = client.post('/api/v1/event/', json=event_data, headers=auth)
-        assert created.status_code == 201
-
-
-def test_can_list_event(app):
-    """Asserts event can be listed"""
-    with app.test_client() as client:
-        events = client.get('/api/v1/event/')
-        assert events.status_code == 200
-        assert 'events' in events.json

@rochacbruno rochacbruno changed the title Ajustes no pytest Ajustes no pytest da branch master Dec 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants