File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed
Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 11import json
2+ import warnings
23
34from supermutes .dot import dotify
45
@@ -10,6 +11,14 @@ def __init__(self, data):
1011 Initialise an ABE mock from data.
1112
1213 """
14+ if not isinstance (data , dict ):
15+ msg = ('Instanciating an AbeMock by filename is deprecated and '
16+ 'will be removed in an upcoming release. '
17+ 'Use AbeMock.from_filename instead' .format (data ))
18+ warnings .warn (msg , DeprecationWarning )
19+ with open (data , 'r' ) as f :
20+ data = json .load (f )
21+
1322 # map JSON fields to attributes
1423 self .__dict__ = data
1524
Original file line number Diff line number Diff line change 1+ {
2+ "description" : " Retrieve profile of logged in user" ,
3+ "url" : " /accounts/me" ,
4+ "method" : " GET" ,
5+ "examples" : {
6+ "OK" : {
7+ "request" : {
8+ "url" : " /accounts/me"
9+ },
10+ "response" : {
11+ "status" : 200 ,
12+ "body" : {
13+ "id" : 1 ,
14+ "username" : " user-0" ,
15+ "first_name" : " " ,
16+ "last_name" : " " ,
17+ "email" : " user-0@example.com"
18+ }
19+ }
20+ },
21+ "unauthenticated" : {
22+ "description" : " I am not logged in" ,
23+ "request" : {
24+ "url" : " /accounts/me"
25+ },
26+ "response" : {
27+ "status" : 403 ,
28+ "body" : {
29+ "detail" : " Authentication credentials were not provided."
30+ }
31+ }
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ from os .path import abspath , dirname , join
12from unittest import TestCase
3+ import warnings
4+
25from mock import Mock
36
47from abe .mocks import AbeMock
58from abe .unittest import AbeTestMixin
69
10+ DATA_DIR = join (dirname (abspath (__file__ )), 'data' )
11+
712
813class TestDataListEqual (TestCase , AbeTestMixin ):
914
@@ -134,3 +139,21 @@ def test_assertion_error_if_post_data_mismatch(self):
134139 self .assert_matches_request (
135140 self .sample_request , self .mock_wsgi_request
136141 )
142+
143+
144+ class TestFilenameInstantiation (TestCase ):
145+
146+ def setUp (self ):
147+ self .filename = join (DATA_DIR , 'sample.json' )
148+
149+ def test_can_still_use_deprecated_instantiation (self ):
150+ with warnings .catch_warnings (record = True ) as w :
151+ warnings .simplefilter ("always" )
152+
153+ mock = AbeMock (self .filename )
154+
155+ self .assertEqual (len (w ), 1 )
156+ self .assertTrue (issubclass (w [- 1 ].category , DeprecationWarning ))
157+
158+ def test_from_filename (self ):
159+ mock = AbeMock .from_filename (self .filename )
You can’t perform that action at this time.
0 commit comments