Пример #1
0
    def test_get_signature_weights(self):
        self.cluster_set = ClusterSetSnapshot(
            game_format=FormatType.FT_STANDARD, live_in_production=True)
        self.cluster_set.save()

        self.class_cluster = ClassClusterSnapshot(cluster_set=self.cluster_set,
                                                  player_class=CardClass.DRUID)
        self.class_cluster.save()

        self.cluster = ClusterSnapshot(class_cluster=self.class_cluster,
                                       cluster_id=1,
                                       external_id=247,
                                       required_cards=[48625],
                                       ccp_signature=MECHATHUN_DRUID)
        self.cluster.save()

        signature_weights = ClusterManager().get_signature_weights(
            FormatType.FT_STANDARD, CardClass.DRUID)

        assert signature_weights == {
            247: {
                "required_cards": [48625],
                "rules": [],
                "signature_weights":
                {int(k): v
                 for k, v in MECHATHUN_DRUID.items()}
            }
        }
Пример #2
0
    def test_synchronize_required_cards(self):
        archetype = Archetype(
            name="Mecha'thun Druid",
            player_class=CardClass.DRUID,
        )
        archetype.save()
        archetype.required_cards.add(Card.objects.get(dbf_id=836))
        archetype.required_cards.add(Card.objects.get(dbf_id=1124))

        cluster_set = ClusterSetSnapshot(game_format=FormatType.FT_STANDARD,
                                         live_in_production=True)
        cluster_set.save()

        class_cluster = ClassClusterSnapshot(cluster_set=cluster_set,
                                             player_class=CardClass.DRUID)
        class_cluster.save()

        cluster = ClusterSnapshot(class_cluster=class_cluster,
                                  cluster_id=1,
                                  external_id=archetype.id,
                                  required_cards=[48625],
                                  ccp_signature=MECHATHUN_DRUID)
        cluster.save()

        cluster_set.synchronize_required_cards()

        assert archetype.required_cards.count() == 1
        assert archetype.required_cards.first() == Card.objects.get(
            dbf_id=48625)
Пример #3
0
	def setup_method(self, db):
		self.cluster_set = ClusterSetSnapshot(latest=True)
		self.cluster_set.save()

		self.class_cluster = ClassClusterSnapshot(
			cluster_set=self.cluster_set,
			player_class=CardClass.PRIEST
		)
		self.class_cluster.save()

		self.cluster = ClusterSnapshot(
			class_cluster=self.class_cluster,
			cluster_id=1,
			data_points=[{
				"x": 0,
				"y": 0,
				"cards": _get_deck_from_deckstring(
					"AAECAa0GCO0Fw8EC0cEClsQCnccC3PUC8fsCiIIDC4oB+wHlBPIMysMCns4C8M8C6NACqe"
					"IC6uYCof4CAA=="""
				),
				"observations": 1
			}],
			signature=MECHATHUN_QUEST_PRIEST
		)
		self.cluster.save()
Пример #4
0
    def setup_method(self, db):
        Feature(name="archetype-training", status=FeatureStatus.PUBLIC).save()

        self.cluster_set = ClusterSetSnapshot()
        self.cluster_set.save()

        self.class_cluster = ClassClusterSnapshot(cluster_set=self.cluster_set)
        self.class_cluster.save()

        self.cluster = ClusterSnapshot(
            class_cluster=self.class_cluster,
            cluster_id=1,
            data_points=[{
                "x":
                0,
                "y":
                0,
                "cards":
                _get_deck_from_deckstring(
                    "AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA=="
                ),
                "observations":
                1
            }],
            signature=MECHATHUN_DRUID)
        self.cluster.save()
