def test_populate_pins(self): """ Checks that pins populate properly """ populate() pins = Pin.objects.all() self.assertEquals(pins.count(), 11)
def test_populate_users(self): """ Checks that users populate correctly """ populate() users = UserProfile.objects.all() self.assertEquals(users.count(), 4)
def test_populate_favourite_places(self): """ Checks favourite place populates correctly """ populate() places = FavouritePlace.objects.all() self.assertEquals(places.count(), 5)
def test_population_script(self): # Populate database population_script.populate() url = self.live_server_url url = url.replace('localhost', '127.0.0.1') self.browser.get(url + reverse('admin:index')) username_field = self.browser.find_element_by_name('username') username_field.send_keys('admin') password_field = self.browser.find_element_by_name('password') password_field.send_keys('admin') password_field.send_keys(Keys.RETURN) # # Check if there is a link to bases # bases_link = self.browser.find_elements_by_partial_link_text('bases') # print(bases_link[0].text) # bases_link[0].click() # Check for the bases self.browser.find_elements_by_partial_link_text('Bases')[0].click() self.browser.find_elements_by_partial_link_text('Fusilli') self.browser.find_elements_by_partial_link_text('Spaghetti') self.browser.find_elements_by_partial_link_text('Tortellini') self.browser.find_elements_by_partial_link_text('Macaroni') self.browser.find_elements_by_partial_link_text('Egg Noodles')
def populate_database(): try: import population_script except ImportError: raise ImportError( f"{FAILURE_HEADER}The population script could not be imported") population_script.populate()
def setUp(self): try: populate() except ImportError: print("The module population_script does not exist") except NameError: print("The module populate() does not exist or is not correct") except: print("Something went wrong in the populate() function") self.client = Client()
def setUp(self): try: from population_script import populate populate() except ImportError: print('The module populate_rango does not exist') except NameError: print('The function populate() does not exist or is not correct') except: print('Something went wrong in the populate() function :-(')
def setUp(self): try: from population_script import populate print "populating test database.........." populate() except ImportError: print "The module population_script.py does not exist" except NameError: print "The function populate() does not exist, or is incorrect" except: print "Something f****d up in the population script"
def setUpTestData(cls): print "UserProfile Model tests commencing..." try: from population_script import populate print "populating test database.........." populate() except ImportError: print "The module population_script.py does not exist" except NameError: print "The function populate() does not exist, or is incorrect" except: print "Something f****d up in the population script"
def setUp(self): try: from population_script import populate populate() except ImportError: print("The module population_script does not exist") except NameError: print("The function populate() does not exist or is not correct") except: print("Something went wrong during running the population script") self.user = User.objects.get(email="*****@*****.**") self.user_pic = Picture.objects.get(slug="matthew-jones-picture1")
def setUp(self): try: from population_script import populate populate() except ImportError: print("The module population_script does not exist") except NameError: print("The function populate() does not exist or is not correct") except: print("Something went wrong during running the population script") self.client.login(email="*****@*****.**", password="******")
def setUp(self): """ Imports and runs the population script, calling the populate() method. """ try: import population_script except ImportError: raise ImportError( f"{FAILURE_HEADER}Population script could not be imported.{FAILURE_FOOTER}" ) if 'populate' not in dir(population_script): raise NameError( f"{FAILURE_HEADER}The populate() function does not exist in the population_script module{FAILURE_FOOTER}" ) population_script.populate()
def test_admin_can_create_post(self): population_script.populate() url = self.live_server_url url = url.replace('localhost', '127.0.0.1') self.browser.get(url + reverse('admin:index')) # Check if it display admin message body = self.browser.find_element_by_tag_name('body') self.assertIn('Django administration', body.text) # Log in the admin page test_utils.login(self) # the Site Administration page body = self.browser.find_element_by_tag_name('body') self.assertIn('Site administration', body.text) # Check if is there link to categories posts_link = self.browser.find_elements_by_partial_link_text('Posts') self.assertEquals(len(posts_link), 1) # Click in the link posts_link[0].click() # Empty, so check for the empty message body = self.browser.find_element_by_tag_name('body') #self.assertIn('0 posts', body.text.lower()) ##ADD new post new_poll_link = self.browser.find_element_by_class_name('addlink') new_poll_link.click() # Check for input field body = self.browser.find_element_by_tag_name('body') self.assertIn('Title:'.lower(), body.text.lower()) # Input category name post_field = self.browser.find_element_by_name('title') post_field.send_keys("new dog") # Gertrude clicks the save button save_button = self.browser.find_element_by_css_selector( "input[value='Save']") save_button.click()
def test_populate(self): try: from population_script import populate populate() except ImportError: print('The populate script does not exist') except NameError: print('The function populate() does not exist') except: print('Something went wrong in the populate() function :(') # Check that books were created books = Book.objects.all() self.assertEqual((len(books) > 0), True) # Check that reviews were created reviews = Review.objects.all() self.assertEqual((len(reviews) > 0), True) # Check that reviews are not empty self.assertEqual((len(reviews[0].text) > 0), True)
def test_edit_profile_post(self): """ test updating a username using edit_profile """ populate() self.client.login(username='******', password='******') profile_data = {'username': '******', 'email': '*****@*****.**'} self.client.post(reverse('explore_scotland_app:edit_profile'), profile_data) user_id = int(self.client.session['_auth_user_id']) user = User.objects.get(id=user_id) self.assertEqual( profile_data.get('username'), user.username, f"{FAILURE_HEADER}filed to edit username through editprofile{FAILURE_FOOTER}" ) self.assertEqual( profile_data.get('email'), user.email, f"{FAILURE_HEADER}filed to edit email through editprofile{FAILURE_FOOTER}" )
def test_population_script(self): population_script.populate() # Check if Songs have correct metadata song = Song.objects.get(track_name="Hymn For The Weekend") self.assertEquals(song.artist, "Coldplay") self.assertEquals(song.genre, "Alternative Rock") self.assertEquals(song.album, "A Head Full Of Dreams") song = Song.objects.get(track_name="Hysteria") self.assertEquals(song.artist, "Muse") self.assertEquals(song.genre, "Alternative Rock") self.assertEquals(song.album, "Absolution") song = Song.objects.get(track_name="Fix You") self.assertEquals(song.artist, "Coldplay") self.assertEquals(song.genre, "Alternative Rock") self.assertEquals(song.album, "X & Y") song = Song.objects.get(track_name="ELEMENT.") self.assertEquals(song.artist, "Kendrick Lamar") self.assertEquals(song.genre, "Rap") self.assertEquals(song.album, "DAMN.") song = Song.objects.get(track_name="Counting Stars") self.assertEquals(song.artist, "OneRepublic") self.assertEquals(song.genre, "Pop Rock") self.assertEquals(song.album, "Native") # Check if Comments have been added to relevent User comments list for comment in Comment.objects.all(): for user in UserProfile.objects.all(): for user_comment in user.comments.all(): if comment.comment_id == user_comment.comment_id: self.assertEquals(comment, user_comment)
def setUp(self): """ Populates the database with required data """ populate() self.client = Client()
def setUp(self): populate() self.response = self.client.get( reverse('LinkedOn:show_category', kwargs={'category_name_slug': 'data-science'})) self.content = self.response.content.decode()
def setUp(self): populate()