def test_geocache_and_log_relationship(self): g = Geocache() g.save() log = Log(id=None, text="test text", geocache=g) log.save() self.assertEqual(log.text, "test text") log2 = Log(id=None, text="test text", geocache=g) log2.save() saved_logs = Log.objects.all() self.assertEqual(saved_logs.count(), 2)
def test_saving_and_retrieving_difficulty(self): good_listing = Geocache() good_listing.difficulty = 3 good_listing.save() bad_listing = Geocache() bad_listing.difficulty = 6 bad_listing.save() saved_listings = Geocache.objects.all() self.assertEqual(saved_listings[0].difficulty, 3)
def test_all_previous_logs_are_shown(self): g = Geocache() g.save() first_log = Log(id=None, text="Test for first log", geocache=g) first_log.save() second_log = Log(id=None, text="Test for second log", geocache=g) second_log.save() request = HttpRequest() response = listing(request, g.id) self.assertIn("Test for first log", response.content.decode()) self.assertIn("Test for second log", response.content.decode())
def setUp(self): # bit of a hack, prepopulating the database first_listing = Geocache( title="First Geocache Listing", description="Test description", latitude=00.000000, longitude=00.000000, ) first_listing.save() second_listing = Geocache(title="Second Geocache Listing") second_listing.save() self.browser = webdriver.Firefox() self.browser.implicitly_wait(3)
def test_saving_and_retrieving_hint(self): first_listing = Geocache() first_listing.hint = "Hint for cache" first_listing.save() second_listing = Geocache() second_listing.hint = "Hint for cache" second_listing.save() saved_listings = Geocache.objects.all() self.assertEqual(saved_listings.count(), 2) first_saved_listing = saved_listings[0] second_saved_listing = saved_listings[1] self.assertEqual(first_saved_listing.hint, "Hint for cache") self.assertEqual(second_saved_listing.hint, "Hint for cache")
def test_saving_and_retrieving_positive_and_negative_coordinates(self): first_listing = Geocache() first_listing.latitude = 10.000001 first_listing.longitude = -10.000001 first_listing.save() second_listing = Geocache() second_listing.latitude = 20.100000 second_listing.longitude = -20.100000 second_listing.save() saved_listings = Geocache.objects.all() self.assertEqual(saved_listings.count(), 2) first_saved_listing = saved_listings[0] second_saved_listing = saved_listings[1] self.assertEqual(first_saved_listing.latitude, 10.000001) self.assertEqual(first_saved_listing.longitude, -10.000001) self.assertEqual(second_saved_listing.latitude, 20.100000) self.assertEqual(second_saved_listing.longitude, -20.100000)
def test_saving_and_retrieving_items(self): first_listing = Geocache() first_listing.title = "First Geocache Listing" first_listing.description = "First geocache description." first_listing.save() second_listing = Geocache() second_listing.title = "Second Geocache Listing" second_listing.description = "Second geocache description." second_listing.save() saved_listings = Geocache.objects.all() self.assertEqual(saved_listings.count(), 2) first_saved_listing = saved_listings[0] second_saved_listing = saved_listings[1] self.assertEqual(first_saved_listing.title, "First Geocache Listing") self.assertEqual(first_saved_listing.description, "First geocache description.") self.assertEqual(second_saved_listing.title, "Second Geocache Listing") self.assertEqual(second_saved_listing.description, "Second geocache description.")