-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
plugins: | ||
api: | ||
plugins: | ||
transferring: | ||
plugins: | ||
lots.transferring: | ||
lots.core: | ||
plugins: | ||
lots.loki: | ||
|
This file contains 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
This file contains 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,30 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
def switch_mode(self): | ||
# set test mode and try to change ownership | ||
|
||
auth = ('Basic', (self.first_owner, '')) | ||
|
||
self.__class__.resource_name = self.resource_name | ||
resource = self.create_resource(auth=auth) | ||
resource_access_transfer = self.resource_transfer | ||
self.__class__.resource_name = '' | ||
|
||
# decision that was created from asset can't be updated (by patch) | ||
document = self.db.get(resource['id']) | ||
document['mode'] = 'test' | ||
self.db.save(document) | ||
|
||
self.app.authorization = ('Basic', (self.test_owner, '')) | ||
transfer = self.create_transfer() | ||
|
||
req_data = {"data": {"id": transfer['data']['id'], | ||
'transfer': resource_access_transfer}} | ||
req_url = '{}/{}/ownership'.format(self.resource_name, resource['id']) | ||
|
||
response = self.app.post_json(req_url, req_data) | ||
|
||
self.assertEqual(response.status, '200 OK') | ||
self.assertIn('owner', response.json['data']) | ||
self.assertEqual(response.json['data']['owner'], self.test_owner) |
This file contains 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,67 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
from openregistry.lots.core.tests.base import snitch | ||
from openregistry.lots.core.tests.plugins.transferring.mixins import ( | ||
LotOwnershipChangeTestCaseMixin | ||
) | ||
|
||
from openregistry.lots.loki.tests.base import LotContentWebTest | ||
from openregistry.lots.loki.tests.blanks.transferring import switch_mode | ||
|
||
|
||
class LotOwnershipChangeResourceTest(LotContentWebTest, | ||
LotOwnershipChangeTestCaseMixin): | ||
|
||
# decision that was created from asset can't be updated | ||
test_new_owner_can_change = None | ||
test_mode_test = snitch(switch_mode) | ||
|
||
def setUp(self): | ||
super(LotOwnershipChangeResourceTest, self).setUp() | ||
|
||
# needed to work with transfer resource | ||
self.resource_name = self.__class__.resource_name | ||
self.__class__.resource_name = '' | ||
|
||
self.not_used_transfer = self.create_transfer() | ||
|
||
def tearDown(self): | ||
super(LotOwnershipChangeResourceTest, self).tearDown() | ||
self.__class__.resource_name = self.resource_name | ||
|
||
def use_transfer(self, transfer, resource_id, origin_transfer): | ||
req_data = {"data": {"id": transfer['data']['id'], | ||
'transfer': origin_transfer}} | ||
|
||
self.app.post_json( | ||
'{}/{}/ownership'.format(self.resource_name, resource_id), req_data | ||
) | ||
response = self.app.get('transfers/{}'.format(transfer['data']['id'])) | ||
return response.json | ||
|
||
def create_transfer(self): | ||
response = self.app.post_json('transfers', {"data": {}}) | ||
return response.json | ||
|
||
def get_resource(self, resource_id): | ||
response = self.app.get('{}/{}'.format(self.resource_name, resource_id)) | ||
return response.json | ||
|
||
def set_resource_mode(self, resource_id, mode): | ||
current_auth = self.app.authorization | ||
|
||
self.app.authorization = ('Basic', ('administrator', '')) | ||
self.app.patch_json('{}/{}'.format(self.resource_name, resource_id), | ||
{'data': {'mode': mode}}) | ||
self.app.authorization = current_auth | ||
|
||
|
||
def suite(): | ||
tests = unittest.TestSuite() | ||
tests.addTest(unittest.makeSuite(LotOwnershipChangeResourceTest)) | ||
return tests | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='suite') |