Example #1
0
def test_delete_target():
    author = AuthorFactory()
    activity = ActivityFactory(target=author)
    assert activity.target == author
    author.delete()
    assert Activity.objects.filter(pk=activity.pk).exists() is True
    activity_updated = Activity.objects.get(pk=activity.pk)
    assert activity_updated.target_content_type == activity.target_content_type
    assert activity_updated.target_object_id == str(activity.target_object_id)
    assert activity_updated.target is None
Example #2
0
def test_author_create_rss(session):
    author = AuthorFactory()
    print(vars(author))
    entry = EntryFactory()
    author.entries.append(entry)
    author.create_rss("http://test.com/author/rss")
    rss = feedparser.parse(author.authorfeed.feed)

    assert rss.feed.title == u"{0}: {1}".format(author.name, app.config["PROJECT_NAME"])
    assert rss.entries[0].title == entry.title
    assert rss.entries[0].author is not None
    print(rss.entries[0].author)
    print(rss.entries[0].author_detail)
    assert rss.entries[0].author == str(author)
Example #3
0
def test_import_articles(admin_client):
    author = AuthorFactory()
    source = SourceFactory()
    contents = []
    count = 5
    for article in ArticleFactory.build_batch(count):
        contents.append({
            "title": article.title,
            "url": article.url,
            "date": article.date.isoformat(),
        })
    file = SimpleUploadedFile(
        "articles.json",
        json.dumps(contents).encode("utf-8"),
        content_type="application/json",
    )
    response = admin_client.post(
        "/admin/lynx/article/import/",
        data={
            "author": author.pk,
            "source": source.pk,
            "file": file
        },
        follow=True,
    )
    assert redirects_to(response, "..")
    assert success_message_shown(response)
    assert Article.objects.count() == count
    assert author.articles.count() == count
    assert source.articles.count() == count
Example #4
0
def test_str():
    user = UserFactory()
    author = AuthorFactory()
    activity = ActivityFactory(target=author,
                               action=Activity.CREATE,
                               by_user=user)
    assert str(activity) == "{} {} {}".format(user, Activity.CREATE, author)
Example #5
0
def test_author_create_rss_multiple_authors(session):
    author1 = AuthorFactory()
    author2 = AuthorFactory()
    entry = EntryFactory()
    entry.authors.append(author1)
    entry.authors.append(author2)
    entry.create_rss_author_string()

    author1.create_rss("http://test.com/author/rss")

    rss = feedparser.parse(author1.authorfeed.feed)

    assert rss.entries is not None
    assert len(rss.entries) == 1
    print(rss.entries[0].author)
    print(rss.entries[0].author_detail)
    assert rss.entries[0].author == entry.authorstring
Example #6
0
def test_create():
    user = UserFactory()
    author = AuthorFactory()
    activity = utils.create_snapshot(author, {}, user)
    assert activity.target == author
    assert activity.action == activity.CREATE
    assert activity.by_user == user
    assert activity.data["name"] == author.name
    assert activity.change == {}
Example #7
0
def test_notification_str(notification):
    author = Author(name='xyz')
    notification.sender = author

    assert 'Email Notification from' in str(notification)
    assert 'from xyz' in str(notification)

    author = AuthorFactory(name='R\xe4dda Barnen')
    notification.sender = author
    assert 'Email Notification from' in str(notification)
    assert 'from R\xe4dda Barnen' in str(notification)
Example #8
0
def test_update():
    user = UserFactory()
    author = AuthorFactory()
    obj_dict = utils.create_dict_with_relations(author)
    book = BookFactory(author=author)
    activity = utils.create_snapshot(author, obj_dict, user)
    assert activity.target == author
    assert activity.action == activity.UPDATE
    assert activity.by_user == user
    assert activity.data["name"] == author.name
    assert activity.change == {
        "books": {
            "before": [],
            "after": [book.pk]
        }
    }
    assert activity.get_display() == "Changed books"
def test_authors(api_client):
    url = reverse('book:authors')

    data = {
        'first_name': 'FirstName',
        'last_name': 'LastName',
        'date_of_birth': datetime.now().date(),
        'country': 'ukraine',
        'language': 'ua',
    }

    response = api_client.post(url, data=data, format='json')
    assert response.status_code == 201
    assert response.json()

    response = api_client.get(url)
    assert response.status_code == 200
    assert response.json()['results']

    last_record_id = response.json()['results'][-1]['id']

    url = reverse('book:author', args=(last_record_id, ))
    response = api_client.get(url)
    assert response.status_code == 200
    response_data = response.json()
    assert response_data['first_name']
    assert response_data['last_name']
    assert response_data['id']

    data = {'first_name': 'NewFirstName'}
    response = api_client.patch(url, data=data)
    assert response.status_code == 200
    assert response.json()['first_name'] == data['first_name']

    response = api_client.delete(url)
    assert response.status_code == 204
    assert response.content == b''

    author = AuthorFactory()
    url = reverse('book:author', args=(author.id,))
    response = api_client.delete(url)
    assert response.status_code == 400
    assert response.json() == {'error': 'Cannot delete Author created by system'}
