def test_clean_alignments_cleans_only_old_alignemnts_sequences(self): """ Tests that only alignments older than 7 days are removed from the database when clean_alignments is run """ seq_ids_old = [] for i in range(2): alignment_old = Alignment.objects.create_alignment(self.name, self.data) alignment_old.created = datetime.now(timezone.utc) - timedelta(days=7) alignment_old.save() modified_old = Alignment.objects.get(pk=alignment_old.pk) seq_ids_old.extend([m.pk for m in modified_old.seqs.all()]) alignment_new = Alignment.objects.create_alignment(self.name, self.data) seq_ids_new = [a.pk for a in alignment_new.seqs.all()] clean_alignments() for s in seq_ids_new: try: new_seq = Seqrecord.objects.get(pk=s) self.assertTrue(new_seq.pk in seq_ids_new, 'sequence %s was removed' % new_seq.pk) except Seqrecord.DoesNotExist as error: self.assertFalse(str(error) == 'Seqrecord matching query does not exist.', error) for s in seq_ids_old: try: old_seq = Seqrecord.objects.get(pk=s) self.assertFalse(old_seq.pk in seq_ids_old, 'sequence %s was not removed' % old_seq.pk) except Seqrecord.DoesNotExist as error: self.assertEqual(str(error), 'Seqrecord matching query does not exist.', error)
def test_clean_alignments_leaves_recent_alignments_untouched(self): """ Tests that an alignment not older than 7 days is not removed from the database when clean_alignments is run """ alignment = Alignment.objects.create_alignment(self.name, self.data) alignment.created = datetime.now(timezone.utc) - timedelta(days=6) alignment.save() modified = Alignment.objects.get(pk=alignment.pk) self.assertTrue(datetime.now(timezone.utc) - modified.created < timedelta(days=7), modified.created) clean_alignments() try: new = Alignment.objects.get(name=self.name) self.assertTrue(new.name == self.name, '%s was removed' % new.name) except Alignment.DoesNotExist as error: self.assertFalse(str(error) == 'Alignment matching query does not exist.', error)
def test_clean_alignments_removes_sequences_associated_to_old_alignments(self): """ Tests that all sequences associated to an alignment older than 7 days are removed from the database when clean_alignments is run """ alignment = Alignment.objects.create_alignment(self.name, self.data) alignment.created = datetime.now(timezone.utc) - timedelta(days=7) alignment.save() modified = Alignment.objects.get(pk=alignment.pk) self.assertTrue(datetime.now(timezone.utc) - modified.created > timedelta(days=7), modified.created) seq_ids = [m.pk for m in modified.seqs.all()] clean_alignments() for s in seq_ids: try: old_seq = Seqrecord.objects.get(pk=s) self.assertFalse(old_seq.pk in seq_ids, 'sequence %s was not removed' % old_seq.pk) except Seqrecord.DoesNotExist as error: self.assertEqual(str(error), 'Seqrecord matching query does not exist.', error)
def test_clean_alignments_cleans_only_old_alignemnts(self): """ Tests that only alignments older than 7 days are removed from the database when clean_alignments is run """ alignment_old = Alignment.objects.create_alignment(self.name, self.data) alignment_new = Alignment.objects.create_alignment(self.name, self.data) alignment_old.created = datetime.now(timezone.utc) - timedelta(days=7) alignment_old.save() modified_old = Alignment.objects.get(pk=alignment_old.pk) self.assertTrue(datetime.now(timezone.utc) - modified_old.created > timedelta(days=7), modified_old.created) clean_alignments() try: new = Alignment.objects.get(pk=alignment_new.pk) self.assertTrue(new.name == self.name, '%s was not removed' % new.name) except Alignment.DoesNotExist as error: self.assertFalse(str(error) == 'Alignment matching query does not exist.', error) try: old = Alignment.objects.get(pk=alignment_old.pk) self.assertFalse(old.name == self.name, '%s was removed' % old.name) except Alignment.DoesNotExist as error: self.assertEqual(str(error), 'Alignment matching query does not exist.', error)