def test_process_subscription_state_change(self): product_1 = ProductFactory(codename="capability_1") product_2 = ProductFactory(codename="capability_2") product_3 = ProductFactory(codename="capability_3") profile = ProfileFactory() profile.products.add(product_3) account_event_1 = AccountEventFactory( body=json.dumps({ "capabilities": ["capability_1", "capability_2"], "isActive": True, "changeTime": 1, }), event_type=AccountEvent.SUBSCRIPTION_STATE_CHANGE, status=AccountEvent.UNPROCESSED, profile=profile, ) process_event_subscription_state_change(account_event_1.id) account_event_1.refresh_from_db() self.assertCountEqual(profile.products.all(), [product_1, product_2, product_3]) eq_(account_event_1.status, AccountEvent.PROCESSED) account_event_2 = AccountEventFactory( body=json.dumps({ "capabilities": ["capability_1", "capability_2"], "isActive": False, "changeTime": 2, }), event_type=AccountEvent.SUBSCRIPTION_STATE_CHANGE, status=AccountEvent.UNPROCESSED, profile=profile, ) process_event_subscription_state_change(account_event_2.id) account_event_2.refresh_from_db() self.assertCountEqual(profile.products.all(), [product_3]) eq_(account_event_2.status, AccountEvent.PROCESSED)
def test_process_subscription_state_change_out_of_order(self): profile = ProfileFactory() account_event_1 = AccountEventFactory( body=json.dumps({ "capabilities": ["capability_1"], "isActive": True, "changeTime": 1 }), event_type=AccountEvent.SUBSCRIPTION_STATE_CHANGE, status=AccountEvent.UNPROCESSED, profile=profile ) process_event_subscription_state_change(account_event_1.id) account_event_1.refresh_from_db() eq_(account_event_1.status, AccountEvent.PROCESSED) account_event_2 = AccountEventFactory( body=json.dumps({ "capabilities": ["capability_1"], "isActive": True, "changeTime": 3 }), event_type=AccountEvent.SUBSCRIPTION_STATE_CHANGE, status=AccountEvent.UNPROCESSED, profile=profile ) process_event_subscription_state_change(account_event_2.id) account_event_2.refresh_from_db() eq_(account_event_2.status, AccountEvent.PROCESSED) account_event_3 = AccountEventFactory( body=json.dumps({ "capabilities": ["capability_1"], "isActive": False, "changeTime": 2 }), event_type=AccountEvent.SUBSCRIPTION_STATE_CHANGE, status=AccountEvent.UNPROCESSED, profile=profile ) process_event_subscription_state_change(account_event_3.id) account_event_3.refresh_from_db() eq_(account_event_3.status, AccountEvent.IGNORED)