Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Handle import issues and add uniqueness constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdines committed Sep 7, 2018
1 parent b7fea42 commit 31eebae
Show file tree
Hide file tree
Showing 29 changed files with 200 additions and 56 deletions.
1 change: 0 additions & 1 deletion pip_src/bullet_train_api/users

This file was deleted.

5 changes: 4 additions & 1 deletion src/api/migrations/0005_auto_20180514_1557.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from django.db import migrations, models

from ...app import utils
try:
from app import utils
except ModuleNotFoundError:
from bullet_train_api.app import utils


class Migration(migrations.Migration):
Expand Down
5 changes: 4 additions & 1 deletion src/api/migrations/0011_auto_20180517_1646.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from django.db import migrations, models

from ...app import utils
try:
from app import utils
except ModuleNotFoundError:
from bullet_train_api.app import utils


class Migration(migrations.Migration):
Expand Down
15 changes: 12 additions & 3 deletions src/api/migrations/0018_auto_20180524_1521.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@
from django.db import migrations, models
import django.db.models.deletion

try:
from users import apps
_dependencies = [
('users', '0013_auto_20180524_1521'),
('api', '0017_feature_description'),
]
except ModuleNotFoundError:
_dependencies = [
('api', '0017_feature_description'),
]


class Migration(migrations.Migration):

dependencies = [
('api', '0017_feature_description'),
]
dependencies = _dependencies

