Ejemplo n.º 1
0
 def test_delete(self):
     table1 = Table(table_name="First Table")
     table1.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     leg1.delete()
     self.assertEqual(Leg.objects.count(), 0)
Ejemplo n.º 2
0
 def test_create(self):
     table1 = Table(table_name="First Table")
     table1.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     self.assertEqual(Leg.objects.count(), 1)
     self.assertEqual(Leg.objects.get(pk=1).table_id, table1)
Ejemplo n.º 3
0
    def test_invalid_data(self):
        table1 = Table(table_name="First Table")
        table1.save()
        leg1 = Leg(table_id=table1)
        leg1.save()
        try:
            with transaction.atomic():
                foot1 = Feet(radius=6, length=1.7, width=2)
                foot1.save()
        except Exception as exception:
            assert "ValidationError" in str(exception)

        try:
            with transaction.atomic():
                foot1 = Feet(length=1.7)
                foot1.save()
        except Exception as exception:
            assert "ValidationError" in str(exception)

        try:
            with transaction.atomic():
                foot1 = Feet(width=1)
                foot1.save()
        except Exception as exception:
            assert "ValidationError" in str(exception)
Ejemplo n.º 4
0
def claim():
    table_id = request.form['table_id']
    table = Table(table_id)
    table.claim(session['username'])

    flash('Table: %s in now on you. Take care of it!' % table.name)
    return "200"
Ejemplo n.º 5
0
 def test_create_rectangle(self):
     table1 = Table(table_name="First Table")
     table1.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     foot1 = Feet(length=1.7, width=2)
     foot1.save()
     foot1.leg.set([leg1])
     foot1.save()
     self.assertEqual(Feet.objects.count(), 1)
Ejemplo n.º 6
0
 def test_create_circle(self):
     table1 = Table(table_name="First Table")
     table1.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     foot1 = Feet(radius=1)
     foot1.save()
     foot1.leg.set([leg1])
     foot1.save()
     self.assertEqual(Feet.objects.count(), 1)
Ejemplo n.º 7
0
    def test_set_columns(self):
        arra = TableFu.from_file(self.filename)
        arra.columns = ["State", "County", "Urban Area"]

        tabled = Table(
            title="That Stimulus", added_by=self.user, file=File(self.file), columns=["State", "County", "Urban Area"]
        )
        tabled.save()

        self.assertEqual(arra.columns, tabled.data.columns)
Ejemplo n.º 8
0
    def test_update(self):
        table1 = Table(table_name="First Table")
        table1.save()
        leg1 = Leg(table_id=table1)
        leg1.save()
        foot1 = Feet(length=100, width=2)
        foot1.save()
        foot1.leg.set([leg1])
        foot1.save()
        self.assertEqual(Feet.objects.count(), 1)
        self.assertEqual(Feet.objects.get(foot_id=1).length, 100)

        foot1.length = 200
        foot1.save()
        self.assertEqual(Feet.objects.get(foot_id=1).length, 200)
Ejemplo n.º 9
0
    def test_freeing_table(self):
        user_id = "user-1"
        table_id = "test-1"

        table = Table(table_id)
        table.redis_client = self.mock_redis
        table.claim(user_id)

        self.assertTrue(table.is_used_now())
        table.free(user_id)
        self.assertFalse(table.is_used_now())
        self.assertEqual(len(table.check()), 2)
Ejemplo n.º 10
0
 def test_list(self):
     table1 = Table(table_name="First Table")
     table1.save()
     table2 = Table(table_name="Second Table")
     table2.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     leg2 = Leg(table_id=table2)
     leg2.save()
     self.assertEqual(Leg.objects.count(), 2)
Ejemplo n.º 11
0
 def test_update(self):
     table1 = Table(table_name="First Table")
     table1.save()
     assert Table.objects.get(pk=1).table_name == "First Table"
     table1.table_name = "First Updated Table"
     table1.save()
     self.assertEqual(Table.objects.get(pk=1).table_name, "First Updated Table")
Ejemplo n.º 12
0
 def test_update(self):
     table1 = Table(table_name="First Table")
     table1.save()
     table2 = Table(table_name="Second Table")
     table2.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     self.assertEqual(Leg.objects.get(pk=1).table_id, table1)
     leg1.table_id = table2
     leg1.save()
     self.assertEqual(Leg.objects.get(pk=1).table_id, table2)
Ejemplo n.º 13
0
 def test_detail(self):
     table1 = Table(table_name="First Table")
     table1.save()
     table2 = Table(table_name="Second Table")
     table2.save()
     leg1 = Leg(table_id=table1)
     leg1.save()
     leg2 = Leg(table_id=table2)
     leg2.save()
     foot1 = Feet(length=70, width=20)
     foot1.save()
     foot1.leg.set([leg1, leg2])
     foot1.save()
     self.assertEqual(Feet.objects.get(foot_id=1).width, 20)
Ejemplo n.º 14
0
    def test_claiming_table(self, m_datetime):
        m_datetime.now = lambda: 12
        user_id = "user-1"
        table_id = "test-1"

        table = Table(table_id)
        table.redis_client = self.mock_redis
        table.claim(user_id)

        table_status = table.check()[0]
        desired_output = {
            'action': 'claim',
            'user_id': 'user-1',
            'how_long': datetime.timedelta(0, 1800),
            'created': 12
        }

        self.assertEqual(table_status, desired_output)
        self.assertTrue(table.is_used_now())
Ejemplo n.º 15
0
def create(request):
    table = Table(id=uuid.uuid4())

    table.save()

    return JsonResponse({'id': table.id}, status=201)
Ejemplo n.º 16
0
 def test_create(self):
     Table(table_name="First Table").save()
     assert Table.objects.count() == 1
Ejemplo n.º 17
0
 def test_list(self):
     Table(table_name="First Table").save()
     Table(table_name="Second Table").save()
     assert Table.objects.count() == 2
Ejemplo n.º 18
0
 def test_delete(self):
     table1 = Table(table_name="First Table")
     table1.save()
     table1.delete()
     self.assertEqual(Table.objects.count(), 0)
Ejemplo n.º 19
0
    def test_from_file(self):
        arra = TableFu.from_file(self.filename)
        tabled = Table(title="That Stimulus", added_by=self.user, file=File(self.file))
        tabled.save()

        self.assertEqual(arra.table, tabled.data.table)
Ejemplo n.º 20
0
    def post(self):
        table = Table(creator_id=request.json['creator_id'])

        db.session.add(table)
        db.session.commit()
        return jsonify(table.serialize)
Ejemplo n.º 21
0
 def test_detail(self):
     Table(table_name="First Table").save()
     Table(table_name="Second Table").save()
     Table(table_name="Third Table").save()
     assert Table.objects.get(pk=1).table_name == "First Table"
Ejemplo n.º 22
0
def free():
    table_id = request.form['table_id']
    table = Table(table_id)
    table.free(session['username'])
    flash('Table: %s is now free. Thanks!' % table.name)
    return "200"
Ejemplo n.º 23
0
    def test_from_url(self):
        murders = TableFu.from_url(self.url)
        tabled = Table(title="DC Homicides 2010", added_by=self.user, url=self.url)
        tabled.save()

        self.assertEqual(murders.table, tabled.data.table)