def test_fetch_expired_consented_attributes(self): id = "test" consented_attributes = ['a', 'b', 'c'] consent = Consent(consented_attributes, 2, datetime.now() - timedelta(weeks=14)) assert consent.has_expired(self.max_month) self.consent_db.save_consent(id, consent) assert not self.cm.fetch_consented_attributes(id)
def get_consent(self, id: str) -> Consent: hashed_id = hash_id(id, self.salt) result = self.consent_table.find_one(consent_id=hashed_id) if not result: return None consent = Consent(json.loads(result['attributes']), result['months_valid'], datetime.strptime(result['timestamp'], ConsentDatasetDB.TIME_PATTERN)) if consent.has_expired(self.max_month): self.remove_consent(id) return None return consent
def get_consent(self, id: str) -> Consent: hashed_id = hash_id(id, self.salt) result = self.consent_table.find_one(consent_id=hashed_id) if not result: return None consent = Consent( json.loads(result['attributes']), result['months_valid'], datetime.strptime(result['timestamp'], ConsentDatasetDB.TIME_PATTERN)) if consent.has_expired(self.max_month): self.remove_consent(id) return None return consent
def test_consent_has_expired(self, mock_datetime, current_time, month, max_month): mock_datetime.now.return_value = current_time start_date = datetime.datetime(2015, 1, 1) consent = Consent(None, month, timestamp=start_date) assert consent.has_expired(max_month)
def test_consent_has_expired(self, mock_datetime, current_time, month, max_month): mock_datetime.now.return_value = current_time start_date = datetime.datetime(2015, 1, 1) consent = Consent(None, month, timestamp=start_date) assert consent.has_expired(max_month)