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 1
1
import json
2
+ import warnings
2
3
3
4
from supermutes .dot import dotify
4
5
@@ -10,6 +11,14 @@ def __init__(self, data):
10
11
Initialise an ABE mock from data.
11
12
12
13
"""
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
+
13
22
# map JSON fields to attributes
14
23
self .__dict__ = data
15
24
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
+
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
1
2
from unittest import TestCase
3
+ import warnings
4
+
2
5
from mock import Mock
3
6
4
7
from abe .mocks import AbeMock
5
8
from abe .unittest import AbeTestMixin
6
9
10
+ DATA_DIR = join (dirname (abspath (__file__ )), 'data' )
11
+
7
12
8
13
class TestDataListEqual (TestCase , AbeTestMixin ):
9
14
@@ -134,3 +139,21 @@ def test_assertion_error_if_post_data_mismatch(self):
134
139
self .assert_matches_request (
135
140
self .sample_request , self .mock_wsgi_request
136
141
)
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