# Path: api/tests/factories.py
# class FuzzyFloatRound(factory.fuzzy.FuzzyFloat):
# class AbstractLocationFactory(factory.django.DjangoModelFactory):
#     class Meta:
# class UserFactory(factory.django.DjangoModelFactory):
#     class Meta:
# class ProjectFactory(AbstractLocationFactory):
#     class Meta:
# class StationFactory(AbstractLocationFactory):
#     class Meta:
# class AbstractMeteringFactory(factory.django.DjangoModelFactory):
#     class Meta:
# class MeteringFactory(AbstractMeteringFactory):
#     class Meta:
# class MeteringHistoryFactory(AbstractMeteringFactory):
#     class Meta:
#     def __init__(self, *args, **kwargs):
#     def fuzz(self):
#     def position(self):
#     def password(self):
#     def create_logo(self, create, extracted, **kwargs):
#     DEFAULT_PASSWORD = 'very_dangerous_password'
# 
# Path: api/serializers.py
# class ProjectSerializer(serializers.ModelSerializer):
#     owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
# 
#     class Meta:
#         model = Project
#         fields = (
#             'name',
#             'slug',
#             'created',
#             'updated',
#             'website',
#             'description',
#             'logo',
#             'position',
#             'country',
#             'state',
#             'county',
#             'community',
#             'city',
#             'district',
#             'owner',
#         )
# 
# class StationSerializer(serializers.ModelSerializer):
#     owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
# 
#     class Meta:
#         model = Station
#         fields = (
#             'id',
#             'name',
#             'created',
#             'updated',
#             'type',
#             'notes',
#             'is_in_test_mode',
#             'altitude',
#             'position',
#             'country',
#             'state',
#             'county',
#             'community',
#             'city',
#             'district',
#             'owner',
#             'project',
#             'last_metering',
#         )
# 
# class MeteringSerializer(serializers.ModelSerializer):
#     pm01 = serializers.FloatField(default=None, write_only=True)
#     temp_out2 = serializers.FloatField(default=None, write_only=True)
#     temp_out3 = serializers.FloatField(default=None, write_only=True)
#     temp_int_air1 = serializers.FloatField(default=None, write_only=True)
#     hum_out2 = serializers.FloatField(default=None, write_only=True)
#     hum_out3 = serializers.FloatField(default=None, write_only=True)
#     hum_int_air1 = serializers.FloatField(default=None, write_only=True)
#     rssi = serializers.FloatField(default=None, write_only=True)
#     bpress_out1 = serializers.FloatField(default=None, write_only=True)
# 
#     class Meta:
#         model = Metering
#         fields = (
#             'station',
#             'created',
#             'pm01',
#             'pm25',
#             'pm10',
#             'temp_out1',
#             'temp_out2',
#             'temp_out3',
#             'temp_int_air1',
#             'hum_out1',
#             'hum_out2',
#             'hum_out3',
#             'hum_int_air1',
#             'rssi',
#             'bpress_out1',
#             'hw_id',
#         )


from django.contrib.gis.geos.point import Point
from rest_framework.reverse import reverse
from rest_framework.status import (
    HTTP_200_OK,
    HTTP_201_CREATED,
    HTTP_204_NO_CONTENT,
    HTTP_401_UNAUTHORIZED,
    HTTP_400_BAD_REQUEST,
    HTTP_404_NOT_FOUND,
    HTTP_403_FORBIDDEN
)
from rest_framework.test import APITestCase
from .factories import (
    Project,
    Station,
    ProjectFactory,
    UserFactory,
    StationFactory,
    MeteringFactory
)
from ..serializers import ProjectSerializer, StationSerializer, MeteringSerializer
    def setUp(self):
        self.project = ProjectFactory.build()
        self.project_data = ProjectSerializer(self.project).data
        self.project_list_url = reverse('project-list')
        return super(ProjectApiTests, self).setUp()

    def create_project(self):
        self.obtain_token_and_set_auth()
        return self.client.post(self.project_list_url, self.project_data)

    def assertProjectDataEqual(self, data):
        self.assertEqual(data['name'], self.project_data['name'])
        self.assertEqual(data['website'], self.project_data['website'])
        self.assertEqual(data['description'], self.project_data['description'])
        self.assertEqual(data['logo'], self.project_data['logo'])
        self.assertEqual(data['position'], self.project_data['position'])
        self.assertEqual(data['country'], self.project_data['country'])
        self.assertEqual(data['state'], self.project_data['state'])
        self.assertEqual(data['county'], self.project_data['county'])
        self.assertEqual(data['community'], self.project_data['community'])
        self.assertEqual(data['city'], self.project_data['city'])
        self.assertEqual(data['district'], self.project_data['district'])

    def test_project_create(self):
        self.assertEqual(Project.objects.count(), 0)
        api_response = self.create_project()
        self.assertEqual(api_response.status_code, HTTP_201_CREATED)
        self.assertEqual(Project.objects.count(), 1)

        created_project = Project.objects.get()