Example #10
0
def test_authorfactory(session):
    author = AuthorFactory()
    author.save()
    assert isinstance(author, Author)
    assert author.id is not None
    assert author.name is not None
    assert author.givenname is not None
    assert author.familyname is not None
    assert author.url is not None
    assert author.email is not None

    author2 = AuthorFactory()
    author2.save()
    assert author.id != author2.id
Example #11
0
    def handle(self, *args, **options):
        call_command("reset_db", "--noinput")
        call_command("migrate")

        library = LibraryFactory()
        UserFactory(username="******",
                    email="*****@*****.**",
                    password="******",
                    is_superuser=True)

        users = UserFactory.create_batch(2, is_staff=False)

        GroupFactory.create_batch(5)

        for author in AuthorFactory.create_batch(10):
            for book in BookFactory.create_batch(5,
                                                 author=author,
                                                 library=library):
                BookLoanFactory(book=book, borrower=choice(users))

        self.stdout.write("All Data reset")
Example #12
0
def test_merge_authors_action(admin_client):
    authors = AuthorFactory.create_batch(5)
    article = ArticleFactory(authors=authors)
    selected = choice(authors)

    url = reverse("admin:lynx_author_changelist")
    data = {
        "post": "yes",
        "_selected_action": [author.pk for author in authors],
        "action": "merge_authors",
        "selected": selected.pk,
    }

    admin_client.post(url, data, follow=True)

    # Merged authors are deleted
    actual = [author.pk for author in Author.objects.all()]
    assert actual == [selected.pk]

    # Merged author are replaced
    actual = [author.pk for author in article.authors.all()]
    assert actual == [selected.pk]
Example #13
0
def test_get_display_update_no_change_value():
    author = AuthorFactory()
    activity = ActivityFactory(target=author, action=Activity.UPDATE)
    assert activity.get_display() == "Changed unknown"
Example #14
0
def test_get_display_update_many_field():
    author = AuthorFactory()
    activity = ActivityFactory(target=author,
                               action=Activity.UPDATE,
                               change={"books": ""})
    assert activity.get_display() == "Changed books"
Example #15
0
def test_relation():
    author = AuthorFactory()
    book = BookFactory(author=author)
    obj_dict = utils.create_dict_with_relations(author)
    assert obj_dict["books"] == [book.pk]
Example #16
0
def test_no_relation():
    author = AuthorFactory()
    obj_dict = utils.create_dict_with_relations(author)
    assert obj_dict["books"] == []
Example #17
0
def test_many_to_one_fields():
    author = AuthorFactory()
    fields = utils.get_to_many_field_names(author.__class__)
    # check many_to_one field
    assert "books" in fields
Example #18
0
def test_jsonify_unicode():
    author = AuthorFactory(name=u'R\xe4dda')
    j = utils.jsonify(model_to_dict(author))
    assert j["name"] == author.name
Example #19
0
def test_jsonify():
    author = AuthorFactory()
    j = utils.jsonify(model_to_dict(author))
    assert j["name"] == author.name
Example #20
0
def test_get_display_update_invalid_field():
    author = AuthorFactory()
    activity = ActivityFactory(target=author,
                               action=Activity.UPDATE,
                               change={"wrong": ""})
    assert activity.get_display() == "Changed "
Example #21
0
def test_get_display_update():
    author = AuthorFactory()
    activity = ActivityFactory(target=author,
                               action=Activity.UPDATE,
                               change={"name": ""})
    assert activity.get_display() == "Changed name"
def articles(topic):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    SourceFactory.create_batch(20)
    return ArticleFactory.create_batch(100, topics=[topic])
Example #23
0
def articles(source):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(20)
    return ArticleFactory.create_batch(100, source=source)
def articles():
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(20)
    NotificationFactory.create_batch(20)
    return ArticleFactory.create_batch(100)
Example #25
0
def author():
    return AuthorFactory()
Example #26
0
def articles(today):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(10)
    SourceFactory.create_batch(10)
    return ArticleFactory.create_batch(10, date=today)