def setUp(self):
        super().setUp(preauth=True)

        # Create some compendium entries as user 1
        test_tag = CompendiumEntryTag.objects.create(tagname="test_tag")
        test_author = Author.objects.create(authorname="test_author")
        self.data = {
            "title": "test article",
            "url": "https://www.example.com",
            "edit-entry": "",
            "tags": [test_tag.id],
            "authors": [test_author.id],
        }
        self.create_compendium_entries(self.data, 3)
        self.client.logout()

        # Create a second user, and add some entries as that user
        email2 = random_email(self.rd)
        username2 = random_username(self.rd)
        password2 = random_password(self.rd)
        self.user2 = User.objects.create_user(email=email2,
                                              username=username2,
                                              password=password2)
        self.client.force_login(self.user2)
        self.create_compendium_entries(self.data, 3)
    def test_invalid_login(self):
        # Meepy visits the login page, but enters the incorrect username.
        self.go_to_login_page()
        initial_url = self.browser.current_url

        self.get_userbox().send_keys(random_username(self.rd))
        self.get_passbox().send_keys(self.password)
        self.get_passbox().send_keys(Keys.ENTER)

        self.wait_for(lambda: self.assertIn("Username does not exist.", self.
                                            browser.page_source))
        self.assertEqual(self.browser.current_url, initial_url)

        # Meepy enters the correct username, but the incorrect password
        self.get_userbox().clear()
        self.get_userbox().send_keys(self.username)
        self.get_passbox().send_keys(random_password(self.rd))
        self.get_passbox().send_keys(Keys.ENTER)

        self.wait_for(lambda: self.assertIn(
            "Sorry, that login was invalid. Please try again.",
            self.browser.page_source,
        ))
        self.assertEqual(self.browser.current_url, initial_url)

        # Meepy enters the correct username and password, and logs in successfully
        self.get_userbox().clear()
        self.get_passbox().clear()
        self.get_userbox().send_keys(self.username)
        self.get_passbox().send_keys(self.password)
        self.get_passbox().send_keys(Keys.ENTER)

        self.wait_for(lambda: self.assertIn("Dashboard", self.browser.title))
Beispiel #3
0
 def setUp(self):
     super().setUp()
     self.title = self.username
     self.abstract = "This is the abstract of our resource"
     self.url = "https://example.com"
     self.year = randrange(1900, date.today().year)
     self.month = randrange(1, 12)
     self.day = randrange(1, 31)
     self.publisher = random_username(self.rd)
    def test_edit_own_form(self):
        # currently logged in as user2
        # test edit entry that belongs to the user2
        entry_id = CompendiumEntry.objects.filter(owner=self.user2).first().id
        data = self.data.copy()
        data["title"] = "change article"
        data["publisher"] = random_username(self.rd)

        response = self.client.post(
            reverse("edit my entries", kwargs={"id": entry_id}), data)
        self.assertEqual(
            CompendiumEntry.objects.filter(id=entry_id).first().title,
            "change article")
    def test_add_new_compendium_entry(self):
        self.assertEqual(len(CompendiumEntry.objects.all()), 0)

        # Retrieve the tag ID for "test_tag_B"
        tag_id = CompendiumEntryTag.objects.get(tagname="test_tag_B").id

        # publisher information
        publisher = random_username(self.rd)

        # published date
        year = random.randrange(1900, datetime.date.today().year)
        month = random.randrange(1, 12)
        day = random.randrange(1, 31)

        # Send POST data to the URL to create a new entry and ensure that
        # the entry was created correctly.
        data = {
            "title": "New compendium entry",
            "abstract": "Abstract for new entry",
            "url": "https://example.com",
            "tags": [tag_id],
            "publisher_text": publisher,
            "year": year,
            "month": month,
            "day": day,
            "edit-entry": "",
        }
        response = self.client.post(self.new_entry_page, data)
        self.assertTrue(len(CompendiumEntry.objects.all()), 1)

        entry = CompendiumEntry.objects.get(title="New compendium entry")
        self.assertEqual(entry.owner, self.user)
        self.assertEqual(entry.title, "New compendium entry")
        self.assertEqual(entry.abstract, "Abstract for new entry")
        self.assertEqual(entry.url, "https://example.com")
        self.assertEqual(len(entry.tags.all()), 1)
        self.assertEqual(entry.tags.get().tagname, "test_tag_B")
        self.assertEqual(entry.publisher.publishername, publisher)
        self.assertEqual(entry.year, year)
        self.assertEqual(entry.month, month)
        self.assertEqual(entry.day, day)
    def test_invalid_login(self):
        ### Use a nonexistent username
        login_data = {
            "username": random_username(self.rd),
            "password": self.password
        }
        self.client.post(reverse("research login"), login_data)
        self.assertFalse(get_user(self.client).is_authenticated)

        ### Use an existing username, but an incorrect password
        original_db_entry = User.objects.get(username=self.username).password
        login_data = {
            "username": self.username,
            "password": random_password(self.rd)
        }
        self.client.post(reverse("research login"), login_data)
        self.assertFalse(get_user(self.client).is_authenticated)

        # Database should not have changed
        self.assertEqual(original_db_entry,
                         User.objects.get(username=self.username).password)
Beispiel #7
0
 def test_entry_with_publisher_field(self):
     # Test publisher field with valid input
     data = self.data
     data["publisher_text"] = random_username(self.rd)
     self.assertTrue(CompendiumEntryForm(data=data).is_valid())