def test_suggestion_tag_reverse(self): # Create a suggestion and tags but with a missing reverse reference. Reminder(key_name='a-b', title='a b', tags='a b'.split()).put() Reminder(key_name='b-c', title='b c', tags='b'.split()).put() Tag(key_name='a', suggestions='a-b'.split(), count=0).put() Tag(key_name='b', suggestions='b-c'.split(), count=0).put() self.assertEqual(Reminder.all().count(), 2) self.assertEqual(Tag.all().count(), 2) self.assertEqual(len(Tag.get_by_key_name('b').suggestions), 1) # Check that the missing tag-reminder reference is detected. response = self.client.get('/consistency/') self.assertTrue('suggestion_tag_reverse' in response.context['problems']) self.assertTrue("Suggestion a-b references b but not reverse." in response.content) # Simulate button click to fix this problem. response = self.client.post('/consistency/', { 'suggestion_tag_reverse': "Create reverse references"}) self.assertRedirects(response, '/consistency/') # Check that the tags are now existing. self.assertEqual(Reminder.all().count(), 2) self.assertEqual(Tag.all().count(), 2) self.assertEqual(len(Tag.get_by_key_name('b').suggestions), 2) response = self.client.get('/consistency/') self.assertFalse('suggestion_tag_reverse' in response.context['problems'])
def test_tag_suggestion_missing(self): self.assertEqual(Tag.all().count(), 0) # Create tags but not all suggestions. Reminder(key_name='a-b', title='a b', tags='a b'.split()).put() Tag(key_name='a', count=2, suggestions='a-b a-c'.split()).put() Tag(key_name='b', count=2, suggestions='b-c'.split()).put() self.assertEqual(Tag.all().count(), 2) # Check that the missing suggestions are detected. response = self.client.get('/consistency/') self.assertTrue('tag_suggestion_missing' in response.context['problems']) self.assertTrue("Tag a references missing suggestion a-c." in response.content) self.assertTrue("Tag b references missing suggestion b-c." in response.content) # Simulate button click to fix this problem. response = self.client.post('/consistency/', { 'tag_suggestion_missing': "Create missing"}) self.assertRedirects(response, '/consistency/') # Check that the references are now gone. self.assertEqual(Tag.all().count(), 1) self.assertEqual(Tag.get_by_key_name('a').count, 1) self.assertEqual(len(Tag.get_by_key_name('a').suggestions), 1) response = self.client.get('/consistency/') self.assertFalse('tag_suggestion_missing' in response.context['problems'])
def submit_suggestion(request, suggestion_form): """ Save a new suggestion in the database. """ slug = suggestion_form.cleaned_data['slug'] tag_list = suggestion_form.cleaned_data['tags'].split() for tag_name in tag_list: tag = Tag.get_by_key_name(tag_name) if tag is None: tag = Tag(key_name=tag_name, count=0) tag.suggestions.append(slug) tag.count += 1 tag.put() suggestion = Reminder( key_name=slug, title=suggestion_form.cleaned_data['title'], days=suggestion_form.cleaned_data['days'], months=suggestion_form.cleaned_data['months'], years=suggestion_form.cleaned_data['years'], miles=suggestion_form.cleaned_data['miles'], kilometers=suggestion_form.cleaned_data['kilometers'], tags=tag_list) logging.debug(suggestion) suggestion.put() return HttpResponseRedirect(suggestion.get_absolute_url())
def test_tag_created_none(self): # Create a tag with missing timestamp. Reminder(key_name='a-b', title='a b', tags='a b'.split()).put() Tag(key_name='a', suggestions=['a-b'], count=1, created=None).put() # Check that the missing timestamp is detected. response = self.client.get('/consistency/') self.assertTrue('tag_created_none' in response.context['problems']) self.assertTrue("Tag a is missing a timestamp." in response.content) # Simulate button click to fix this problem. response = self.client.post('/consistency/', {'tag_created_none': "Adjust timestamps"}) self.assertRedirects(response, '/consistency/') # Check that the timestamps are now correct. self.assertEqual(Reminder.get_by_key_name('a-b').created, Tag.get_by_key_name('a').created) response = self.client.get('/consistency/') self.assertFalse('tag_created_none' in response.context['problems'])