Exemplo n.º 1
0
def test_activity_list_filter_active(auth_client):
    user = auth_client.user
    ActivityFactory.create(user=user)
    activity = ActivityFactory.create(user=user, to_time=None)

    url = reverse("activity-list")

    response = auth_client.get(url, data={"active": "true"})
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(json["data"]) == 1
    assert json["data"][0]["id"] == str(activity.id)
Exemplo n.º 2
0
def test_activity_list_filter_active(auth_client):
    user = auth_client.user
    ActivityFactory.create(user=user)
    activity = ActivityFactory.create(user=user)
    ActivityBlockFactory.create(activity=activity, to_time=None)

    url = reverse('activity-list')

    response = auth_client.get(url, data={'active': 'true'})
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(json['data']) == 1
    assert json['data'][0]['id'] == str(activity.id)
Exemplo n.º 3
0
def test_activity_list_filter_day(auth_client):
    user = auth_client.user
    day = date(2016, 2, 2)
    ActivityFactory.create(date=day - timedelta(days=1), user=user)
    activity = ActivityFactory.create(date=day, user=user)

    url = reverse("activity-list")
    response = auth_client.get(url, data={"day": day.strftime("%Y-%m-%d")})
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert len(json["data"]) == 1
    assert json["data"][0]["id"] == str(activity.id)
Exemplo n.º 4
0
    def setUp(self):
        """Set the environment for the tests up."""
        super().setUp()

        other_user = get_user_model().objects.create_user(username='******',
                                                          password='******')

        activity = ActivityFactory.create(user=self.user)
        other_activity = ActivityFactory.create(user=other_user)

        self.activity_blocks = ActivityBlockFactory.create_batch(
            10, activity=activity)

        ActivityBlockFactory.create_batch(10, activity=other_activity)
Exemplo n.º 5
0
def test_activity_block_to_before_from(auth_client):
    """Test that to is not before from."""
    activity = ActivityFactory.create(user=auth_client.user)
    block = ActivityBlockFactory.create(from_time=time(7, 30),
                                        to_time=None,
                                        activity=activity)

    data = {
        'data': {
            'type': 'activity-blocks',
            'id': block.id,
            'attributes': {
                'to-time': '07:00',
            }
        }
    }

    url = reverse('activity-block-detail', args=[block.id])

    res = auth_client.patch(url, data)

    assert res.status_code == status.HTTP_400_BAD_REQUEST
    json = res.json()
    assert json['errors'][0]['detail'] == (
        'An activity block may not end before it starts.')
Exemplo n.º 6
0
def test_activity_block_active_unique(auth_client):
    """Should not be able to have two active blocks."""
    activity = ActivityFactory.create(user=auth_client.user)
    block = ActivityBlockFactory.create(to_time=None, activity=activity)

    data = {
        'data': {
            'type': 'activity-blocks',
            'id': None,
            'attributes': {
                'from-time': '08:00',
            },
            'relationships': {
                'activity': {
                    'data': {
                        'type': 'activities',
                        'id': block.activity.id
                    }
                }
            }
        }
    }

    url = reverse('activity-block-list')

    res = auth_client.post(url, data)

    assert res.status_code == status.HTTP_400_BAD_REQUEST
    json = res.json()
    assert json['errors'][0]['detail'] == (
        'A user can only have one active activity')
Exemplo n.º 7
0
def test_activity_block_create(auth_client):
    user = auth_client.user
    activity = ActivityFactory.create(user=user)

    data = {
        'data': {
            'type': 'activity-blocks',
            'id': None,
            'attributes': {
                'from-time': '08:00'
            },
            'relationships': {
                'activity': {
                    'data': {
                        'type': 'activities',
                        'id': activity.id
                    }
                }
            }
        }
    }

    url = reverse('activity-block-list')

    response = auth_client.post(url, data)
    assert response.status_code == status.HTTP_201_CREATED

    json = response.json()
    assert not json['data']['attributes']['from-time'] == '08:00'
    assert json['data']['attributes']['to-time'] is None
Exemplo n.º 8
0
def test_activity_detail(auth_client):
    activity = ActivityFactory.create(user=auth_client.user)

    url = reverse('activity-detail', args=[activity.id])

    response = auth_client.get(url)
    assert response.status_code == status.HTTP_200_OK
Exemplo n.º 9
0
def test_activity_delete(auth_client):
    activity = ActivityFactory.create(user=auth_client.user)

    url = reverse("activity-detail", args=[activity.id])

    response = auth_client.delete(url)
    assert response.status_code == status.HTTP_204_NO_CONTENT
Exemplo n.º 10
0
def test_activity_retrievable_not_editable(auth_client):
    """Test that transferred activities are still retrievable."""
    activity = ActivityFactory.create(user=auth_client.user, transferred=True)

    url = reverse("activity-detail", args=[activity.id])

    response = auth_client.get(url)
    assert response.status_code == status.HTTP_200_OK
