Ejemplo n.º 1
0
def test_categories(sku_client, admin_user):
    location = factories.LocationFactory(user=admin_user)
    department = factories.DepartmentFactory(location=location,
                                             user=admin_user)
    res = sku_client.get(reverse('locations:category-list'))
    assert res.status_code == 200

    payload = {"name": "category", "department": department.pk}
    response = sku_client.post(path=reverse('locations:category-list'),
                               data=json.dumps(payload),
                               content_type='application/json',
                               follow=True)
    assert response.status_code == 201
    category = models.Category.objects.last()
    assert category.name == 'category'

    response = sku_client.get(
        reverse('locations:category-detail', args=[category.pk]))
    assert response.status_code == 200
    assert category.name == 'category'

    response = sku_client.delete(
        reverse('locations:category-detail', args=[category.pk]))
    assert response.status_code == 204
    assert models.Category.objects.count() == 0
Ejemplo n.º 2
0
def test_locations(sku_client, admin_user):
    location = factories.LocationFactory(sku_code="sku_1",
                                         sku_name="sku_name",
                                         name="location",
                                         user=admin_user)
    res = sku_client.get(reverse('locations:location-list'))
    assert res.status_code == 200

    payload = {"sku_code": "sku_2", "sku_name": "sku_2", "name": "location2"}
    response = sku_client.post(path=reverse('locations:location-list'),
                               data=json.dumps(payload),
                               content_type='application/json',
                               follow=True)
    assert response.status_code == 201
    location = models.Location.objects.first()
    assert location.name == 'location2'

    response = sku_client.get(
        reverse('locations:location-detail', args=[location.pk]))
    assert response.status_code == 200
    assert location.name == 'location2'

    response = sku_client.delete(
        reverse('locations:location-detail', args=[location.pk]))
    assert response.status_code == 204
    assert models.Location.objects.count() == 1
Ejemplo n.º 3
0
def test_department(db, admin_user):
    location = factories.LocationFactory(user=admin_user)
    factories.DepartmentFactory(name="test dpt", location=location, user=admin_user)

    assert models.Location.objects.count() == 1
    assert models.Department.objects.count() == 1
    dept = models.Department.objects.first()
    assert dept.name == 'test dpt'
Ejemplo n.º 4
0
def test_location(db, admin_user):
    factories.LocationFactory(
        sku_code="sku_1",
        sku_name="sku_name",
        name="location",
        user=admin_user
    )
    assert models.Location.objects.count() == 1
    location = models.Location.objects.first()
    assert location.name == 'location'
Ejemplo n.º 5
0
def test_category(db, admin_user):
    location = factories.LocationFactory(user=admin_user)
    department = factories.DepartmentFactory(location=location, user=admin_user)
    factories.CategoryFactory(name="test cat", department=department, user=admin_user)

    assert models.Location.objects.count() == 1
    assert models.Department.objects.count() == 1
    assert models.Category.objects.count() == 1
    cat = models.Category.objects.first()
    assert cat.name == 'test cat'
Ejemplo n.º 6
0
def setup_data(admin_user):
    location = factories.LocationFactory(name="location",
                                         sku_code="SKU 1",
                                         sku_name="SKU Name",
                                         user=admin_user)
    department = factories.DepartmentFactory(name="dept",
                                             location=location,
                                             user=admin_user)
    category = factories.CategoryFactory(name="cat",
                                         department=department,
                                         user=admin_user)
    subcat = factories.SubcategoryFactory(name="subcat",
                                          category=category,
                                          user=admin_user)
Ejemplo n.º 7
0
def test_departments(sku_client, admin_user):
    location = factories.LocationFactory(user=admin_user)
    res = sku_client.get(reverse('locations:department-list'))
    assert res.status_code == 200

    payload = {"name": "dept 2", "location": location.pk}
    response = sku_client.post(path=reverse('locations:department-list'),
                               data=json.dumps(payload),
                               content_type='application/json',
                               follow=True)
    assert response.status_code == 201
    dept = models.Department.objects.last()
    assert dept.name == 'dept 2'

    response = sku_client.get(
        reverse('locations:department-detail', args=[dept.pk]))
    assert response.status_code == 200
    assert dept.name == 'dept 2'

    response = sku_client.delete(
        reverse('locations:department-detail', args=[dept.pk]))
    assert response.status_code == 204
    assert models.Department.objects.count() == 0