operations = [
migrations.AlterField(
Expand Down
21 changes: 13 additions & 8 deletions src/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
from rest_framework.authtoken.models import Token
from rest_framework.test import APIClient

from ..environments.models import Environment, Identity
from ..features.models import Feature, FeatureState
from ..projects.models import Project
from ..organisations.models import Organisation
try:
from environments.models import Environment, Identity
from features.models import Feature, FeatureState
from projects.models import Project
from organisations.models import Organisation
from users.models import FFAdminUser, Invite
except ModuleNotFoundError:
from bullet_train_api.environments.models import Environment, Identity
from bullet_train_api.features.models import Feature, FeatureState
from bullet_train_api.projects.models import Project
from bullet_train_api.organisations.models import Organisation
from bullet_train_api.users.models import FFAdminUser, Invite

from rest_framework import status

from ..users.models import FFAdminUser, Invite


class OrganisationTestCase(TestCase):
put_template = '{ "name" : "%s"}'
Expand Down Expand Up @@ -326,8 +332,7 @@ def test_should_delete_feature_states_when_feature_deleted(self):
# Given
client = self.set_up()
organisation = Organisation.objects.get(name="test org")
project = Project(name="test project", organisation=organisation)
project.save()
project = Project.objects.get(name="test project", organisation=organisation)
environment_1 = Environment(name="env 1", project=project)
environment_2 = Environment(name="env 2", project=project)
environment_3 = Environment(name="env 3", project=project)
Expand Down
5 changes: 4 additions & 1 deletion src/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.conf.urls import url, include

from ..features.views import SDKFeatureStates
try:
from features.views import SDKFeatureStates
except ModuleNotFoundError:
from bullet_train_api.features.views import SDKFeatureStates

urlpatterns = [
url(r'^v1/', include([
Expand Down
2 changes: 1 addition & 1 deletion src/docs/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf.urls import url

from ..docs.views import schema_view
from .views import schema_view

urlpatterns = [
url(r'^', schema_view, name='index')
Expand Down
5 changes: 4 additions & 1 deletion src/environments/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# Generated by Django 1.11.13 on 2018-05-25 15:41
from __future__ import unicode_literals

from ...app import utils
try:
from app import utils
except ModuleNotFoundError:
from bullet_train_api.app import utils
from django.db import migrations, models
import django.db.models.deletion

Expand Down
24 changes: 24 additions & 0 deletions src/environments/migrations/0003_auto_20180907_0313.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-07 03:13
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('projects', '0002_auto_20180907_0313'),
('environments', '0002_auto_20180809_0014'),
]

operations = [
migrations.AlterUniqueTogether(
name='environment',
unique_together=set([('name', 'project')]),
),
migrations.AlterUniqueTogether(
name='identity',
unique_together=set([('identifier', 'environment')]),
),
]
13 changes: 10 additions & 3 deletions src/environments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

from ..app.utils import create_hash
from django.utils.encoding import python_2_unicode_compatible
from ..features.models import FeatureState
from ..projects.models import Project
try:
from app.utils import create_hash
from features.models import FeatureState
from projects.models import Project
except ModuleNotFoundError:
from bullet_train_api.app.utils import create_hash
from bullet_train_api.features.models import FeatureState
from bullet_train_api.projects.models import Project


@python_2_unicode_compatible
Expand All @@ -28,6 +33,7 @@ class Environment(models.Model):
api_key = models.CharField(default=create_hash, unique=True, max_length=100)

class Meta:
unique_together = ("name", "project")
ordering = ['id']

def save(self, *args, **kwargs):
Expand Down Expand Up @@ -72,6 +78,7 @@ class Identity(models.Model):
)

class Meta:
unique_together = ("identifier", "environment")
verbose_name_plural = "Identities"
ordering = ['id']

Expand Down
11 changes: 8 additions & 3 deletions src/environments/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from rest_framework import serializers

from ..features.serializers import FeatureStateSerializerFull
from ..environments.models import Environment, Identity
from ..projects.serializers import ProjectSerializer
try:
from features.serializers import FeatureStateSerializerFull
from environments.models import Environment, Identity
from projects.serializers import ProjectSerializer
except ModuleNotFoundError:
from bullet_train_api.features.serializers import FeatureStateSerializerFull
from bullet_train_api.environments.models import Environment, Identity
from bullet_train_api.projects.serializers import ProjectSerializer


class EnvironmentSerializerFull(serializers.ModelSerializer):
Expand Down
11 changes: 8 additions & 3 deletions src/environments/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.test import TestCase

from .models import Environment, Identity
from ..features.models import Feature, FeatureState
from ..organisations.models import Organisation
from ..projects.models import Project
try:
from features.models import Feature, FeatureState
from organisations.models import Organisation
from projects.models import Project
except ModuleNotFoundError:
from bullet_train_api.features.models import Feature, FeatureState
from bullet_train_api.organisations.models import Organisation
from bullet_train_api.projects.models import Project


class EnvironmentTestCase(TestCase):
Expand Down
6 changes: 5 additions & 1 deletion src/environments/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from django.conf.urls import url, include
from rest_framework_nested import routers

from ..features.views import FeatureStateViewSet
try:
from features.views import FeatureStateViewSet
except ModuleNotFoundError:
from bullet_train_api.features.views import FeatureStateViewSet

from .views import IdentityViewSet, EnvironmentViewSet

router = routers.DefaultRouter()
Expand Down
5 changes: 4 additions & 1 deletion src/features/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from ..projects.models import Project
try:
from projects.models import Project
except ModuleNotFoundError:
from bullet_train_api.projects.models import Project


# Feature Types
Expand Down
12 changes: 9 additions & 3 deletions src/features/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from django.test import TestCase

from ..environments.models import Environment
try:
from environments.models import Environment
from organisations.models import Organisation
from projects.models import Project
except ModuleNotFoundError:
from bullet_train_api.environments.models import Environment
from bullet_train_api.organisations.models import Organisation
from bullet_train_api.projects.models import Project

from .models import Feature, FeatureState
from ..organisations.models import Organisation
from ..projects.models import Project


class FeatureTestCase(TestCase):
Expand Down
8 changes: 6 additions & 2 deletions src/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from rest_framework.response import Response
from rest_framework.schemas import AutoSchema

from ..environments.models import Environment, Identity
from ..projects.models import Project
try:
from environments.models import Environment, Identity
from projects.models import Project
except ModuleNotFoundError:
from bullet_train_api.environments.models import Environment, Identity
from bullet_train_api.projects.models import Project
from .models import FeatureState, Feature
from .serializers import FeatureStateSerializerBasic, FeatureStateSerializerFull, \
FeatureStateSerializerCreate, CreateFeatureSerializer, FeatureSerializer, \
Expand Down
7 changes: 5 additions & 2 deletions src/organisations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

from django.contrib import admin

from ..projects.models import Project
from ..organisations.models import Organisation
try:
from projects.models import Project
except ModuleNotFoundError:
from bullet_train_api.projects.models import Project
from .models import Organisation


class ProjectInline(admin.StackedInline):
Expand Down
20 changes: 20 additions & 0 deletions src/organisations/migrations/0003_auto_20180907_0313.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-07 03:13
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('organisations', '0002_organisation_has_requested_features'),
]

operations = [
migrations.AlterField(
model_name='organisation',
name='name',
field=models.CharField(max_length=2000, unique=True),
),
]
2 changes: 1 addition & 1 deletion src/organisations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@python_2_unicode_compatible
class Organisation(models.Model):
name = models.CharField(max_length=2000)
name = models.CharField(max_length=2000, unique=True)
has_requested_features = models.BooleanField(default=False)

class Meta:
Expand Down
10 changes: 7 additions & 3 deletions src/organisations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
from rest_framework.exceptions import ValidationError
from rest_framework.response import Response

from ..projects.serializers import ProjectSerializer
from ..organisations.serializers import OrganisationSerializer
from ..users.serializers import UserFullSerializer, InviteSerializer
try:
from projects.serializers import ProjectSerializer
from users.serializers import UserFullSerializer, InviteSerializer
except ModuleNotFoundError:
from bullet_train_api.projects.serializers import ProjectSerializer
from bullet_train_api.users.serializers import UserFullSerializer, InviteSerializer
from .serializers import OrganisationSerializer


class OrganisationViewSet(viewsets.ModelViewSet):
Expand Down
10 changes: 7 additions & 3 deletions src/projects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

from django.contrib import admin

from ..environments.models import Environment
from ..features.models import Feature
from ..projects.models import Project
try:
from environments.models import Environment
from features.models import Feature
except ModuleNotFoundError:
from bullet_train_api.environments.models import Environment
from bullet_train_api.features.models import Feature
from .models import Project


class EnvironmentInline(admin.StackedInline):
Expand Down
20 changes: 20 additions & 0 deletions src/projects/migrations/0002_auto_20180907_0313.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.15 on 2018-09-07 03:13
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('organisations', '0003_auto_20180907_0313'),
('projects', '0001_initial'),
]

operations = [
migrations.AlterUniqueTogether(
name='project',
unique_together=set([('name', 'organisation')]),
),
]
6 changes: 5 additions & 1 deletion src/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

from ..organisations.models import Organisation
try:
from organisations.models import Organisation
except ModuleNotFoundError:
from bullet_train_api.organisations.models import Organisation


@python_2_unicode_compatible
Expand All @@ -19,6 +22,7 @@ class Project(models.Model):

class Meta:
ordering = ['id']
unique_together = ('name', 'organisation')

def __str__(self):
return "Project %s" % self.name
Loading

0 comments on commit 31eebae

Please sign in to comment.