Пример #5
0
class TestClusterSnapshotRequiredCardsUpdateView:
	view = ClusterSnapshotRequiredCardsUpdateView()

	@pytest.fixture(autouse=True)
	def setup_method(self, db):
		self.cluster_set = ClusterSetSnapshot(latest=True)
		self.cluster_set.save()

		self.class_cluster = ClassClusterSnapshot(
			cluster_set=self.cluster_set,
			player_class=CardClass.PRIEST
		)
		self.class_cluster.save()

		self.cluster = ClusterSnapshot(
			class_cluster=self.class_cluster,
			cluster_id=1,
			data_points=[{
				"x": 0,
				"y": 0,
				"cards": _get_deck_from_deckstring(
					"AAECAa0GCO0Fw8EC0cEClsQCnccC3PUC8fsCiIIDC4oB+wHlBPIMysMCns4C8M8C6NACqe"
					"IC6uYCof4CAA=="""
				),
				"observations": 1
			}],
			signature=MECHATHUN_QUEST_PRIEST
		)
		self.cluster.save()

	@pytest.mark.django_db
	def test_delete(self, client):
		self.cluster.required_cards = [41494, 48625]
		self.cluster.save()

		response = client.delete(
			f"/clusters/latest/FT_STANDARD/PRIEST/{self.cluster.cluster_id}/41494/"
		)

		assert response.status_code == 200

		self.cluster.refresh_from_db()

		assert self.cluster.required_cards == [48625]

	@pytest.mark.django_db
	def test_put(self, client):
		self.cluster.required_cards = [48625]
		self.cluster.save()

		response = client.put(
			f"/clusters/latest/FT_STANDARD/PRIEST/{self.cluster.cluster_id}/41494/"
		)

		assert response.status_code == 200

		self.cluster.refresh_from_db()

		assert self.cluster.required_cards == [48625, 41494]
Пример #6
0
	def test_patch_with_archetype_id_merge(self, client):
		archetype = Archetype(
			name="Mecha'thun Druid",
			player_class=CardClass.DRUID,
		)
		archetype.save()
		archetype.required_cards.add(Card.objects.get(dbf_id=48625))

		existing_cluster = ClusterSnapshot(
			class_cluster=self.class_cluster,
			cluster_id=2,
			data_points=[{
				"x": 0,
				"y": 0,
				"cards": _get_deck_from_deckstring(
					"AAECAZICBFaHzgKZ0wLx+wINQF/pAf4BxAbkCKDNApTSApjSAp7SAtvTAoTmAr/yAgA="
				),
				"observations": 1
			}],
			external_id=archetype.id,
			name=archetype.name,
			required_cards=[48625],
			signature=MECHATHUN_DRUID
		)
		existing_cluster.save()

		response = client.patch(
			f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/",
			data=json.dumps({
				"archetype_id": archetype.id
			})
		)

		assert response.status_code == 200

		assert ClusterSnapshot.objects.filter(pk=self.cluster.id).count() == 0
		assert ClusterSnapshot.objects.filter(pk=existing_cluster.id).count() == 0

		new_cluster = ClusterSnapshot.objects.filter(external_id=archetype.id).first()

		assert new_cluster.name == archetype.name
		assert new_cluster.required_cards == [48625]
Пример #7
0
	def setup_method(self, db):
		self.cluster_set = ClusterSetSnapshot(latest=True)
		self.cluster_set.save()

		self.class_cluster = ClassClusterSnapshot(
			cluster_set=self.cluster_set,
			player_class=CardClass.DRUID
		)
		self.class_cluster.save()

		self.cluster = ClusterSnapshot(
			class_cluster=self.class_cluster,
			cluster_id=1,
			data_points=[{
				"x": 0,
				"y": 0,
				"cards": _get_deck_from_deckstring(
					"AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA=="
				),
				"observations": 1
			}],
			signature=MECHATHUN_DRUID
		)
		self.cluster.save()
