def test_get_by_ANY_or_create(self): """Issue #51""" manager = Series.objects ph1 = generate_rand_word(4) obj1 = manager.get_by_name_or_create(ph1) obj2 = manager.get_by_name_or_create(generate_rand_word(5)) self.assertNotEqual(obj1.id, obj2.id) obj1_again = manager.get_by_name_or_create(ph1) self.assertEqual(obj1_again.id, obj1.id)
def test_get_id_by_ANY_or_create(self): """Issue #51""" manager = Author.objects ph1 = generate_rand_word(4) obj1_id = manager.get_id_by_fullname_or_create(ph1) obj2_id = manager.get_id_by_fullname_or_create(generate_rand_word(5)) self.assertIsInstance(obj1_id, int) self.assertNotEqual(obj1_id, obj2_id) obj1_again_id = manager.get_id_by_fullname_or_create(ph1) self.assertEquals(obj1_again_id, obj1_id)
def test_over_max_length_strings(self): """Issue #52""" series_index_maxlen = BookSeries._meta.get_field_by_name('number')[0].max_length genre_code_maxlen = Genre._meta.get_field_by_name('code')[0].max_length #format in ponylib.meta.read_fb2_meta() mock_meta = { #unlimited field 'title': generate_rand_word(1986), #limited fields 'genres': [generate_rand_word(genre_code_maxlen*2)], 'series': [{'name': generate_rand_word(1111), 'index': generate_rand_word(series_index_maxlen*2)}] } with patch.object(AddOrUpdateBookConsumer, '_read_meta_data', return_value=(mock_meta, True)): consumer = AddOrUpdateBookConsumer(kwargs={'connection_alias': 'default'}) consumer.allow_update = False book = consumer._process_path(self.sample_root, self.sample_fb2) book_id = book.id book_from_db = Book.objects.get(pk=book_id) #unlimited field self.assertEqual(book_from_db.title, mock_meta['title']) #limited fiels self.assertEqual(book_from_db.series.count(), 1) self.assertEquals( book_from_db.get_series_links()[0].number, mock_meta['series'][0]['index'][:series_index_maxlen-3] + '...') self.assertEqual(book_from_db.genres.count(), 1) self.assertEquals(book_from_db.genres.all()[0].code, mock_meta['genres'][0][:genre_code_maxlen]) #TODO: consumer_without_stat_test