| |
@@ -4,6 +4,7 @@
|
| |
import http.client as httplib
|
| |
|
| |
import mock
|
| |
+ import pytest
|
| |
|
| |
from blockerbugs import db
|
| |
from blockerbugs import app
|
| |
@@ -18,50 +19,50 @@
|
| |
from blockerbugs.util import pagure_bot
|
| |
|
| |
|
| |
- class TestRestAPI(object):
|
| |
- @classmethod
|
| |
- def setup_class(cls):
|
| |
+ @pytest.mark.usefixtures('app_ctx', 'setup_teardown')
|
| |
+ class TestRestAPI:
|
| |
+ @pytest.fixture
|
| |
+ def setup_teardown(self):
|
| |
+ # === setup ===
|
| |
db.session.rollback()
|
| |
db.drop_all()
|
| |
db.create_all()
|
| |
- s = db.session()
|
| |
- s.expire_on_commit = False # avoid LazyLoading error, https://docs.sqlalchemy.org/en/14/errors.html#error-bhk3
|
| |
- cls.client = app.test_client()
|
| |
- cls.release = add_release(99)
|
| |
- cls.milestone = add_milestone(cls.release, 'final', 100, 101,
|
| |
+ self.client = app.test_client()
|
| |
+ self.release = add_release(99)
|
| |
+ self.milestone = add_milestone(self.release, 'final', 100, 101,
|
| |
'99-final', True)
|
| |
- cls.milestone.current = True
|
| |
+ self.milestone.current = True
|
| |
|
| |
- cls.milestone2 = add_milestone(cls.release, 'beta', 200, 201,
|
| |
+ self.milestone2 = add_milestone(self.release, 'beta', 200, 201,
|
| |
'99-beta')
|
| |
- bug1 = add_bug(9000, 'testbug1', cls.milestone)
|
| |
+ bug1 = add_bug(9000, 'testbug1', self.milestone)
|
| |
bug1.accepted_fe = True
|
| |
bug1.status = 'CLOSED'
|
| |
bug1.discussion_link = 'example.com'
|
| |
- bug1copy = add_bug(9000, 'testbug1', cls.milestone2) # different milestone than bug1
|
| |
+ bug1copy = add_bug(9000, 'testbug1', self.milestone2) # different milestone than bug1
|
| |
bug1copy.accepted_fe = True
|
| |
bug1copy.status = 'CLOSED'
|
| |
- bug2 = add_bug(9002, 'testbug2', cls.milestone)
|
| |
+ bug2 = add_bug(9002, 'testbug2', self.milestone)
|
| |
bug2.accepted_blocker = False
|
| |
bug2.proposed_fe = True
|
| |
- bug2copy = add_bug(9002, 'testbug2', cls.milestone2) # different milestone than bug2
|
| |
+ bug2copy = add_bug(9002, 'testbug2', self.milestone2) # different milestone than bug2
|
| |
bug2copy.accepted_blocker = False
|
| |
bug2copy.proposed_fe = True
|
| |
- bug3 = add_bug(9003, 'testbug3', cls.milestone)
|
| |
+ bug3 = add_bug(9003, 'testbug3', self.milestone)
|
| |
bug3.accepted_blocker = False
|
| |
bug3.proposed_fe = True
|
| |
- bug4 = add_bug(9003, 'testbug3', cls.milestone2) # different milestone and proposals than bug3
|
| |
+ bug4 = add_bug(9003, 'testbug3', self.milestone2) # different milestone and proposals than bug3
|
| |
bug4.accepted_blocker = True
|
| |
bug4.proposed_fe = False
|
| |
bug4.status = 'CLOSED'
|
| |
- cls.update_pending_stable = add_update('test-pending-stable.fc99', cls.release, 'testing',
|
| |
- [bug1, bug1copy])
|
| |
- cls.update_pending_stable.date_submitted = datetime(1990, 1, 1)
|
| |
- cls.update_pending_stable.request = 'stable'
|
| |
- cls.update_pending_stable.title = 'mega fixer'
|
| |
- cls.update_testing2 = add_update('test-testing2.fc99', cls.release, 'testing', [bug2])
|
| |
-
|
| |
- cls.webhook_data = {
|
| |
+ self.update_pending_stable = add_update('test-pending-stable.fc99', self.release, 'testing',
|
| |
+ [bug1, bug1copy])
|
| |
+ self.update_pending_stable.date_submitted = datetime(1990, 1, 1)
|
| |
+ self.update_pending_stable.request = 'stable'
|
| |
+ self.update_pending_stable.title = 'mega fixer'
|
| |
+ self.update_testing2 = add_update('test-testing2.fc99', self.release, 'testing', [bug2])
|
| |
+
|
| |
+ self.webhook_data = {
|
| |
'msg': {
|
| |
'issue': {
|
| |
'id': 6666,
|
| |
@@ -71,14 +72,16 @@
|
| |
'topic': 'issue.comment.added',
|
| |
}
|
| |
|
| |
- cls.api_user = UserInfo('api_user')
|
| |
- passwd = cls.api_user.generate_api_key()
|
| |
- cls.headers = {'X-Auth-User': 'api_user', 'X-Auth-Key': passwd}
|
| |
- db.session.add(cls.api_user)
|
| |
+ self.api_user = UserInfo('api_user')
|
| |
+ passwd = self.api_user.generate_api_key()
|
| |
+ self.headers = {'X-Auth-User': 'api_user', 'X-Auth-Key': passwd}
|
| |
+ db.session.add(self.api_user)
|
| |
db.session.commit()
|
| |
|
| |
- @classmethod
|
| |
- def teardown_class(cls):
|
| |
+ # === run method ===
|
| |
+ yield
|
| |
+
|
| |
+ # === teardown ===
|
| |
db.session.rollback()
|
| |
db.drop_all()
|
| |
|
| |
Since Flask-SQLAlchemy 3.0, it is necessary to manually push Flask
application context when needed (in tests, in CLI commands not
registered through Flask). This patch adjusts our code to set the app
context when needed.
I chose a bit different approach to Frantisek's PR #262, using pytest
fixtures instead. While doing that, I converted all old xunit-style
classes to pytest fixtures. One of the reasons is that xunit-style
special methods can't receive fixture arguments, but it's not
communicated and confuses the developer, so I converted them everywhere.
Fixes: https://pagure.io/fedora-qa/blockerbugs/issue/260
Related: https://pagure.io/fedora-qa/blockerbugs/pull-request/262