Пример #8
0
class TestClusterSnapshotUpdateView:
	view = ClusterSnapshotUpdateView()

	@pytest.fixture(autouse=True)
	def setup_method(self, db):
		self.cluster_set = ClusterSetSnapshot(latest=True)
		self.cluster_set.save()

		self.class_cluster = ClassClusterSnapshot(
			cluster_set=self.cluster_set,
			player_class=CardClass.DRUID
		)
		self.class_cluster.save()

		self.cluster = ClusterSnapshot(
			class_cluster=self.class_cluster,
			cluster_id=1,
			data_points=[{
				"x": 0,
				"y": 0,
				"cards": _get_deck_from_deckstring(
					"AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA=="
				),
				"observations": 1
			}],
			signature=MECHATHUN_DRUID
		)
		self.cluster.save()

	@pytest.mark.django_db
	def test_patch_no_archetype_id(self, client):
		response = client.patch(
			f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/",
			data="{}"
		)

		assert response.status_code == 200

		self.cluster.refresh_from_db()

		assert self.cluster.external_id is None
		assert self.cluster.name == "NEW"
		assert self.cluster.required_cards == []

	@pytest.mark.django_db
	def test_patch_with_archetype_id(self, client):
		archetype = Archetype(
			name="Mecha'thun Druid",
			player_class=CardClass.DRUID,
		)
		archetype.save()
		archetype.required_cards.add(Card.objects.get(dbf_id=48625))

		response = client.patch(
			f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/",
			data=json.dumps({
				"archetype_id": archetype.id
			})
		)

		assert response.status_code == 200

		self.cluster.refresh_from_db()

		assert self.cluster.external_id == archetype.id
		assert self.cluster.name == "Mecha'thun Druid"
		assert self.cluster.required_cards == [48625]

	@pytest.mark.django_db
	def test_patch_with_archetype_id_merge(self, client):
		archetype = Archetype(
			name="Mecha'thun Druid",
			player_class=CardClass.DRUID,
		)
		archetype.save()
		archetype.required_cards.add(Card.objects.get(dbf_id=48625))

		existing_cluster = ClusterSnapshot(
			class_cluster=self.class_cluster,
			cluster_id=2,
			data_points=[{
				"x": 0,
				"y": 0,
				"cards": _get_deck_from_deckstring(
					"AAECAZICBFaHzgKZ0wLx+wINQF/pAf4BxAbkCKDNApTSApjSAp7SAtvTAoTmAr/yAgA="
				),
				"observations": 1
			}],
			external_id=archetype.id,
			name=archetype.name,
			required_cards=[48625],
			signature=MECHATHUN_DRUID
		)
		existing_cluster.save()

		response = client.patch(
			f"/clusters/latest/FT_STANDARD/DRUID/{self.cluster.cluster_id}/",
			data=json.dumps({
				"archetype_id": archetype.id
			})
		)

		assert response.status_code == 200

		assert ClusterSnapshot.objects.filter(pk=self.cluster.id).count() == 0
		assert ClusterSnapshot.objects.filter(pk=existing_cluster.id).count() == 0

		new_cluster = ClusterSnapshot.objects.filter(external_id=archetype.id).first()

		assert new_cluster.name == archetype.name
		assert new_cluster.required_cards == [48625]
Пример #9
0
class TestSingleClusterUpdateView:
    view = SingleClusterUpdateView()

    @pytest.fixture(autouse=True)
    def setup_method(self, db):
        Feature(name="archetype-training", status=FeatureStatus.PUBLIC).save()

        self.cluster_set = ClusterSetSnapshot()
        self.cluster_set.save()

        self.class_cluster = ClassClusterSnapshot(cluster_set=self.cluster_set)
        self.class_cluster.save()

        self.cluster = ClusterSnapshot(
            class_cluster=self.class_cluster,
            cluster_id=1,
            data_points=[{
                "x":
                0,
                "y":
                0,
                "cards":
                _get_deck_from_deckstring(
                    "AAECAZICApnTAvH7Ag5AX+kB/gHTA8QGpAf2B+QIktICmNICntICv/ICj/YCAA=="
                ),
                "observations":
                1
            }],
            signature=MECHATHUN_DRUID)
        self.cluster.save()

    @pytest.mark.django_db
    def test_patch_no_archetype_id(self, client):
        response = client.patch(
            f"/analytics/clustering/data/{self.cluster_set.id}/{self.cluster.cluster_id}/",
            data="{}")

        assert response.status_code == 200

        self.cluster.refresh_from_db()

        assert self.cluster.external_id is None
        assert self.cluster.name == "NEW"
        assert self.cluster.required_cards == []

    def test_patch_with_archetype_id(self, client):
        archetype = Archetype(
            name="Mecha'thun Druid",
            player_class=CardClass.DRUID,
        )
        archetype.save()
        archetype.required_cards.add(Card.objects.get(dbf_id=48625))

        response = client.patch(
            f"/analytics/clustering/data/{self.cluster_set.id}/{self.cluster.cluster_id}/",
            data=json.dumps({"archetype_id": archetype.id}))

        assert response.status_code == 200

        self.cluster.refresh_from_db()

        assert self.cluster.external_id == archetype.id
        assert self.cluster.name == "Mecha'thun Druid"
        assert self.cluster.required_cards == [48625]