Exemplo n.º 11
0
def test_activity_set_to_time_none(auth_client):
    activity = ActivityFactory.create(user=auth_client.user)
    ActivityFactory.create(user=auth_client.user, to_time=None)

    data = {
        "data": {
            "type": "activities",
            "id": activity.id,
            "attributes": {
                "to-time": None
            },
        }
    }

    url = reverse("activity-detail", args=[activity.id])

    res = auth_client.patch(url, data)
    assert res.status_code == status.HTTP_400_BAD_REQUEST
Exemplo n.º 12
0
def test_activity_block_delete(auth_client):
    user = auth_client.user
    activity = ActivityFactory.create(user=user)
    block = ActivityBlockFactory.create(activity=activity)

    url = reverse('activity-block-detail', args=[block.id])

    response = auth_client.delete(url)
    assert response.status_code == status.HTTP_204_NO_CONTENT
Exemplo n.º 13
0
def test_activity_list(auth_client):
    activity = ActivityFactory.create(user=auth_client.user)
    url = reverse("activity-list")

    response = auth_client.get(url)
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert len(json["data"]) == 1
    assert json["data"][0]["id"] == str(activity.id)
Exemplo n.º 14
0
def test_activity_block_list(auth_client):
    user = auth_client.user
    activity = ActivityFactory.create(user=user)
    block = ActivityBlockFactory.create(activity=activity)
    ActivityBlockFactory.create()

    url = reverse('activity-block-list')
    response = auth_client.get(url)
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert len(json['data']) == 1
    assert json['data'][0]['id'] == str(block.id)
Exemplo n.º 15
0
def test_activity_active_unique(auth_client):
    """Should not be able to have two active blocks."""
    ActivityFactory.create(user=auth_client.user, to_time=None)

    data = {
        "data": {
            "type": "activities",
            "id": None,
            "attributes": {
                "from-time": "08:00",
                "date": "2017-01-01",
                "comment": "Test activity",
            },
        }
    }

    url = reverse("activity-list")

    res = auth_client.post(url, data)

    assert res.status_code == status.HTTP_400_BAD_REQUEST
    json = res.json()
    assert json["errors"][0]["detail"] == (
        "A user can only have one active activity")
Exemplo n.º 16
0
def test_activity_not_editable(auth_client):
    """Test that transferred activities are read only."""
    activity = ActivityFactory.create(user=auth_client.user, transferred=True)

    data = {
        "data": {
            "type": "activities",
            "id": activity.id,
            "attributes": {
                "comment": "Changed Comment"
            },
        }
    }

    url = reverse("activity-detail", args=[activity.id])
    response = auth_client.patch(url, data)
    assert response.status_code == status.HTTP_403_FORBIDDEN
Exemplo n.º 17
0
def test_activity_active_update(auth_client):
    activity = ActivityFactory.create(user=auth_client.user, to_time=None)

    data = {
        "data": {
            "type": "activities",
            "id": activity.id,
            "attributes": {
                "from-time": "08:00",
                "comment": "Changed Comment"
            },
        }
    }

    url = reverse("activity-detail", args=[activity.id])
    response = auth_client.patch(url, data)
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert (json["data"]["attributes"]["comment"] == data["data"]["attributes"]
            ["comment"])
Exemplo n.º 18
0
def test_activity_update(auth_client):
    activity = ActivityFactory.create(user=auth_client.user)

    data = {
        'data': {
            'type': 'activities',
            'id': activity.id,
            'attributes': {
                'comment': 'Test activity 2'
            }
        }
    }

    url = reverse('activity-detail', args=[activity.id])

    response = auth_client.patch(url, data)
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert (json['data']['attributes']['comment'] == data['data']['attributes']
            ['comment'])
Exemplo n.º 19
0
def test_activity_block_update(auth_client):
    user = auth_client.user
    activity = ActivityFactory.create(user=user)
    block = ActivityBlockFactory.create(activity=activity, to_time=time(10, 0))

    data = {
        'data': {
            'type': 'activity-blocks',
            'id': block.id,
            'attributes': {
                'to-time': '23:59:00',
                'from-time': '10:00:00'
            }
        }
    }

    url = reverse('activity-block-detail', args=[block.id])
    response = auth_client.patch(url, data)
    assert response.status_code == status.HTTP_200_OK

    json = response.json()
    assert (json['data']['attributes']['to-time'] == data['data']['attributes']
            ['to-time'])
Exemplo n.º 20
0
def test_activity_to_before_from(auth_client):
    """Test that to is not before from."""
    activity = ActivityFactory.create(user=auth_client.user,
                                      from_time=time(7, 30),
                                      to_time=None)

    data = {
        "data": {
            "type": "activities",
            "id": activity.id,
            "attributes": {
                "to-time": "07:00"
            },
        }
    }

    url = reverse("activity-detail", args=[activity.id])

    res = auth_client.patch(url, data)

    assert res.status_code == status.HTTP_400_BAD_REQUEST
    json = res.json()
    assert json["errors"][0]["detail"] == (
        "An activity block may not end before it starts.")