Exemple #1
0
 def test_to_dict(self):
     c = CategoryFactory()
     d = c.to_dict()
     self.assertEqual(sorted(d.keys()), sorted(["id", "name", "parent_id"]))
     self.assertEqual(d["id"], c.category_id)
     self.assertEqual(d["name"], c.name)
     self.assertEqual(d["parent_id"], c.parent_id)
Exemple #2
0
def test_categories_can_be_listed(client, num_of_categories):
    CategoryFactory.create_batch(size=num_of_categories)
    response = client.get('/categories')

    assert response.status_code == 200
    assert response.content_type == 'application/json'
    assert len(response.json['items']) == num_of_categories
Exemple #3
0
 def setUp(self):
     self.client = Client()
     category = CategoryFactory(slug="tier2",
                                parent=CategoryFactory(slug="tier1"))
     # We need a category so haystack doesn't get upset
     ProductFactory(primary_category=category, status="l")
     call_command("rebuild_index", interactive=False)
     self.addCleanup(call_command, "clear_index", interactive=False)
Exemple #4
0
def test_get_post(db_connection, event_loop, test_client, cookies_fixture):
    category1, category2, category3 = event_loop.run_until_complete(
        CategoryFactory.create_batch(3))
    post = event_loop.run_until_complete(PostFactory.create())
    response = test_client.get(f'/admin/blog/{post.title_slug}',
                               cookies=cookies_fixture)

    assert response.status_code == 200
    assert '<form id="update-post" method="post">' \
        in response.text
    assert '<label for="title">Title:</label>' in response.text
    assert f'<input id="title" name="title" type="text" required autofocus ' \
           f'value="{post.title}">' in response.text
    assert '<label for="category_id">Category:</label>' in response.text
    assert '<input id="category_id" name="category_id" list="category_values' \
           f'" required value="{post.category_id}">' in response.text
    assert '<datalist id="category_values">' in response.text
    assert f'<option value="{category1.id}">{category1.name}</option>' \
        in response.text
    assert f'<option value="{category2.id}">{category2.name}</option>' \
        in response.text
    assert f'<option value="{category3.id}">{category3.name}</option>' \
        in response.text
    assert '</datalist>' in response.text
    assert '<label for="description">Description:</label>' in response.text
    assert '<input id="description" name="description" type="text" required ' \
           f'value="{post.description}">' in response.text
    assert '<label for="body">Body:</label>' in response.text
    assert '<textarea id="body" name="body" required>' \
           f'{post.body}</textarea>' in response.text
    assert '<input type="submit" value="Update">' in response.text
    assert '<p>post updated successfully</p>' not in response.text
Exemple #5
0
def test_get_category_by_name(client):
    category = CategoryFactory()
    response = client.get('/categories?name=%s' % category.name)

    assert response.status_code == 200
    assert response.content_type == 'application/json'
    expected = {'items': [{'id': category.id, 'name': category.name}]}
    assert response.json == expected
Exemple #6
0
async def test_filter_by_id(db_transaction):
    fixture = CategoryFactory(name='qwerty')
    await fixture.save()
    categories = await Category.filter(id=fixture.id)
    record = categories[0]

    assert record.id == fixture.id
    assert record.name == 'qwerty'
Exemple #7
0
def test_an_articles_can_be_created_by_put_request_with_categories(
        client, num_of_cats):
    categories = CategoryFactory.create_batch(size=num_of_cats)
    response = client.put('/articles/%d' % num_of_cats,
                          json={'categories': [c.id for c in categories]})
    assert response.status_code == 201

    article = models.Article.query.get('%d' % num_of_cats)
    assert len(article.categories) == num_of_cats
 def create_product(self, db):
     brand = BrandFactory()
     category = CategoryFactory()
     db.session.commit()
     db.session.refresh(category)
     db.session.refresh(brand)
     product = ProductFactory(brand=brand, categories=[category])
     db.session.commit()
     db.session.refresh(product)
     return product, brand, category
Exemple #9
0
def test_create_post_with_missing_data(db_connection, event_loop, test_client,
                                       cookies_fixture):
    category = event_loop.run_until_complete(CategoryFactory.create())
    response = test_client.post('/admin/blog',
                                cookies=cookies_fixture,
                                data={
                                    'body': 'test body',
                                    'category_id': category.id
                                })

    assert response.status_code == 400
    assert '<p>title is obligatory</p>' in response.text
Exemple #10
0
async def test_filter_by_name_and_description_with_two_different_filter_calls(
        category_fixture):
    cat = CategoryFactory.build(description='another description')
    await cat.save()
    queryset = Category.filter(description='test description')
    queryset = queryset.filter(name='test name')
    categories = await queryset
    record = categories[0]

    assert len(categories) == 1
    assert record.id == category_fixture.id
    assert record.description == 'test description'
