-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathtest_migrations.py
More file actions
53 lines (39 loc) · 1.63 KB
/
test_migrations.py
File metadata and controls
53 lines (39 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import importlib
import json
from unittest.mock import MagicMock
from django.db import connection
from django.test import TestCase
from openwisp_radius.models import RadiusBatch
migration_module = importlib.import_module(
"openwisp_radius.migrations.0044_convert_user_credentials_data"
)
convert_user_credentials_data = migration_module.convert_user_credentials_data
class Test0044Migration(TestCase):
def test_convert_user_credentials_data(self):
batch = RadiusBatch.objects.create(
name="test_batch_migration", strategy="prefix", prefix="test"
)
RadiusBatch.objects.filter(pk=batch.pk).update(
user_credentials=json.dumps({"user1": "pass1"})
)
apps = MagicMock()
apps.get_model.return_value = RadiusBatch
schema_editor = MagicMock()
schema_editor.connection = connection
convert_user_credentials_data(apps, schema_editor)
batch.refresh_from_db()
self.assertEqual(batch.user_credentials, {"user1": "pass1"})
def test_convert_user_credentials_data_invalid_json(self):
batch = RadiusBatch.objects.create(
name="test_batch_invalid", strategy="prefix", prefix="test2"
)
RadiusBatch.objects.filter(pk=batch.pk).update(
user_credentials="invalid_json_string"
)
apps = MagicMock()
apps.get_model.return_value = RadiusBatch
schema_editor = MagicMock()
schema_editor.connection = connection
convert_user_credentials_data(apps, schema_editor)
batch.refresh_from_db()
self.assertEqual(batch.user_credentials, "invalid_json_string")