Skip to content

Commit c1a4082

Browse files
jamalexbjester
authored andcommitted
Fixes to tests to get them working with deferred fks
1 parent 9ce10b1 commit c1a4082

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

tests/testapp/facility_profile/models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,20 @@ class MyUser(AbstractBaseUser, FacilityDataSyncableModel):
6060
objects = SyncableUserModelManager()
6161

6262
def calculate_source_id(self, *args, **kwargs):
63-
return self.username
63+
if self._morango_source_id:
64+
return self._morango_source_id
65+
else:
66+
return uuid.uuid5(uuid.UUID("a" * 32), self.username).hex
6467

6568
def calculate_partition(self, *args, **kwargs):
6669
return '{id}:user'.format(id=self.ID_PLACEHOLDER)
6770

6871
def has_morango_certificate_scope_permission(self, scope_definition_id, scope_params):
69-
return self.is_superuser
72+
return self.is_superuser
73+
74+
@staticmethod
75+
def compute_namespaced_id(partition_value, source_id_value, model_name):
76+
return source_id_value
7077

7178

7279
class SummaryLog(FacilityDataSyncableModel):

tests/testapp/tests/integration/test_syncsession.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,20 @@ def setUp(self):
5353
)
5454
self.conn.chunk_size = 3
5555

56-
self.remote_user = self._setUpServer()
56+
self.remote_user, self.root_cert_id = self._setUpServer()
5757
self.filter = Filter("{}:user".format(self.remote_user.id))
58-
self.client = self._setUpClient(self.remote_user.id)
58+
self.client = self._setUpClient(self.root_cert_id)
5959
self.session = self.client.sync_session
6060
self.last_session_activity = self.session.last_activity_timestamp
6161
self.last_transfer_activity = None
6262

63-
self.local_user = MyUser.objects.create(
64-
id=self.remote_user.id, username="bob", is_superuser=True
65-
)
63+
# perform an initial sync to ensure the user is on both sides
64+
client = self.client.get_pull_client()
65+
client.initialize(self.filter)
66+
client.run()
67+
client.finalize()
68+
69+
self.local_user = MyUser.objects.first()
6670

6771
def _setUpCertScopes(self):
6872
root_scope = ScopeDefinition.objects.create(
@@ -90,37 +94,37 @@ def _setUpCertScopes(self):
9094

9195
def _setUpServer(self):
9296
with second_environment():
93-
root_scope, subset_scope = self._setUpCertScopes()
94-
root_cert = Certificate.generate_root_certificate(root_scope.id)
97+
self.server_root_scope, self.server_subset_scope = self._setUpCertScopes()
98+
root_cert = Certificate.generate_root_certificate(self.server_root_scope.id)
9599

96100
remote_user = MyUser.objects.create(
97-
id=root_cert.id, username="bob", is_superuser=True
101+
_morango_source_id=root_cert.id, username="bob", is_superuser=True
98102
)
99103
remote_user.set_password("password")
100104
remote_user.save()
101105

102106
subset_cert = Certificate(
103107
parent=root_cert,
104108
profile=self.profile,
105-
scope_definition=subset_scope,
106-
scope_version=subset_scope.version,
109+
scope_definition=self.server_subset_scope,
110+
scope_version=self.server_subset_scope.version,
107111
scope_params=json.dumps({"user": remote_user.id, "sub": "user"}),
108112
private_key=Key(),
109113
)
110114
root_cert.sign_certificate(subset_cert)
111115
subset_cert.save()
112-
return remote_user
116+
return remote_user, root_cert.id
113117

114118
def _setUpClient(self, primary_partition):
115-
root_scope, subset_scope = self._setUpCertScopes()
119+
self.client_root_scope, self.client_subset_scope = self._setUpCertScopes()
116120

117121
server_certs = self.conn.get_remote_certificates(
118-
primary_partition, root_scope.id
122+
primary_partition, self.client_root_scope.id
119123
)
120124
server_cert = server_certs[0]
121125
client_cert = self.conn.certificate_signing_request(
122126
server_cert,
123-
subset_scope.id,
127+
self.client_subset_scope.id,
124128
{"user": primary_partition, "sub": "user"},
125129
userargs="bob",
126130
password="password",

tests/testapp/tests/sync/test_controller.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,10 @@ def test_record_with_dirty_bit_off_doesnt_deserialize(self):
428428
self.assertFalse(Facility.objects.filter(id=st.id).exists())
429429

430430
def test_broken_fk_leaves_store_dirty_bit(self):
431-
serialized = """{"user_id": "40de9a3fded95d7198f200c78e559353", "id": "bd205b5ee5bc42da85925d24c61341a8"}"""
431+
log_id = uuid.uuid4().hex
432+
serialized = json.dumps({"user_id": "40de9a3fded95d7198f200c78e559353", "id": log_id})
432433
st = StoreModelFacilityFactory(
433-
id=uuid.uuid4().hex, serialized=serialized, model_name="contentsummarylog"
434+
id=log_id, serialized=serialized, model_name="contentsummarylog"
434435
)
435436
self.assertTrue(st.dirty_bit)
436437
self.mc.deserialize_from_store()

0 commit comments

Comments
 (0)