|
22 | 22 | # External fixtures used below can be found in |
23 | 23 | # django/sierra/conftest.py: |
24 | 24 | # apiuser_with_custom_defaults |
25 | | -# |
26 | | - |
27 | | - |
28 | | -def calculate_expected_apiuser_details(test_cls, new, start=None): |
29 | | - """ |
30 | | - Calculate and return the expected values for an APIUser instance. |
31 | | -
|
32 | | - This is a utility function used in a few of the tests. It |
33 | | - determines the expected final attributes for an APIUser for tests |
34 | | - that test create/update operations. `test_cls` is the APIUser test |
35 | | - class that test uses. `new` is a dict containing data attributes |
36 | | - for the new/updated APIUser. And `start` is a dict containing data |
37 | | - attributes for the existing user that `new` is updating, if you're |
38 | | - testing an update operation. Expected values are returned as a |
39 | | - dict. |
40 | | - """ |
41 | | - exp, start = {}, (start or {}) |
42 | | - exp['permissions_dict'] = test_cls.permission_defaults.copy() |
43 | | - exp['permissions_dict'].update(start.get('permissions_dict', None) or {}) |
44 | | - exp['permissions_dict'].update(new.get('permissions_dict', None) or {}) |
45 | | - exp['permissions'] = ujson.encode(exp['permissions_dict']) |
46 | | - |
47 | | - key_fields = ('username', 'secret_text', 'password', 'email', 'first_name', |
48 | | - 'last_name') |
49 | | - for k in key_fields: |
50 | | - new_val = new.get(k, None) |
51 | | - default = start.get(k, None) or '' |
52 | | - exp[k] = new_val if new_val is not None else default |
53 | | - |
54 | | - exp['secret'] = test_cls.encode_secret(exp['secret_text']) |
55 | | - return exp |
56 | | - |
57 | | - |
58 | | -def assert_apiuser_matches_expected_data(apiuser, expected): |
59 | | - """ |
60 | | - Assert that an `apiuser` obj matches `expected` data. |
61 | | - """ |
62 | | - assert apiuser.secret == expected['secret'] |
63 | | - assert apiuser.permissions == expected['permissions'] |
64 | | - assert authenticate(username=expected['username'], |
65 | | - password=expected['password']) |
66 | | - assert apiuser.user.email == expected['email'] |
67 | | - assert apiuser.user.first_name == expected['first_name'] |
68 | | - assert apiuser.user.last_name == expected['last_name'] |
69 | | - |
| 25 | +# calculate_expected_apiuser_details |
| 26 | +# assert_apiuser_matches_expected_data |
70 | 27 |
|
71 | 28 | # TESTS |
72 | 29 | # --------------------------------------------------------------------- |
@@ -374,9 +331,10 @@ def test_apiuser_creation_permission_errors(apiuser_with_custom_defaults, |
374 | 331 | 'only new first_name value', |
375 | 332 | 'provided data is all blank strings' |
376 | 333 | ]) |
377 | | -def test_apiuser_updateandsave_works_correctly(apiuser_with_custom_defaults, |
378 | | - secret_text, permissions_dict, |
379 | | - pw, email, fn, ln): |
| 334 | +def test_apiuser_updateandsave_works(apiuser_with_custom_defaults, |
| 335 | + calculate_expected_apiuser_details, |
| 336 | + secret_text, permissions_dict, pw, email, |
| 337 | + fn, ln): |
380 | 338 | """ |
381 | 339 | The APIUser `update_and_save` method should update the APIUser |
382 | 340 | and/or associated user based on the provided details. Missing |
@@ -729,8 +687,10 @@ def test_apiuser_setallpermissionstovalue_errors(apiuser_with_custom_defaults): |
729 | 687 | 'some exist, update some, create some; no errors', |
730 | 688 | 'some exist, update one, create some; creation and update errors', |
731 | 689 | ]) |
732 | | -def test_apiusermgr_batchimport_works(apiuser_with_custom_defaults, fields, |
733 | | - start_vals, new_vals, err_vals): |
| 690 | +def test_apiusermgr_batchimport_works(apiuser_with_custom_defaults, |
| 691 | + calculate_expected_apiuser_details, |
| 692 | + assert_apiuser_matches_expected_data, |
| 693 | + fields, start_vals, new_vals, err_vals): |
734 | 694 | """ |
735 | 695 | The APIUser manager's `batch_import_users` method should: create |
736 | 696 | new Users/APIUsers for ones that don't already exist; update |
|
0 commit comments