# Path: api/tests/factories.py
# class FuzzyFloatRound(factory.fuzzy.FuzzyFloat):
# class AbstractLocationFactory(factory.django.DjangoModelFactory):
#     class Meta:
# class UserFactory(factory.django.DjangoModelFactory):
#     class Meta:
# class ProjectFactory(AbstractLocationFactory):
#     class Meta:
# class StationFactory(AbstractLocationFactory):
#     class Meta:
# class AbstractMeteringFactory(factory.django.DjangoModelFactory):
#     class Meta:
# class MeteringFactory(AbstractMeteringFactory):
#     class Meta:
# class MeteringHistoryFactory(AbstractMeteringFactory):
#     class Meta:
#     def __init__(self, *args, **kwargs):
#     def fuzz(self):
#     def position(self):
#     def password(self):
#     def create_logo(self, create, extracted, **kwargs):
#     DEFAULT_PASSWORD = 'very_dangerous_password'
# 
# Path: api/serializers.py
# class ProjectSerializer(serializers.ModelSerializer):
#     owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
# 
#     class Meta:
#         model = Project
#         fields = (
#             'name',
#             'slug',
#             'created',
#             'updated',
#             'website',
#             'description',
#             'logo',
#             'position',
#             'country',
#             'state',
#             'county',
#             'community',
#             'city',
#             'district',
#             'owner',
#         )
# 
# class StationSerializer(serializers.ModelSerializer):
#     owner = serializers.HiddenField(default=serializers.CurrentUserDefault())
# 
#     class Meta:
#         model = Station
#         fields = (
#             'id',
#             'name',
#             'created',
#             'updated',
#             'type',
#             'notes',
#             'is_in_test_mode',
#             'altitude',
#             'position',
#             'country',
#             'state',
#             'county',
#             'community',
#             'city',
#             'district',
#             'owner',
#             'project',
#             'last_metering',
#         )
# 
# class MeteringSerializer(serializers.ModelSerializer):
#     pm01 = serializers.FloatField(default=None, write_only=True)
#     temp_out2 = serializers.FloatField(default=None, write_only=True)
#     temp_out3 = serializers.FloatField(default=None, write_only=True)
#     temp_int_air1 = serializers.FloatField(default=None, write_only=True)
#     hum_out2 = serializers.FloatField(default=None, write_only=True)
#     hum_out3 = serializers.FloatField(default=None, write_only=True)
#     hum_int_air1 = serializers.FloatField(default=None, write_only=True)
#     rssi = serializers.FloatField(default=None, write_only=True)
#     bpress_out1 = serializers.FloatField(default=None, write_only=True)
# 
#     class Meta:
#         model = Metering
#         fields = (
#             'station',
#             'created',
#             'pm01',
#             'pm25',
#             'pm10',
#             'temp_out1',
#             'temp_out2',
#             'temp_out3',
#             'temp_int_air1',
#             'hum_out1',
#             'hum_out2',
#             'hum_out3',
#             'hum_int_air1',
#             'rssi',
#             'bpress_out1',
#             'hw_id',
#         )


# Path: api/tests/test_views.py
from django.contrib.gis.geos.point import Point
from rest_framework.reverse import reverse
from rest_framework.status import (
    HTTP_200_OK,
    HTTP_201_CREATED,
    HTTP_204_NO_CONTENT,
    HTTP_401_UNAUTHORIZED,
    HTTP_400_BAD_REQUEST,
    HTTP_404_NOT_FOUND,
    HTTP_403_FORBIDDEN
)
from rest_framework.test import APITestCase
from .factories import (
    Project,
    Station,
    ProjectFactory,
    UserFactory,
    StationFactory,
    MeteringFactory
)
from ..serializers import ProjectSerializer, StationSerializer, MeteringSerializer

    def setUp(self):
        self.project = ProjectFactory.build()
        self.project_data = ProjectSerializer(self.project).data
        self.project_list_url = reverse('project-list')
        return super(ProjectApiTests, self).setUp()

    def create_project(self):
        self.obtain_token_and_set_auth()
        return self.client.post(self.project_list_url, self.project_data)

    def assertProjectDataEqual(self, data):
        self.assertEqual(data['name'], self.project_data['name'])
        self.assertEqual(data['website'], self.project_data['website'])
        self.assertEqual(data['description'], self.project_data['description'])
        self.assertEqual(data['logo'], self.project_data['logo'])
        self.assertEqual(data['position'], self.project_data['position'])
        self.assertEqual(data['country'], self.project_data['country'])
        self.assertEqual(data['state'], self.project_data['state'])
        self.assertEqual(data['county'], self.project_data['county'])
        self.assertEqual(data['community'], self.project_data['community'])
        self.assertEqual(data['city'], self.project_data['city'])
        self.assertEqual(data['district'], self.project_data['district'])

    def test_project_create(self):
        self.assertEqual(Project.objects.count(), 0)
        api_response = self.create_project()
        self.assertEqual(api_response.status_code, HTTP_201_CREATED)
        self.assertEqual(Project.objects.count(), 1)

        created_project = Project.objects.get()

        created_project_data = ProjectSerializer(created_project).data