Exemple #11
0
def test_create_post(db_connection, event_loop, test_client, cookies_fixture):
    category = event_loop.run_until_complete(CategoryFactory.create())
    response = test_client.post('/admin/blog',
                                cookies=cookies_fixture,
                                data={
                                    'title': 'test title',
                                    'body': 'test body',
                                    'category_id': category.id,
                                    'description': 'test description'
                                })

    assert response.status_code == 201
    assert '<p>post created successfully</p>' in response.text
Exemple #12
0
    def setUp(self):
        self.database = ':memory:'

        self.category_storage = CategoryStorage(self.database)
        self.task_storage = TaskStorage(self.database)
        self.task_plan_storage = TaskPlanStorage(self.database)
        self.notification_storage = NotificationStorage(self.database)
        self.category = CategoryFactory(user_id=10)
        self.task = TaskFactory()
        self.task_plan = TaskPlanFactory()
        self.notification = NotificationFactory()

        DatabaseConnector(self.database).create_tables()
Exemple #13
0
    def setUp(self):
        self.database = ':memory:'

        self.user_id = 10
        self.categories_controller = CategoriesController(
            self.user_id, CategoryStorage(self.database))
        self.tasks_controller = TasksController(self.user_id,
                                                TaskStorage(self.database))
        self.task_plans_controller = TaskPlansController(
            self.user_id, TaskPlanStorage(self.database))
        self.notifications_controller = NotificationsController(
            self.user_id, NotificationStorage(self.database))
        self.category = CategoryFactory()
        self.task = TaskFactory()
        self.task_plan = TaskPlanFactory()
        self.notification = NotificationFactory()
        DatabaseConnector(self.database).create_tables()
 def test_article_submit(self, admin_client):
     CategoryFactory()
     TagFactory()
     cat_id = Category.objects.all()[0].pk
     tag_id = Tag.objects.all()[0].pk
     response = admin_client.post(
         self.article_url, {
             'title': 'Title_text',
             'decsription': 'Description_text',
             'published': True,
             'category': cat_id,
             'tags': tag_id,
             'updated_at': '11-11-2016 10:53'
         })
     articles_obj = Article.objects.count()
     assert response.status_code == 302
     assert articles_obj == 1
Exemple #15
0
def test_category(graph_client):
    query = '''
        query($id: ID!) {
            category(id: $id) {
                name
                description
            }
        }
    '''
    category = CategoryFactory.create()
    result = graph_client.execute(query, variable_values={'id': model_instance_id_to_base64(category)})
    assert result == {
        'data': {
            'category': {
                'name': category.name,
                'description': category.description
            }
        }
    }
    def test_create_product_should_became_featured_if_rating_more_than_8(
            self, db, product_request, client):
        brand = BrandFactory()
        category = CategoryFactory()
        db.session.commit()
        db.session.refresh(category)
        db.session.refresh(brand)

        product_request['brand_id'] = brand.id
        product_request['categories'] = [category.id]
        product_request['rating'] = 8.5

        response = client.post(url_for("products.create_product"),
                               json=product_request)
        response_dict = json.loads(response.data)
        assert response.status_code == 200
        assert 'validation_error' not in response_dict
        assert 'error' not in response_dict
        assert response_dict['featured'] == True
    def test_create_product_just_do_it(self, db, product_request, client):
        brand = BrandFactory()
        category = CategoryFactory()
        db.session.commit()
        db.session.refresh(category)
        db.session.refresh(brand)
        product_request['brand_id'] = brand.id
        product_request['categories'] = [category.id]

        response = client.post(url_for("products.create_product"),
                               json=product_request)
        response_dict = json.loads(response.data)

        assert response.status_code == 200
        assert 'validation_error' not in response_dict
        assert 'error' not in response_dict
        assert response_dict['id'] is not None
        assert response_dict['name'] == product_request['name']
        assert response_dict['brand']['id'] == brand.id
        assert response_dict['categories'][0]['id'] == category.id
Exemple #18
0
async def category_fixture(db_transaction):
    category = CategoryFactory.build()
    await category.save()
    return category
Exemple #19
0
def test_str(category_factory: factories.CategoryFactory) -> None:
    """Test that the string representation returns the name."""
    category = category_factory.build(name="Python")
    assert str(category) == "Python"
Exemple #20
0
 def test_from_xml(self):
     c = CategoryFactory()
     el = c.to_xml()
     parsed_c = Category.from_xml(el)
     self.assertEqual(c.to_dict(), parsed_c.to_dict())
Exemple #21
0
 def test_to_xml(self):
     c = CategoryFactory(parent_id=None)
     el = c.to_xml()
     expected_el = ET.Element("category", {"id": c.category_id})
     expected_el.text = c.name
     self.assertElementsEquals(el, expected_el)
Exemple #22
0
 def test_search_mixin_no_search_fules(self):
     CategoryFactory.create_batch(size=10)
     categories = Category.objects.search(query="foo")
     self.assertEqual(0, categories.count())
Exemple #23
0
async def test_all(create_db, db_transaction):
    categories = CategoryFactory.build_batch(5)
    for category in categories:
        await category.save()

    assert len(await Category.all()) == 5